Repository navigation
Description
What is the problem the feature request solves?
Comet currently delegates to DataFusion for many cast operations, and the behavior is not guaranteed to match Spark. This epic is to track fully implementing Spark-compatible cast and try_cast operations in Comet, with support for ANSI mode.
For each item in this list to be considered complete, we should have scala tests demonstrating that cast and try_cast produce the same results as Spark, both with ANSI mode enabled and disabled, using fuzz testing to find edge cases. We can update this list with links to issues as we make progress.
For cast operations that we cannot easily support with full compatibility, we should either fall back to Spark or provide a configuration that the user can enable to allow the operation to run in Comet. We should also provide documentation explaining any differences in behavior compared to Spark.
- Cast from string to another type
- Boolean - feat: Support ANSI mode in CAST from String to Bool #290
- Integral Types (byte, short, int, long) - feat: Implement Spark-compatible CAST from string to integral types #307
- Floating-point (float, double) - Implement Spark-compatible CAST from String to Floating Point #326
- Decimal - Implement Spark-compatible CAST from String to Decimal #325
- Date - Implement Spark-compatible CAST from String to Date #327
- Timestamp - Implement Spark-compatible CAST from String to Timestamp #328 and Cast string to timestamp remaining work #376
- Cast to string from primitive types
- Boolean - chore: Add more cast tests and improve test framework #351
- Integral Types (byte, short, int, long) - chore: Add more cast tests and improve test framework #351
- Floating-point (float, double) - Implement Spark-compatible CAST float/double to string #312
- Decimal - seems to correct but needs tests to confirm, also should fall back to Spark if
spark.sql.legacy.allowNegativeScaleOfDecimalis true and scale is negative - fix: Add legacy mode handling to cast Decimal to String #3939 - Date - seems correct but needs tests to confirm
- Timestamp - seems correct but needs tests to confirm
- Cast between numeric types
- Integral to Integral - Implement Spark-compatible CAST between integer types #311
- Integral to Boolean - chore: Add more cast tests and improve test framework #351
- Integral to Decimal - Implement Spark-compatible cast from integral types to decimal #2049
- Integral to Floating-point - chore: Add more cast tests and improve test framework #351
- Floating-point to Boolean - chore: Add more cast tests and improve test framework #351
- Floating-point to Decimal - Implement Spark-compatible CAST from floating-point to decimal #371
- Floating-point to Integral - Implement Spark-compatible CAST from float/double to integer types #350
- Decimal to Boolean - fails because arrow does not support this cast - fix: improve test coverage for decimal to primitive type casts #3948
- Decimal to Integral - same issues as Implement Spark-compatible CAST from float/double to integer types #350
- Decimal to Floating-point - seems correct but needs tests to confirm - fix: improve test coverage for decimal to primitive type casts #3948
- Implement Spark-compatible cast between decimals with different precision and scale #375
- Cast between temporal types
- Date to boolean/int/float/decimal - results are incorrect
- Date to Timestamp / TimestampNTZ
- Timestamp to boolean/int/float/decimal - Implement Spark-compatible CAST from timestamp to numeric types #352
- Timestamp to Date
- Other
In addition to the above tasks, we also need to do the following:
- Implement a mechanism where we can selectively fall back to Spark for specific cast operations (feat: Disable cast string to timestamp by default #337 )
- Write documentation that explains any differences between Comet and Spark
- Add support for TryCast expression in Spark 3.2 and 3.3 #374
Activity
edmondop commentedon Apr 19, 2024
@andygrove do we have already a framework for fuzz testing in Scala (i.e. ScalaCheck?) Should anyone wait until you are done with the first ones so you establish a pattern?
andygrove commentedon Apr 19, 2024
There is a
CometCastSuiteand I am working on a PR right now to improve this and I am also implementing cast string to boolean (an easy one) so that there is an example for others to learn from. I should have a draft PR up on Monday.andygrove commentedon Apr 22, 2024
I am now working on cast string -> integral types. I will have a PR up later this week.
edmondop commentedon Apr 28, 2024
@andygrove can I take care of this " Implement a mechanism where we can selectively fall back to Spark for specific cast operations" ? I was looking at the top of the list, but everything was quickly taken
andygrove commentedon Apr 29, 2024
@edmondop feel free to pick up other items on the list that don't have issues yet (I will start filing more!)
I added an example of falling back top Spark for cast string to timestamp in #337 so we do have an approach. I will update that item in this epic.
andygrove commentedon Apr 29, 2024
@edmondop also just added #350
coderfender commentedon Sep 29, 2025
Raised issue : #2489 to track Decimal to Boolean cast op and integer to decimal cast op #2472
coderfender commentedon Oct 12, 2025
Raised : #2490 for Decimal -> Boolean cast native support
coderfender commentedon Dec 8, 2025
Raised : #2835 for full String -> float/Double casts
coderfender commentedon Dec 17, 2025
Raised #2926 to track String -> Decimal Type casting
andygrove commentedon Jan 30, 2026
@coderfender do you think we can close this epic now? Do you we need to create any additional issues for remaining work?
coderfender commentedon Jan 30, 2026
@andygrove I believe we can close / update this EPIC given that most of the expressions are supported and we also now have documentation with cast support at different eval modes. We might however want to create new epic for temporal casts which @parthchandra might be working on
attilapiros commentedon Jan 31, 2026
For your awareness, this Spark PR was recently submitted: apache/spark#53458
and this will affect how an invalid UTF-8 from binary to string will be casted.
coderfender commentedon Feb 5, 2026
Issue to to cast from date to timestamp : #3400
PR : #3383
boudica-dev-eng commentedon Feb 5, 2026
I haven't found an issue for Long -> Timestamp. Is this planned?
coderfender commentedon Feb 6, 2026
whole numbers to binary and bool to decimal : #3083
coderfender commentedon Mar 9, 2026
numeric (non int) to timestamp : #3560
andygrove commentedon Apr 24, 2026
All items in this epic are now completed 🎉 so let's close this and just file individual issues for any are casts that need implementing.
coderfender commentedon Apr 24, 2026
This is great news @andygrove !