Commit 93724b0
authored
fix: validate wrapped negation during type coercion (apache#20965)
## Which issue does this PR close?
- Related to apache#20988 .
## Rationale for this change
Invalid wrapped negation expressions such as `(-'a') IS NULL` could
still escape type validation during optimization.
This PR keeps the fix in the analyzer/type coercion path, which is where
most of DataFusion's type validation already happens, rather than adding
SQL-planner-specific validation.
## What changes are included in this PR?
- add type validation for `Expr::Negative` in `TypeCoercionRewriter`
- return an error for invalid negation operands during optimization
- add focused regression tests for wrapped negation
## Are these changes tested?
Yes.
Added:
- a unit test for `(-'a') IS NULL` in `type_coercion`
- an integration test that verifies the same case fails during
`into_optimized_plan()`
## Are there any user-facing changes?
Yes. Invalid wrapped negation expressions now fail during optimization
instead of escaping type validation until later phases.1 parent 85a34e9 commit 93724b0
File tree
2 files changed
+45
-2
lines changed- datafusion
- core/tests/sql
- optimizer/src/analyzer
2 files changed
+45
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
559 | 561 | | |
560 | 562 | | |
561 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
562 | 578 | | |
563 | 579 | | |
564 | 580 | | |
| |||
753 | 769 | | |
754 | 770 | | |
755 | 771 | | |
756 | | - | |
757 | 772 | | |
758 | 773 | | |
759 | 774 | | |
| |||
1369 | 1384 | | |
1370 | 1385 | | |
1371 | 1386 | | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1372 | 1398 | | |
1373 | 1399 | | |
1374 | 1400 | | |
| |||
0 commit comments