Commit 971cf99
authored
fix ^ evaluates as bitwise XOR instead of exponentiation (#22314)
## Which issue does this PR close?
- Closes #22252.
## Rationale for this change
In PostgreSQL, the `^` operator represents exponentiation, but
DataFusion was interpreting it as bitwise XOR. This caused
PostgreSQL-dialect queries such as `SELECT 2 ^ 3;` to return `1` instead
of `8`.
This change aligns DataFusion's PostgreSQL SQL semantics with PostgreSQL
for this operator while preserving existing non-PostgreSQL behavior.
## What changes are included in this PR?
- Added PostgreSQL-specific handling for `BinaryOperator::PGExp` during
SQL expression lowering.
- Lowered PostgreSQL `^` expressions to the built-in `power(left,
right)` scalar function instead of treating them as bitwise XOR.
- Kept existing generic-dialect `^` behavior unchanged.
- Kept PostgreSQL bitwise XOR behavior unchanged via `#`.
- Added a sqllogictest regression covering `SELECT 2 ^ 3;` under the
PostgreSQL parser dialect.
## Are these changes tested?
Yes.
Added a regression test in scalar.slt to verify that PostgreSQL-dialect
`^` is evaluated as exponentiation.
Validated with:
```bash
cargo test -p datafusion-sqllogictest --test sqllogictests scalar
```
## Are there any user-facing changes?
Yes.
For the PostgreSQL SQL parser dialect, `^` now behaves as exponentiation
instead of bitwise XOR, matching PostgreSQL semantics. Generic-dialect
behavior is unchanged, and PostgreSQL bitwise XOR remains available
through `#`.1 parent 097efae commit 971cf99
3 files changed
Lines changed: 40 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
75 | 107 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 145 | + | |
150 | 146 | | |
151 | 147 | | |
152 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1300 | 1300 | | |
1301 | 1301 | | |
1302 | 1302 | | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
1303 | 1309 | | |
1304 | 1310 | | |
1305 | 1311 | | |
| |||
0 commit comments