Skip to content

[SPARK-58316][SQL] Reject non-finite decimal casts in ANSI mode - #58534

Open
charliec05 wants to merge 1 commit into
apache:masterfrom
charliec05:codex/spark-58316-ansi-nonfinite-decimal
Open

[SPARK-58316][SQL] Reject non-finite decimal casts in ANSI mode#58534
charliec05 wants to merge 1 commit into
apache:masterfrom
charliec05:codex/spark-58316-ansi-nonfinite-decimal

Conversation

@charliec05

Copy link
Copy Markdown

What changes were proposed in this pull request?

Make the NumberFormatException path in floating-point-to-decimal casts ANSI-aware in both interpreted evaluation and generated code.

When ANSI mode is enabled, casting NaN, positive infinity, or negative infinity from float or double to decimal now raises the existing CAST_OVERFLOW error. Non-ANSI casts and TRY_CAST continue to return null.

Add regression coverage for all six float/double non-finite inputs.

Why are the changes needed?

Decimal cannot represent non-finite floating-point values. Constructing the intermediate decimal throws NumberFormatException, but the current catch block always converts that exception to null before the ANSI-aware precision handling can run. This makes ANSI mode silently return null instead of reporting an unrepresentable cast.

Does this PR introduce any user-facing change?

Yes. With ANSI mode enabled, casting float or double NaN and infinities to decimal now throws CAST_OVERFLOW. Behavior with ANSI mode disabled and for TRY_CAST remains unchanged.

How was this patch tested?

Added regression tests and ran:

build/sbt "catalyst/Test/testOnly org.apache.spark.sql.catalyst.expressions.CastWithAnsiOnSuite org.apache.spark.sql.catalyst.expressions.CastWithAnsiOffSuite org.apache.spark.sql.catalyst.expressions.TryCastSuite"

All 410 tests passed. Also ran dev/lint-scala; Scalastyle and Scalafmt passed.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-5)

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.

1 participant