Skip to content

[GLUTEN-10134][VL] (STORE_ASSIGNMENT_POLICY defaults to ANSI) Preserve store assignment cast modes - #12051

Open
ReemaAlzaid wants to merge 28 commits into
apache:mainfrom
ReemaAlzaid:store-assignment-policy-cast-modes
Open

[GLUTEN-10134][VL] (STORE_ASSIGNMENT_POLICY defaults to ANSI) Preserve store assignment cast modes#12051
ReemaAlzaid wants to merge 28 commits into
apache:mainfrom
ReemaAlzaid:store-assignment-policy-cast-modes

Conversation

@ReemaAlzaid

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

This PR preserves Spark cast eval mode when Gluten translates casts to Velox, so store assignment casts keep ANSI behavior even when spark.sql.ansi.enabled=false.
#10134

  • Preserves Spark cast mode in Gluten Substrait.
  • Adds Velox ANSI/legacy cast handling.
  • Keeps TRY_CAST as Velox try-cast.
  • Tests default STORE_ASSIGNMENT_POLICY=ANSI.

How was this patch tested?

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

@ReemaAlzaid ReemaAlzaid mentioned this pull request May 7, 2026
53 tasks
@github-actions github-actions Bot added CORE works for Gluten Core VELOX labels May 7, 2026
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid

Copy link
Copy Markdown
Contributor Author

Could you please review this? @rui-mo

@rui-mo rui-mo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any background to support this policy, and would it make sense to add some tests covering the configurable behaviors under different policy settings?

type == BIGINT();
}

bool isAnsiSupported(const TypePtr& fromType, const TypePtr& toType) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a check on the Velox side. Will we maintain the ANSI support check only here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended to mirror the existing Velox ANSI support side check not to replace it, since that check is private today, I added this local helper for the expression level ANSI/legacy cast mode. I’ll add a comment to make sure we keep it aligned with Velox

}
}

testGluten("storeAssignmentPolicy default ANSI is independent from ANSI mode") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be a variant of a Spark test. Can we move it to a new suite under backends-velox/?


spark.sql("CREATE TABLE store_assignment_ansi (c INT) USING PARQUET")
intercept[Exception] {
spark.sql("INSERT INTO store_assignment_ansi SELECT '2147483648'").collect()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check for the exception message to confirm the expected exception is thrown?

@ReemaAlzaid

Copy link
Copy Markdown
Contributor Author

Do we have any background to support this policy, and would it make sense to add some tests covering the configurable behaviors under different policy settings?

My understanding is that Spark applies spark.sql.storeAssignmentPolicy during analysis, and Gluten should just preserve the cast mode Spark selected when translating the resulting casts. Otherwise INSERT/store assignment behavior may differ from Spark. I’ll add tests for the configurable policy cases.

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid
ReemaAlzaid requested a review from philo-he May 14, 2026 12:15
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid
ReemaAlzaid requested a review from rui-mo May 14, 2026 16:20
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@philo-he philo-he left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Two comments, possibly due to missing context on my side.

std::make_shared<SparkCastHooks>(config, allowOverflow));
}

class SparkAnsiCastCallToSpecialForm : public exec::CastCallToSpecialForm {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still wondering if we can move or keep these code on Velox side, and just call the register API in Gluten C++ code. Could you please clarify?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Existing Velox Spark cast depends on session ansiEnabled, but Gluten needs Substrait’s per expression cast mode. This patch adds thin Gluten registration while reusing Velox cast code. I agree we can move it to Velox and call the registration API from Gluten

// Keep this in sync with Velox's SparkCastCallToSpecialForm::isAnsiSupported.
// Velox's helper is private today; this local copy is needed for expression-level
// ANSI and legacy cast modes.
bool isAnsiSupported(const TypePtr& fromType, const TypePtr& toType) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really need it, to reduce code maintenance effort, could we make it public in Velox to allow calling it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created the pr here facebookincubator/velox#17687

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid
ReemaAlzaid requested a review from philo-he June 9, 2026 12:03
@philo-he

Copy link
Copy Markdown
Member

@ReemaAlzaid, thanks for the update. Could you check if the CI failures are related?

@ReemaAlzaid

Copy link
Copy Markdown
Contributor Author

The pr got merged facebookincubator/velox#17687 @philo-he

@philo-he

philo-he commented Jul 8, 2026

Copy link
Copy Markdown
Member

The pr got merged facebookincubator/velox#17687 @philo-he

@ReemaAlzaid, thanks for the update. I noticed the CI failed. Is it because Gluten's referenced Velox branch doesn't yet include that Velox commit? If so, you could reference the PR ID in the following code so Gluten picks up that Velox patch for the CI tests.

UPSTREAM_VELOX_PR_ID=""

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid

ReemaAlzaid commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Hey @philo-he, the velox commit is added now and has been merged I just forgot to update the ansi config key class here Fix Spark ANSI config key in cast tests. So the CI should run fine now

@philo-he

philo-he commented Jul 8, 2026

Copy link
Copy Markdown
Member

@ReemaAlzaid, thanks for the update. It seems that CI failure is related. Could you check further? Thank you!

- storeAssignmentPolicy preserves configured cast modes *** FAILED ***
  executedPlan.exists(((plan: org.apache.spark.sql.execution.SparkPlan) => tag.runtimeClass.isInstance(plan))) was false Expect ProjectExecTransformer exists in executedPlan:
   CommandResult <empty>
     +- Execute InsertIntoHadoopFsRelationCommand file:/__w/gluten/gluten/backends-velox/spark-warehouse/org.apache.gluten.execution.VeloxInsertSuite/store_assignment_legacy, false, Parquet, [path=file:/__w/gluten/gluten/backends-velox/spark-warehouse/org.apache.gluten.execution.VeloxInsertSuite/store_assignment_legacy], Append, `spark_catalog`.`default`.`store_assignment_legacy`, org.apache.spark.sql.execution.datasources.InMemoryFileIndex(file:/__w/gluten/gluten/backends-velox/spark-warehouse/org.apache.gluten.execution.VeloxInsertSuite/store_assignment_legacy), [c]
        +- WriteFiles
           +- *(1) Project [cast(c#242653 as int) AS c#242655]
              +- *(1) ColumnarToRow
                 +- FileScan parquet spark_catalog.default.store_assignment_legacy_src[c#242653] Batched: true, DataFilters: [], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/__w/gluten/gluten/backends-velox/spark-warehouse/org.apache.glut..., PartitionFilters: [], PushedFilters: [], ReadSchema: struct<c:string> (GlutenQueryTest.scala:427)

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid
ReemaAlzaid force-pushed the store-assignment-policy-cast-modes branch from 10c7de5 to 7dc2bef Compare August 12, 2026 15:48
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@philo-he

Copy link
Copy Markdown
Member

@ReemaAlzaid, thanks for the iterating. Could you check if the clickhouse backend CI failure is related? You can use this account to login:

public read-only account:gluten/hN2xX3uQ4m

If not related, you can re-trigger that CI by posting a comment to this PR page: Run Gluten Clickhouse CI on x86.

toType: String)(f: => Unit): Unit = {
val exception = intercept[AnalysisException](f)
// Older Spark versions report the types in lower case, e.g. "string to int",
// while newer ones quote them in upper case, e.g. "STRING" to "INT".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
Could you leave some details about since which Spark versions upper case is used? Then, we can remove the case conversion when those old Spark versions are deprecated.

You may clarify like this "Since Spark xxx, the types in the exception message are in upper case, e.g. ...."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you leave some details about since which Spark versions upper case is used? Then, we can remove the case conversion when those old Spark versions are deprecated.

You may clarify like this "Since Spark xxx, the types in the exception message are in upper case, e.g. ...."

Sure I have added the comment thanks

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@ReemaAlzaid

Copy link
Copy Markdown
Contributor Author

Hey @philo-he thanks for the review! I have addressed the comments and reran the CI

@ReemaAlzaid
ReemaAlzaid requested a review from philo-he August 13, 2026 19:44
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.

3 participants