Internal error when there is a bitwise operation in `order by` clause (SQLancer)
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
Bitwise operations are producing various inconsistent behavior during fuzzing.
The root cause seems to be bitwise operation evaluation (maybe related to https://github.com/apache/datafusion/issues/11260)
However, when bitwise operations are used in the ORDER BY clause, other SORT-related errors show up.
We could investigate if this bitwise operation bug might propagate into the SORT logic.
### To Reproduce
Reproduce in datafusion-cli
This is a potential bug in bitwise operation, `|` of two `DOUBLE` type should not be allowed, it should yield a planning error, but in this case it produces an internal error (https://github.com/apache/datafusion/issues/11249)
```
> select (0.7|0.8);
Internal error: Data type Float64 not supported for binary operation 'bitwise_or' on dyn arrays.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
```
However, when this expression is placed in `order by` clause, some query can execute successfully, some query can trigger another internal error in sort logic.
```
> /*DML*/CREATE TABLE t1(v0 BOOLEAN);
/*DML*/CREATE TABLE t3(v0 BOOLEAN, v1 BIGINT);
0 row(s) fetched.
Elapsed 0.058 seconds.
0 row(s) fetched.
Elapsed 0.002 seconds.
> SELECT * FROM t3 NATURAL JOIN t1 ORDER BY (0.7 | 0.8);
+----+----+
| v1 | v0 |
+----+----+
+----+----+
0 row(s) fetched.
Elapsed 0.084 seconds.
> SELECT * FROM t3 NATURAL JOIN t1 ORDER BY (0.7 | 0.8) > 0;
Internal error: Sort expressions cannot be empty for streaming merge.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
```
### Expected behavior
_No response_
### Additional context
Found by SQLancer https://github.com/apache/datafusion/issues/11030
Contributor guide
Research direction
Start by reproducing the standalone bitwise expression and the two ORDER BY queries in datafusion-cli. Trace the planning and sort paths involved in bitwise operations and ORDER BY handling, using the reported errors as checkpoints. Done means invalid DOUBLE bitwise operations produce a planning error and the ORDER BY cases no longer produce internal errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100