Commit 62cbb3a
committed
[SPARK-53454][SQL][FOLLOWUP] Parenthesize AlwaysTrue/AlwaysFalse SQL so it is valid as a nested operand
### What changes were proposed in this pull request?
Followup to #56085.
That PR made `JDBCSQLBuilder.build()` emit `"1 = 1"` / `"1 = 0"` for `AlwaysTrue` / `AlwaysFalse` predicates. This change parenthesizes the output -- `"(1 = 1)"` / `"(1 = 0)"` -- so it remains valid SQL when the predicate is nested as an operand of a larger expression.
### Why are the changes needed?
`AlwaysTrue` / `AlwaysFalse` can appear not only as a standalone `WHERE` predicate but also nested as an operand of a larger expression (e.g. when an equality against a boolean column is expanded to a null-aware form). With the bare `1 = 1`, the generated SQL inlines into invalid syntax such as `"a" = 1 = 1` or `1 = 1 IS NOT NULL`, which databases reject (e.g. PostgreSQL: `ERROR: syntax error at or near "="`). Parenthesizing produces `"a" = (1 = 1)` / `(1 = 1) IS NOT NULL`, which is valid both standalone and nested.
### Does this PR introduce _any_ user-facing change?
Yes. JDBC pushed-filter SQL for `AlwaysTrue` / `AlwaysFalse` now uses `(1 = 1)` / `(1 = 0)` instead of bare `1 = 1` / `1 = 0`. This is semantically identical and fixes queries that previously generated invalid SQL when these predicates were nested.
### How was this patch tested?
Extended the existing unit test in `JDBCSuite` to also cover the nested-operand case (`"a" = (1 = 1)`). Verified the test fails without the fix (`"1 = 1"` not equal to `"(1 = 1)"`) and passes with it.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
Closes #56263 from cloud-fan/SPARK-53454-followup.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent 1b60970 commit 62cbb3a
2 files changed
Lines changed: 19 additions & 5 deletions
File tree
- sql/core/src
- main/scala/org/apache/spark/sql/jdbc
- test/scala/org/apache/spark/sql/jdbc
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
405 | 408 | | |
406 | | - | |
407 | | - | |
| 409 | + | |
| 410 | + | |
408 | 411 | | |
409 | 412 | | |
410 | 413 | | |
| |||
Lines changed: 14 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
895 | 896 | | |
896 | 897 | | |
897 | 898 | | |
898 | | - | |
899 | | - | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
900 | 911 | | |
901 | 912 | | |
902 | 913 | | |
| |||
0 commit comments