Skip to content

[VL] Add ANSI mode support for Spark CAST(NumericType as integral)#11854

Open
minni31 wants to merge 2 commits intoapache:mainfrom
minni31:oss/ansi-cast-numeric-to-integral
Open

[VL] Add ANSI mode support for Spark CAST(NumericType as integral)#11854
minni31 wants to merge 2 commits intoapache:mainfrom
minni31:oss/ansi-cast-numeric-to-integral

Conversation

@minni31
Copy link
Copy Markdown

@minni31 minni31 commented Mar 30, 2026

Summary

Enables ANSI mode handling for cast operations from numeric types (int, long, float, double) to integral types (tinyint, smallint, integer, bigint) in the Velox backend.

When spark.sql.ansi.enabled=true, CAST from numeric to integral types now throws on overflow instead of silently wrapping/truncating, matching Spark's ANSI compliance.

Depends on Velox PR: facebookincubator/velox#16962

Changes

C++ (Velox backend config)

  • VeloxConfig.h: Add spark.sql.ansi.enabled config key
  • WholeStageResultIterator.cc: Propagate ANSI config to Velox QueryConfig

Scala/Java (Substrait conversion)

  • CastNode.java: Use int failureBehavior (0=UNSPECIFIED, 1=RETURN_NULL, 2=THROW_EXCEPTION) instead of boolean isTryCast
  • ExpressionBuilder.java: Add makeCast overload with isAnsiCast param
  • UnaryExpressionTransformer.scala: Pass withAnsiEvalMode to CastTransformer

Shims

  • Spark34/35/40Shims.scala: Add Cast to withAnsiEvalMode pattern matching

Tests

  • VeloxTestSettings.scala (spark34/35/40): Remove exclusions for 4 ANSI cast overflow tests
  • GlutenTryCastSuite.scala: Enable ANSI overflow tests

Testing

  • GlutenTryCastSuite: 78/78 tests passed, 0 failures

Enables ANSI mode handling for cast operations from numeric types
(int, long, float, double) to integral types (tinyint, smallint,
integer, bigint) in the Velox backend.

Changes:
- VeloxConfig.h: Add spark.sql.ansi.enabled config key
- WholeStageResultIterator.cc: Propagate ANSI config to Velox QueryConfig
- CastNode.java: Use int failureBehavior (0=UNSPECIFIED, 1=RETURN_NULL,
  2=THROW_EXCEPTION) instead of boolean isTryCast
- ExpressionBuilder.java: Add makeCast overload with isAnsiCast param
- UnaryExpressionTransformer.scala: Pass withAnsiEvalMode to CastTransformer
- Spark34/35/40Shims.scala: Add Cast to withAnsiEvalMode pattern matching
- VeloxTestSettings.scala: Remove exclusions for ANSI cast overflow tests
- GlutenTryCastSuite.scala: Enable ANSI overflow tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added CORE works for Gluten Core VELOX labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

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

Labels

CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant