-
Notifications
You must be signed in to change notification settings - Fork 643
[GLUTEN-10134][VL] Preserve store assignment cast modes (STORE_ASSIGNMENT_POLICY defaults to ANSI)
#12051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
philo-he
merged 28 commits into
apache:main
from
ReemaAlzaid:store-assignment-policy-cast-modes
Aug 17, 2026
Merged
[GLUTEN-10134][VL] Preserve store assignment cast modes (STORE_ASSIGNMENT_POLICY defaults to ANSI)
#12051
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
10414a2
Preserve store assignment cast modes
ReemaAlzaid 44d0731
Address Velox insert review comments
ReemaAlzaid 6e4b609
Add store assignment policy insert tests
ReemaAlzaid 0b6c65a
Preserve store assignment cast modes
ReemaAlzaid 222f1f1
Address Velox insert review comments
ReemaAlzaid a998015
Add store assignment policy insert tests
ReemaAlzaid eea937a
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid b2f41b5
Merge branch 'apache:main' into store-assignment-policy-cast-modes
ReemaAlzaid 89f3284
Merge branch 'store-assignment-policy-cast-modes' of https://github.c…
ReemaAlzaid 8e1a1cb
Use upstream Velox cast mode special forms
ReemaAlzaid 36133ca
Use Velox ANSI cast support helper
ReemaAlzaid 44eb11f
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 2de3e9e
Format Spark cast mode changes
ReemaAlzaid ec071d3
Merge branch 'store-assignment-policy-cast-modes' of https://github.c…
ReemaAlzaid 331bfb9
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 1350edb
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 9cc99a2
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 653285b
Adapt Spark cast mode registration to Velox API
ReemaAlzaid 469c319
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 570e3c2
Fix Spark ANSI config key in cast tests
ReemaAlzaid a21cffc
Merge branch 'store-assignment-policy-cast-modes' of https://github.c…
ReemaAlzaid 06856ba
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 7dc2bef
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid abb474c
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 83d88df
[GLUTEN-10134][VL] Fix CI failures for store assignment cast modes
ReemaAlzaid d69e751
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid 71c3610
Merge branch 'main' into store-assignment-policy-cast-modes
ReemaAlzaid dac6f8f
address comments
ReemaAlzaid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
backends-velox/src/test/scala/org/apache/gluten/execution/VeloxInsertSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.gluten.execution | ||
|
|
||
| import org.apache.gluten.config.GlutenConfig | ||
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.sql.{AnalysisException, Row} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| class VeloxInsertSuite extends VeloxWholeStageTransformerSuite { | ||
| override protected val resourcePath: String = "placeholder" | ||
| override protected val fileFormat: String = "parquet" | ||
|
|
||
| override protected def sparkConf: SparkConf = { | ||
| super.sparkConf | ||
| .set("spark.shuffle.manager", "org.apache.spark.shuffle.sort.ColumnarShuffleManager") | ||
| .set("spark.sql.shuffle.partitions", "1") | ||
| .set("spark.memory.offHeap.size", "2g") | ||
| .set("spark.unsafe.exceptionOnMemoryLeak", "true") | ||
| } | ||
|
|
||
| test("storeAssignmentPolicy default ANSI is independent from ANSI mode") { | ||
| withTable("store_assignment_ansi_src", "store_assignment_ansi") { | ||
| withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") { | ||
| assert(SQLConf.get.storeAssignmentPolicy == SQLConf.StoreAssignmentPolicy.ANSI) | ||
|
|
||
| createTableWithValue("store_assignment_ansi_src", "STRING", "'2147483648'") | ||
| createTable("store_assignment_ansi", "INT") | ||
| assertUnsafeCastAnalysisException("STRING", "INT") { | ||
| insertIntoFrom("store_assignment_ansi", "store_assignment_ansi_src").collect() | ||
| } | ||
|
|
||
| withSQLConf( | ||
| SQLConf.STORE_ASSIGNMENT_POLICY.key -> SQLConf.StoreAssignmentPolicy.LEGACY.toString) { | ||
| val insert = insertIntoFrom("store_assignment_ansi", "store_assignment_ansi_src") | ||
| insert.collect() | ||
| checkGlutenPlan[ProjectExecTransformer](insert) | ||
| checkAnswer(spark.table("store_assignment_ansi"), Row(null)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("storeAssignmentPolicy preserves configured cast modes") { | ||
| withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") { | ||
| withTable("store_assignment_ansi_src", "store_assignment_ansi") { | ||
| createTableWithValue("store_assignment_ansi_src", "STRING", "'2147483648'") | ||
| createTable("store_assignment_ansi", "INT") | ||
|
|
||
| withSQLConf( | ||
| SQLConf.STORE_ASSIGNMENT_POLICY.key -> SQLConf.StoreAssignmentPolicy.ANSI.toString) { | ||
| assertUnsafeCastAnalysisException("STRING", "INT") { | ||
| insertIntoFrom("store_assignment_ansi", "store_assignment_ansi_src").collect() | ||
| } | ||
| checkAnswer(spark.table("store_assignment_ansi"), Seq.empty[Row]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") { | ||
| withTable("store_assignment_legacy_src", "store_assignment_legacy") { | ||
| createTableWithValue("store_assignment_legacy_src", "STRING", "'2147483648'") | ||
| createTable("store_assignment_legacy", "INT") | ||
|
|
||
| // Disable the whole-plan ANSI fallback so the legacy store-assignment cast | ||
| // gets a chance to offload while the session runs in ANSI mode. | ||
| withSQLConf( | ||
| SQLConf.STORE_ASSIGNMENT_POLICY.key -> SQLConf.StoreAssignmentPolicy.LEGACY.toString, | ||
| GlutenConfig.GLUTEN_ANSI_FALLBACK_ENABLED.key -> "false" | ||
| ) { | ||
| val insert = insertIntoFrom("store_assignment_legacy", "store_assignment_legacy_src") | ||
| insert.collect() | ||
| checkGlutenPlan[ProjectExecTransformer](insert) | ||
| checkAnswer(spark.table("store_assignment_legacy"), Row(null)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("storeAssignmentPolicy strict rejects unsafe insert casts") { | ||
| withTable("store_assignment_strict_src", "store_assignment_strict") { | ||
| withSQLConf( | ||
| SQLConf.STORE_ASSIGNMENT_POLICY.key -> SQLConf.StoreAssignmentPolicy.STRICT.toString) { | ||
| createTableWithValue("store_assignment_strict_src", "INT", "1") | ||
| createTable("store_assignment_strict", "TINYINT") | ||
|
|
||
| assertUnsafeCastAnalysisException("INT", "TINYINT") { | ||
| insertIntoFrom("store_assignment_strict", "store_assignment_strict_src").collect() | ||
| } | ||
| checkAnswer(spark.table("store_assignment_strict"), Seq.empty[Row]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def createTable(table: String, dataType: String): Unit = | ||
| spark.sql(s"CREATE TABLE $table (c $dataType) USING PARQUET") | ||
|
|
||
| private def createTableWithValue(table: String, dataType: String, value: String): Unit = { | ||
| createTable(table, dataType) | ||
| spark.sql(s"INSERT INTO $table VALUES ($value)").collect() | ||
| } | ||
|
|
||
| private def insertIntoFrom(target: String, source: String) = | ||
| spark.sql(s"INSERT INTO $target SELECT c FROM $source") | ||
|
|
||
| private def assertUnsafeCastAnalysisException( | ||
| fromType: String, | ||
| 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". | ||
| val message = exceptionMessages(exception).toLowerCase() | ||
| assert(message.contains(fromType.toLowerCase()), message) | ||
| assert(message.contains(toType.toLowerCase()), message) | ||
| assert(message.contains("cast"), message) | ||
| } | ||
|
|
||
| private def exceptionMessages(e: Throwable): String = { | ||
| val message = Option(e.getMessage).getOrElse("") | ||
| if (e.getCause == null) { | ||
| message | ||
| } else { | ||
| message + "\n" + exceptionMessages(e.getCause) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| #include "velox/functions/sparksql/Rand.h" | ||
| #include "velox/functions/sparksql/aggregates/Register.h" | ||
| #include "velox/functions/sparksql/registration/Register.h" | ||
| #include "velox/functions/sparksql/specialforms/SparkCastExpr.h" | ||
| #include "velox/functions/sparksql/window/WindowFunctionsRegistration.h" | ||
|
|
||
| using namespace facebook; | ||
|
|
@@ -84,6 +85,7 @@ void registerFunctionOverwrite() { | |
|
|
||
| void registerAllFunctions() { | ||
| velox::functions::sparksql::registerFunctions(""); | ||
| velox::functions::sparksql::registerSparkCastModeSpecialForms(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| velox::aggregate::prestosql::registerAllAggregateFunctions( | ||
| "", true /*registerCompanionFunctions*/, false /*onlyPrestoSignatures*/, true /*overwrite*/); | ||
| velox::functions::aggregate::sparksql::registerAggregateFunctions( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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. ...."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I have added the comment thanks