You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement Spark-compatible CAST from String to Decimal #325
We currently delegate to DataFusion when casting from string to decimal and there are some differences in behavior compared to Spark.
An input of 4e7 produces 40000000.00 in Spark, and null in DataFusion
Inputs of ., -, + and empty string produce null in Spark, and 0.0 in DataFusion
Input of 0 produces 0 in Spark, and null in DataFusion
Arrow-rs does not support negative scale (Cannot cast string to decimal with negative scale). We could choose to fallback to Spark for this use case (or if SQLConf.LEGACY_ALLOW_NEGATIVE_SCALE_OF_DECIMAL_ENABLED is enabled)
Describe the potential solution
No response
Additional context
I used the following test in CometCastSuite to explore this.
Note: I encountered a java.lang.AssertionError: assertion failed: Decimal$DecimalIsFractional on the second df2.show, but it seems like a known issue and can safely be ignored: https://kb.databricks.com/scala/decimal-is-fractional-error
Hi @kevinmingtarja, are you working on this issue? If not, I would like to work on it. Thank you.
Hey, i don't think i have the bandwidth rn to complete this, so please feel free to work on it. I have made some progress here on a branch in my fork, so feel free to take inspirations from there as well if needed!
But even with comet enabled it does not go through DataFusion as it is marked as incompatible, I then checked this in the DataFusion project the following queries
works fine but the following one if I add a '4e7' as shown below it throws arrow-error
External error: query failed: DataFusion error: Arrow error: Cast error: Cannot cast string '4e7' to value of Decimal128(38, 10) type
[SQL] select arrow_typeof(cast('4e7'asdecimal(10,2))), cast('4e7'asdecimal(10,2));
I think, if we add the functionality for string of this format to decimal in arrow-rs, then the above error could be resolved and also this issue will be addressed. Previous attempt to fix this issue was made on DataFusion project. Can someone please help me understand whether the fix can be applied in arrow-rs and use the cast from there?
I think, if we add the functionality for string of this format to decimal in arrow-rs, then the above error could be resolved and also this issue will be addressed. Previous attempt to fix this issue was made on DataFusion project. Can someone please help me understand whether the fix can be applied in arrow-rs and use the cast from there?
It makes sense to me for arrow-rs to support casting 4e7 as decimal. There was actually a discussion about this in apache/datafusion#10315
Activity
kevinmingtarja commentedon Apr 26, 2024
Hi, I'd like to contribute to this!
viirya commentedon Apr 26, 2024
Thanks @kevinmingtarja.
You can take a look at @andygrove's PR as a reference #307
kevinmingtarja commentedon Apr 28, 2024
Current state for reference:
Note: I encountered a
java.lang.AssertionError: assertion failed: Decimal$DecimalIsFractionalon the seconddf2.show, but it seems like a known issue and can safely be ignored: https://kb.databricks.com/scala/decimal-is-fractional-errorsujithjay commentedon Jun 4, 2024
Hi @kevinmingtarja, are you working on this issue? If not, I would like to work on it. Thank you.
kevinmingtarja commentedon Jun 5, 2024
Hey, i don't think i have the bandwidth rn to complete this, so please feel free to work on it. I have made some progress here on a branch in my fork, so feel free to take inspirations from there as well if needed!
himadripal commentedon Dec 9, 2024
I was looking at this issue and now - with comet enabled and comet disabled shows same result -
But even with comet enabled it does not go through DataFusion as it is marked as incompatible, I then checked this in the DataFusion project the following queries
works fine but the following one if I add a '4e7' as shown below it throws arrow-error
I think, if we add the functionality for string of this format to decimal in arrow-rs, then the above error could be resolved and also this issue will be addressed. Previous attempt to fix this issue was made on DataFusion project. Can someone please help me understand whether the fix can be applied in arrow-rs and use the cast from there?
andygrove commentedon Dec 11, 2024
It makes sense to me for arrow-rs to support casting
4e7as decimal. There was actually a discussion about this in apache/datafusion#10315himadripal commentedon Dec 27, 2024
take, this arrow-pr should fix one.
coderfender commentedon Dec 8, 2025
Raised PR to add further support from String to Decimal Type : #2835
parthchandra commentedon Apr 9, 2026
Completed in #3884