Skip to content

fix: Add legacy mode handling to cast Decimal to String#3939

Open
parthchandra wants to merge 7 commits intoapache:mainfrom
parthchandra:cast-primitive-string
Open

fix: Add legacy mode handling to cast Decimal to String#3939
parthchandra wants to merge 7 commits intoapache:mainfrom
parthchandra:cast-primitive-string

Conversation

@parthchandra
Copy link
Copy Markdown
Contributor

@parthchandra parthchandra commented Apr 13, 2026

Which issue does this PR close?

Part of #286
Fixes: #1068

Rationale for this change

CometCast.canCastToString had previously marked DecimalType -> StringType as Compatible with a caveat. However, the native Decimal128 -> String cast was not explicitly handled in cast_array and it was falling through to DataFusion's built-in cast, which was incompatible with Spark legacy mode for large scale values.

For example, zero with a large scale: Decimal(38,18) zero exponent = -18 which produced "0E-18" in Spark LEGACY but "0.000000000000000000" from Comet

TRY and ANSI modes are compatible

What changes are included in this PR?

Adds explicit handling for legacy mode

How are these changes tested?

unit tests

@parthchandra parthchandra force-pushed the cast-primitive-string branch from 569d741 to f570e55 Compare April 13, 2026 23:01
@parthchandra parthchandra marked this pull request as draft April 14, 2026 21:57
@parthchandra parthchandra marked this pull request as ready for review April 15, 2026 16:28
@parthchandra
Copy link
Copy Markdown
Contributor Author

@andygrove @kazuyukitanimura this is ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make decimal to string cast fully compatible with Spark

1 participant