Commit 6d7ff76
[SPARK-54843][SQL] Try_to_number expression not working for empty string input
### What changes were proposed in this pull request?
Catching the case in `ToNumberParser` when the input string only consists of whitespace, preventing a failure with an internal error later on when trying to create `BigDecimal`.
### Why are the changes needed?
Without this change passing an empty string (`select try_to_number('', '99')`) would fail with the following exception:
```
JVM stacktrace:
java.lang.NumberFormatException
at java.base/java.math.BigDecimal.(BigDecimal.java:692)
at java.base/java.math.BigDecimal.(BigDecimal.java:471)
at java.base/java.math.BigDecimal.(BigDecimal.java:900)
at org.apache.spark.sql.catalyst.util.ToNumberParser.parseResultToDecimalValue(ToNumberParser.scala:627)
at org.apache.spark.sql.catalyst.util.ToNumberParser.parse(ToNumberParser.scala:499)
```
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
New unit tests.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #53609 from stefankandic/numFormatFix.
Authored-by: Stefan Kandic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit df720c1)
Signed-off-by: Wenchen Fan <[email protected]>1 parent eec9f8f commit 6d7ff76
File tree
2 files changed
+23
-0
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/util
- core/src/test/scala/org/apache/spark/sql
2 files changed
+23
-0
lines changedLines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
498 | 501 | | |
499 | 502 | | |
500 | 503 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1342 | 1342 | | |
1343 | 1343 | | |
1344 | 1344 | | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1345 | 1365 | | |
1346 | 1366 | | |
1347 | 1367 | | |
| |||
0 commit comments