Commit 5bb514b
committed
[SPARK-56912][SQL] Refactor Cast to boolean codegen under ANSI mode
### What changes were proposed in this pull request?
Extend `CastUtils.java` with `stringToBooleanExact(UTF8String, QueryContext)`
and use it from `Cast.scala` for the ANSI `String -> Boolean` cast path
(both eval and codegen). The non-ANSI path keeps the inline
`if/else if/else evNull = true` form because it has no error to throw.
### Why are the changes needed?
Part of SPARK-56908 (umbrella). The ANSI String->Boolean cast emits an
8-line `if (isTrueString) … else if (isFalseString) … else throw` block
in codegen. This PR collapses it to a one-line `CastUtils
.stringToBooleanExact(...)` call.
### Does this PR introduce _any_ user-facing change?
No. The compiled behavior is identical; only the emitted Java source
text changes.
### How was this patch tested?
```
build/sbt "catalyst/testOnly *CastSuite *CastWithAnsiOnSuite \
*AnsiCastSuite *TryCastSuite"
```
204/204 pass.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor 1.x1 parent 0beac87 commit 5bb514b
2 files changed
Lines changed: 18 additions & 12 deletions
File tree
- sql/catalyst/src/main
- java/org/apache/spark/sql/catalyst/expressions
- scala/org/apache/spark/sql/catalyst/expressions
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
140 | 150 | | |
Lines changed: 8 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
| 698 | + | |
| 699 | + | |
698 | 700 | | |
699 | 701 | | |
700 | 702 | | |
701 | 703 | | |
702 | 704 | | |
703 | 705 | | |
704 | 706 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
| 707 | + | |
710 | 708 | | |
711 | 709 | | |
712 | 710 | | |
| |||
1891 | 1889 | | |
1892 | 1890 | | |
1893 | 1891 | | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
1894 | 1896 | | |
1895 | 1897 | | |
1896 | 1898 | | |
1897 | | - | |
1898 | | - | |
1899 | | - | |
1900 | | - | |
1901 | | - | |
1902 | | - | |
1903 | 1899 | | |
1904 | 1900 | | |
1905 | 1901 | | |
1906 | 1902 | | |
1907 | 1903 | | |
1908 | 1904 | | |
1909 | | - | |
| 1905 | + | |
1910 | 1906 | | |
1911 | 1907 | | |
1912 | 1908 | | |
| |||
0 commit comments