Skip to content

Conversation

@stefankandic
Copy link
Contributor

@stefankandic stefankandic commented Dec 25, 2025

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.

@github-actions github-actions bot added the SQL label Dec 25, 2025
@stefankandic stefankandic changed the title [SPARK-54843] Try_to_number expression not working for empty string input [SPARK-54843][SQL] Try_to_number expression not working for empty string input Dec 25, 2025
@stefankandic
Copy link
Contributor Author

Please take a look when you get the chance @dtenedor @cloud-fan

@cloud-fan
Copy link
Contributor

thanks, merging to master/4.1!

@cloud-fan cloud-fan closed this in df720c1 Dec 26, 2025
cloud-fan pushed a commit that referenced this pull request Dec 26, 2025
…ing 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 <stefan.kandic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit df720c1)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants