This is an automated email from the ASF dual-hosted git repository.
zhztheplayer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 35398b7556 [GLUTEN-11912][VL] Translate Velox assert_not_null errors
to Spark's NOT_NULL_ASSERT_VIOLATION exception (#13780)
35398b7556 is described below
commit 35398b75563db509d89b37591f6c8e6d98aa8911
Author: Pedrum Jalali <[email protected]>
AuthorDate: Thu Nov 26 09:40:03 2026 -0800
[GLUTEN-11912][VL] Translate Velox assert_not_null errors to Spark's
NOT_NULL_ASSERT_VIOLATION exception (#13780)
---
.../vectorized/ColumnarBatchOutIterator.java | 27 +++
.../gluten/utils/velox/VeloxTestSettings.scala | 39 +---
.../sql/GlutenRuntimeNullChecksV2Writes.scala | 241 +--------------------
.../GlutenGroupBasedUpdateTableSuite.scala | 3 +-
.../gluten/utils/velox/VeloxTestSettings.scala | 39 +---
.../sql/GlutenRuntimeNullChecksV2Writes.scala | 238 +-------------------
.../GlutenGroupBasedUpdateTableSuite.scala | 3 +-
.../gluten/utils/velox/VeloxTestSettings.scala | 53 +----
.../sql/GlutenRuntimeNullChecksV2Writes.scala | 238 +-------------------
.../sql/connector/GlutenUpdateTableSuiteBase.scala | 7 +-
.../spark/sql/sources/GlutenInsertSuite.scala | 182 +---------------
11 files changed, 48 insertions(+), 1022 deletions(-)
diff --git
a/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
b/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
index fb0baab238..8bb9ef5e75 100644
---
a/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
+++
b/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
@@ -143,6 +143,10 @@ public class ColumnarBatchOutIterator extends
ClosableIterator<ColumnarBatch>
private static final Pattern CHAR_VARCHAR_LENGTH_EXCEEDED =
Pattern.compile("Exceeds allowed length limitation: (\\d+)");
+ // Velox's message when assert_not_null finds a null in a non-nullable field.
+ private static final Pattern NOT_NULL_ASSERT_VIOLATED =
+ Pattern.compile("^Reason: Null value appeared in non-nullable field$",
Pattern.MULTILINE);
+
/**
* Translates a Velox type conversion error into a
SchemaColumnConvertNotSupportedException.
* Returns null if the message does not indicate a type conversion error.
@@ -174,6 +178,25 @@ public class ColumnarBatchOutIterator extends
ClosableIterator<ColumnarBatch>
"EXCEED_LIMIT_LENGTH", new Map.Map1<>("limit", limit), e, new
QueryContext[0], "");
}
+ /**
+ * Translates a Velox assert_not_null failure into the exception Spark
throws for a null in a
+ * non-nullable field. Returns null if the message does not indicate one.
+ */
+ private static RuntimeException translateToNotNullAssertViolation(String
msg, Exception e) {
+ // Spark 3.x throws a NullPointerException whose message names the field
instead.
+ if (!SparkVersionUtil.gteSpark40() ||
!NOT_NULL_ASSERT_VIOLATED.matcher(msg).find()) {
+ return null;
+ }
+ // Builds the exception QueryExecutionErrors.notNullAssertViolation
builds. Velox's message
+ // does not name the field, so the path is "\n\n", the value Spark uses
when it has none.
+ return new SparkRuntimeException(
+ "NOT_NULL_ASSERT_VIOLATION",
+ new Map.Map1<>("walkedTypePath", "\n\n"),
+ e,
+ new QueryContext[0],
+ "");
+ }
+
@Override
protected RuntimeException translateException(Exception e) {
String msg = findFirstNonNullMessage(e);
@@ -187,6 +210,10 @@ public class ColumnarBatchOutIterator extends
ClosableIterator<ColumnarBatch>
if (lengthEx != null) {
return lengthEx;
}
+ RuntimeException notNullEx = translateToNotNullAssertViolation(msg, e);
+ if (notNullEx != null) {
+ return notNullEx;
+ }
}
// A GlutenException raised by native/nested code is already translated;
return it
// as-is rather than nesting it in another GlutenException. Keep this
after every more
diff --git
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 604bcdf2ce..5abf0896fc 100644
---
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -61,8 +61,6 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2FunctionSuite]
enableSuite[GlutenDataSourceV2SQLSessionCatalogSuite]
enableSuite[GlutenDataSourceV2SQLSuiteV1Filter]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("CreateTableAsSelect: nullable schema")
enableSuite[GlutenDataSourceV2SQLSuiteV2Filter]
enableSuite[GlutenDataSourceV2Suite]
// Rewrite the following tests in GlutenDataSourceV2Suite.
@@ -269,7 +267,7 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2OptionSuite]
enableSuite[GlutenDataSourceV2UtilsSuite]
enableSuite[GlutenGroupBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenMergeIntoDataFrameSuite]
enableSuite[GlutenProcedureSuite]
@@ -846,8 +844,6 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFilteredScanSuite]
enableSuite[GlutenFiltersSuite]
enableSuite[GlutenInsertSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("SPARK-24583 Wrong schema type in InsertIntoDataSourceCommand")
// the native write staing dir is differnt with vanilla Spark for coustom
partition paths
.exclude("SPARK-35106: Throw exception when rename custom partition paths
returns false")
// The case expects a SparkException; Gluten surfaces the raw
@@ -1203,51 +1199,22 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenBitmapExpressionsQuerySuite]
enableSuite[GlutenEmptyInSuite]
enableSuite[GlutenRuntimeNullChecksV2Writes]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("NOT NULL checks for atomic top-level fields (byName)")
- .exclude("NOT NULL checks for atomic top-level fields (byPosition)")
- .exclude("NOT NULL checks for nested struct fields (byName)")
- .exclude("NOT NULL checks for nested struct fields (byPosition)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byName)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable array (byName)")
- // Overridden.
- .exclude("not null checks for fields inside nullable array (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values (byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byName)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byPosition)")
enableSuite[GlutenTableOptionsConstantFoldingSuite]
enableSuite[GlutenDeltaBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedMergeIntoTableUpdateAsDeleteAndInsertSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedUpdateAsDeleteAndInsertTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenDeltaBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenGroupBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenFileSourceCustomMetadataStructSuite]
enableSuite[GlutenParquetFileMetadataStructRowIndexSuite]
enableSuite[GlutenTableLocationSuite]
diff --git
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
index d8e83175c1..abd997bea8 100644
---
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
+++
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
@@ -16,243 +16,4 @@
*/
package org.apache.spark.sql
-import org.apache.gluten.exception.GlutenException
-
-import org.apache.spark.SparkException
-import org.apache.spark.sql.connector.catalog.{Column => ColumnV2, Identifier}
-import org.apache.spark.sql.connector.expressions.Transform
-import org.apache.spark.sql.types.{ArrayType, IntegerType, MapType, StructType}
-
-import java.util.Collections
-
-class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {
-
- /**
- * Shadows Spark's `assertNotNullException`, which is private and so cannot
be reused.
- *
- * Spark expects a `SparkRuntimeException` carrying
`NOT_NULL_ASSERT_VIOLATION` and never reads
- * `colPath`. When the projection is offloaded, Velox `assert_not_null`
raises a `VeloxUserError`
- * instead, which reaches the test as a `SparkException` whose cause is a
`GlutenException`
- * carrying the reason text but not the error condition.
- */
- private def assertNotNullException(e: SparkException, colPath: Seq[String]):
Unit = {
- e.getCause match {
- case ge: GlutenException =>
- assert(
- ge.getMessage.contains("Null value appeared in non-nullable field"),
- s"expected a not-null violation for ${colPath.mkString(".")},
got:\n${ge.getMessage}"
- )
- case other =>
- fail(s"Unexpected exception cause: $other")
- }
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byName)") {
- checkNullableArrayWithNotNullElement(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byPosition)") {
- checkNullableArrayWithNotNullElement(byName = false)
- }
-
- private def checkNullableArrayWithNotNullElement(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int").add("y", "int")
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- columns = Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = false))),
- partitions = Array.empty[Transform],
- properties = Collections.emptyMap[String, String]
- )
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS arr")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS arr)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable array (byName)") {
- checkNotNullFieldsInsideNullableArray(byName = true)
- }
-
- testGluten("not null checks for fields inside nullable array (byPosition)") {
- checkNotNullFieldsInsideNullableArray(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableArray(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- columns = Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = true))),
- partitions = Array.empty[Transform],
- properties = Collections.emptyMap[String, String]
- )
-
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- checkAnswer(spark.table("t"), Row(1, List(null, Row(1, 1))))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element", "x"))
- }
- }
-
- testGluten("NOT NULL checks for nullable map with required values (byName)")
{
- checkNullableMapWithNonNullValues(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable map with required values
(byPosition)") {
- checkNullableMapWithNonNullValues(byName = false)
- }
-
- private def checkNullableMapWithNonNullValues(byName: Boolean): Unit = {
- withTable("t") {
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- columns = Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(IntegerType, IntegerType,
valueContainsNull = false))),
- partitions = Array.empty[Transform],
- properties = Collections.emptyMap[String, String]
- )
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(1, null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(1, null) AS m)")
- }
- }
- assertNotNullException(e, Seq("m", "value"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byName)") {
- checkNotNullFieldsInsideNullableMap(byName = true)
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byPosition)") {
- checkNotNullFieldsInsideNullableMap(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableMap(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- columns = Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(structType, structType,
valueContainsNull = true))),
- partitions = Array.empty[Transform],
- properties = Collections.emptyMap[String, String]
- )
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, Map(Row(1, 1) -> null)))
-
- val e1 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e1, Seq("m", "key", "x"))
-
- val e2 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e2, Seq("m", "value", "x"))
- }
- }
-}
+class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {}
diff --git
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
index 4c400fa07a..5ce34ad622 100644
---
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
+++
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
@@ -16,7 +16,6 @@
*/
package org.apache.spark.sql.connector
-import org.apache.spark.SparkException
import org.apache.spark.sql.GlutenSQLTestsTrait
class GlutenGroupBasedUpdateTableSuite
@@ -24,7 +23,7 @@ class GlutenGroupBasedUpdateTableSuite
with GlutenSQLTestsTrait {
private def assertNotNullViolation(f: => Unit): Unit = {
- val exception = intercept[SparkException](f)
+ val exception = intercept[Exception](f)
val messages = Iterator
.iterate[Throwable](exception)(_.getCause)
.takeWhile(_ != null)
diff --git
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index ea6a17c748..e19eefd4db 100644
---
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -61,8 +61,6 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2FunctionSuite]
enableSuite[GlutenDataSourceV2SQLSessionCatalogSuite]
enableSuite[GlutenDataSourceV2SQLSuiteV1Filter]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("CreateTableAsSelect: nullable schema")
enableSuite[GlutenDataSourceV2SQLSuiteV2Filter]
enableSuite[GlutenDataSourceV2Suite]
// Rewrite the following tests in GlutenDataSourceV2Suite.
@@ -279,7 +277,7 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2OptionSuite]
enableSuite[GlutenDataSourceV2UtilsSuite]
enableSuite[GlutenGroupBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenMergeIntoDataFrameSuite]
enableSuite[GlutenProcedureSuite]
@@ -829,8 +827,6 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFilteredScanSuite]
enableSuite[GlutenFiltersSuite]
enableSuite[GlutenInsertSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("SPARK-24583 Wrong schema type in InsertIntoDataSourceCommand")
// the native write staing dir is differnt with vanilla Spark for coustom
partition paths
.exclude("SPARK-35106: Throw exception when rename custom partition paths
returns false")
// The case expects a SparkException; Gluten surfaces the raw
@@ -1204,51 +1200,22 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenBitmapExpressionsQuerySuite]
enableSuite[GlutenEmptyInSuite]
enableSuite[GlutenRuntimeNullChecksV2Writes]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("NOT NULL checks for atomic top-level fields (byName)")
- .exclude("NOT NULL checks for atomic top-level fields (byPosition)")
- .exclude("NOT NULL checks for nested struct fields (byName)")
- .exclude("NOT NULL checks for nested struct fields (byPosition)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byName)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable array (byName)")
- // Overridden.
- .exclude("not null checks for fields inside nullable array (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values (byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byName)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byPosition)")
enableSuite[GlutenTableOptionsConstantFoldingSuite]
enableSuite[GlutenDeltaBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedMergeIntoTableUpdateAsDeleteAndInsertSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedUpdateAsDeleteAndInsertTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenDeltaBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
enableSuite[GlutenGroupBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenFileSourceCustomMetadataStructSuite]
enableSuite[GlutenParquetFileMetadataStructRowIndexSuite]
enableSuite[GlutenTableLocationSuite]
diff --git
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
index e677abdce6..abd997bea8 100644
---
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
+++
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
@@ -16,240 +16,4 @@
*/
package org.apache.spark.sql
-import org.apache.gluten.exception.GlutenException
-
-import org.apache.spark.SparkException
-import org.apache.spark.sql.connector.catalog.{Column => ColumnV2, Identifier,
TableInfo}
-import org.apache.spark.sql.types.{ArrayType, IntegerType, MapType, StructType}
-
-class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {
-
- /**
- * Shadows Spark's `assertNotNullException`, which is private and so cannot
be reused.
- *
- * Spark expects a `SparkRuntimeException` carrying
`NOT_NULL_ASSERT_VIOLATION` and never reads
- * `colPath`. When the projection is offloaded, Velox `assert_not_null`
raises a `VeloxUserError`
- * instead, which reaches the test as a `SparkException` whose cause is a
`GlutenException`
- * carrying the reason text but not the error condition.
- */
- private def assertNotNullException(e: SparkException, colPath: Seq[String]):
Unit = {
- e.getCause match {
- case ge: GlutenException =>
- assert(
- ge.getMessage.contains("Null value appeared in non-nullable field"),
- s"expected a not-null violation for ${colPath.mkString(".")},
got:\n${ge.getMessage}"
- )
- case other =>
- fail(s"Unexpected exception cause: $other")
- }
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byName)") {
- checkNullableArrayWithNotNullElement(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byPosition)") {
- checkNullableArrayWithNotNullElement(byName = false)
- }
-
- private def checkNullableArrayWithNotNullElement(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int").add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = false))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS arr")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS arr)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable array (byName)") {
- checkNotNullFieldsInsideNullableArray(byName = true)
- }
-
- testGluten("not null checks for fields inside nullable array (byPosition)") {
- checkNotNullFieldsInsideNullableArray(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableArray(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = true))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- checkAnswer(spark.table("t"), Row(1, List(null, Row(1, 1))))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element", "x"))
- }
- }
-
- testGluten("NOT NULL checks for nullable map with required values (byName)")
{
- checkNullableMapWithNonNullValues(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable map with required values
(byPosition)") {
- checkNullableMapWithNonNullValues(byName = false)
- }
-
- private def checkNullableMapWithNonNullValues(byName: Boolean): Unit = {
- withTable("t") {
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(IntegerType, IntegerType,
valueContainsNull = false))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(1, null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(1, null) AS m)")
- }
- }
- assertNotNullException(e, Seq("m", "value"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byName)") {
- checkNotNullFieldsInsideNullableMap(byName = true)
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byPosition)") {
- checkNotNullFieldsInsideNullableMap(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableMap(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(structType, structType,
valueContainsNull = true))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, Map(Row(1, 1) -> null)))
-
- val e1 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e1, Seq("m", "key", "x"))
-
- val e2 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e2, Seq("m", "value", "x"))
- }
- }
-}
+class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {}
diff --git
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
index 4c400fa07a..5ce34ad622 100644
---
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
+++
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/connector/GlutenGroupBasedUpdateTableSuite.scala
@@ -16,7 +16,6 @@
*/
package org.apache.spark.sql.connector
-import org.apache.spark.SparkException
import org.apache.spark.sql.GlutenSQLTestsTrait
class GlutenGroupBasedUpdateTableSuite
@@ -24,7 +23,7 @@ class GlutenGroupBasedUpdateTableSuite
with GlutenSQLTestsTrait {
private def assertNotNullViolation(f: => Unit): Unit = {
- val exception = intercept[SparkException](f)
+ val exception = intercept[Exception](f)
val messages = Iterator
.iterate[Throwable](exception)(_.getCause)
.takeWhile(_ != null)
diff --git
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 0a90af2ad3..4c8cfd6f14 100644
---
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -70,8 +70,6 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2FunctionSuite]
enableSuite[GlutenDataSourceV2SQLSessionCatalogSuite]
enableSuite[GlutenDataSourceV2SQLSuiteV1Filter]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("CreateTableAsSelect: nullable schema")
enableSuite[GlutenDataSourceV2SQLSuiteV2Filter]
enableSuite[GlutenDataSourceV2Suite]
// Rewrite the following tests in GlutenDataSourceV2Suite.
@@ -304,9 +302,9 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenDataSourceV2OptionSuite]
enableSuite[GlutenDataSourceV2UtilsSuite]
enableSuite[GlutenGroupBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException.
+ // A nested native pipeline wraps NOT_NULL_ASSERT_VIOLATION in a
GlutenException.
// Rewritten in GlutenUpdateTableSuiteBase.
.exclude("update with constraint violation and transactional checks")
enableSuite[GlutenMergeIntoDataFrameSuite]
@@ -875,21 +873,11 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFilteredScanSuite]
enableSuite[GlutenFiltersSuite]
enableSuite[GlutenInsertSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("SPARK-24583 Wrong schema type in InsertIntoDataSourceCommand")
// the native write staing dir is differnt with vanilla Spark for coustom
partition paths
.exclude("SPARK-35106: Throw exception when rename custom partition paths
returns false")
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException.
- // Rewritten in GlutenInsertSuite.
- .exclude("SPARK-55716: V1 INSERT rejects null into NOT NULL column for
file sources")
- .exclude("SPARK-55716: V1 INSERT NOT NULL enforcement respects
storeAssignmentPolicy")
- .exclude("SPARK-55716: V1 INSERT rejects null with V2 file source path")
- .exclude("SPARK-55716: V1 INSERT rejects null array element for NOT NULL
element type")
- .exclude("SPARK-55716: V1 INSERT rejects null struct field for NOT NULL
field")
- .exclude("SPARK-55716: V1 INSERT rejects null map value for NOT NULL value
type")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
@@ -1290,57 +1278,28 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenBitmapExpressionsQuerySuite]
enableSuite[GlutenEmptyInSuite]
enableSuite[GlutenRuntimeNullChecksV2Writes]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("NOT NULL checks for atomic top-level fields (byName)")
- .exclude("NOT NULL checks for atomic top-level fields (byPosition)")
- .exclude("NOT NULL checks for nested struct fields (byName)")
- .exclude("NOT NULL checks for nested struct fields (byPosition)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byName)")
- .exclude("NOT NULL checks for nested structs, arrays, maps (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable array with required element
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable array (byName)")
- // Overridden.
- .exclude("not null checks for fields inside nullable array (byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values (byName)")
- // Overridden.
- .exclude("NOT NULL checks for nullable map with required values
(byPosition)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byName)")
- // Overridden.
- .exclude("NOT NULL checks for fields inside nullable maps (byPosition)")
enableSuite[GlutenTableOptionsConstantFoldingSuite]
enableSuite[GlutenDeltaBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedMergeIntoTableUpdateAsDeleteAndInsertSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenDeltaBasedUpdateAsDeleteAndInsertTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException.
+ // A nested native pipeline wraps NOT_NULL_ASSERT_VIOLATION in a
GlutenException.
// Rewritten in GlutenUpdateTableSuiteBase.
.exclude("update with constraint violation and transactional checks")
enableSuite[GlutenDeltaBasedUpdateTableSuite]
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
+ // Velox assert_not_null's error does not name the field, so
walkedTypePath is empty
.exclude("update with NOT NULL checks")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException.
+ // A nested native pipeline wraps NOT_NULL_ASSERT_VIOLATION in a
GlutenException.
// Rewritten in GlutenUpdateTableSuiteBase.
.exclude("update with constraint violation and transactional checks")
enableSuite[GlutenGroupBasedMergeIntoTableSuite]
// Replaced by Gluten versions that handle wrapped exceptions
.excludeByPrefix("merge cardinality check with")
- // Velox assert_not_null throws VeloxUserError instead of
SparkRuntimeException
- .exclude("merge with NOT NULL checks")
enableSuite[GlutenFileSourceCustomMetadataStructSuite]
enableSuite[GlutenParquetFileMetadataStructRowIndexSuite]
enableSuite[GlutenTableLocationSuite]
diff --git
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
index e677abdce6..abd997bea8 100644
---
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
+++
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala
@@ -16,240 +16,4 @@
*/
package org.apache.spark.sql
-import org.apache.gluten.exception.GlutenException
-
-import org.apache.spark.SparkException
-import org.apache.spark.sql.connector.catalog.{Column => ColumnV2, Identifier,
TableInfo}
-import org.apache.spark.sql.types.{ArrayType, IntegerType, MapType, StructType}
-
-class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {
-
- /**
- * Shadows Spark's `assertNotNullException`, which is private and so cannot
be reused.
- *
- * Spark expects a `SparkRuntimeException` carrying
`NOT_NULL_ASSERT_VIOLATION` and never reads
- * `colPath`. When the projection is offloaded, Velox `assert_not_null`
raises a `VeloxUserError`
- * instead, which reaches the test as a `SparkException` whose cause is a
`GlutenException`
- * carrying the reason text but not the error condition.
- */
- private def assertNotNullException(e: SparkException, colPath: Seq[String]):
Unit = {
- e.getCause match {
- case ge: GlutenException =>
- assert(
- ge.getMessage.contains("Null value appeared in non-nullable field"),
- s"expected a not-null violation for ${colPath.mkString(".")},
got:\n${ge.getMessage}"
- )
- case other =>
- fail(s"Unexpected exception cause: $other")
- }
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byName)") {
- checkNullableArrayWithNotNullElement(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable array with required element
(byPosition)") {
- checkNullableArrayWithNotNullElement(byName = false)
- }
-
- private def checkNullableArrayWithNotNullElement(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int").add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = false))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS arr")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS arr)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable array (byName)") {
- checkNotNullFieldsInsideNullableArray(byName = true)
- }
-
- testGluten("not null checks for fields inside nullable array (byPosition)") {
- checkNotNullFieldsInsideNullableArray(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableArray(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("arr", ArrayType(structType, containsNull = true))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', 1, 'y', 1)) AS arr)
- """.stripMargin)
- }
- checkAnswer(spark.table("t"), Row(1, List(null, Row(1, 1))))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | array(null, named_struct('x', null, 'y', 1)) AS arr)
- """.stripMargin)
- }
- }
- assertNotNullException(e, Seq("arr", "element", "x"))
- }
- }
-
- testGluten("NOT NULL checks for nullable map with required values (byName)")
{
- checkNullableMapWithNonNullValues(byName = true)
- }
-
- testGluten("NOT NULL checks for nullable map with required values
(byPosition)") {
- checkNullableMapWithNonNullValues(byName = false)
- }
-
- private def checkNullableMapWithNonNullValues(byName: Boolean): Unit = {
- withTable("t") {
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(IntegerType, IntegerType,
valueContainsNull = false))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, null AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, null AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, null))
-
- val e = intercept[SparkException] {
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(1, null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(1, null) AS m)")
- }
- }
- assertNotNullException(e, Seq("m", "value"))
- }
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byName)") {
- checkNotNullFieldsInsideNullableMap(byName = true)
- }
-
- testGluten("NOT NULL checks for fields inside nullable maps (byPosition)") {
- checkNotNullFieldsInsideNullableMap(byName = false)
- }
-
- private def checkNotNullFieldsInsideNullableMap(byName: Boolean): Unit = {
- withTable("t") {
- val structType = new StructType().add("x", "int", nullable =
false).add("y", "int")
- val tableInfo = new TableInfo.Builder()
- .withColumns(Array(
- ColumnV2.create("i", IntegerType),
- ColumnV2.create("m", MapType(structType, structType,
valueContainsNull = true))))
- .build()
- catalog.createTable(
- ident = Identifier.of(Array(), "t"),
- tableInfo = tableInfo)
-
- if (byName) {
- val inputDF = sql("SELECT 1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m")
- inputDF.writeTo("t").append()
- } else {
- sql("INSERT INTO t VALUES (1 AS i, map(named_struct('x', 1, 'y', 1),
null) AS m)")
- }
- checkAnswer(spark.table("t"), Row(1, Map(Row(1, 1) -> null)))
-
- val e1 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', null, 'y', 1), null) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e1, Seq("m", "key", "x"))
-
- val e2 = intercept[SparkException] {
- if (byName) {
- val inputDF = sql(
- s"""SELECT
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m
- """.stripMargin)
- inputDF.writeTo("t").append()
- } else {
- sql(
- s"""INSERT INTO t VALUES (
- | 1 AS i,
- | map(named_struct('x', 1, 'y', 1), named_struct('x', null,
'y', 1)) AS m)
- """.stripMargin)
- }
- }
- assertNotNullException(e2, Seq("m", "value", "x"))
- }
- }
-}
+class GlutenRuntimeNullChecksV2Writes extends RuntimeNullChecksV2Writes with
GlutenSQLTestsTrait {}
diff --git
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/connector/GlutenUpdateTableSuiteBase.scala
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/connector/GlutenUpdateTableSuiteBase.scala
index 5dc767e102..854928baf4 100644
---
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/connector/GlutenUpdateTableSuiteBase.scala
+++
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/connector/GlutenUpdateTableSuiteBase.scala
@@ -16,19 +16,18 @@
*/
package org.apache.spark.sql.connector
-import org.apache.spark.SparkException
import org.apache.spark.sql.GlutenSQLTestsBaseTrait
import org.apache.spark.sql.connector.catalog.Aborted
/**
* Gluten versions of [[UpdateTableSuiteBase]] tests that expect Spark's
- * `SparkRuntimeException(NOT_NULL_ASSERT_VIOLATION)`. Velox `assert_not_null`
throws a
- * `VeloxUserError` instead, which fails the query with a `SparkException`.
+ * `SparkRuntimeException(NOT_NULL_ASSERT_VIOLATION)`. Velox `assert_not_null`
does not report the
+ * field path, and a nested native pipeline wraps the exception in a
`GlutenException`.
*/
trait GlutenUpdateTableSuiteBase extends UpdateTableSuiteBase with
GlutenSQLTestsBaseTrait {
protected def assertNotNullViolation(f: => Unit): Unit = {
- val exception = intercept[SparkException](f)
+ val exception = intercept[Exception](f)
val messages = Iterator
.iterate[Throwable](exception)(_.getCause)
.takeWhile(_ != null)
diff --git
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
index d3b36feb19..ef4f92c2a3 100644
---
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
+++
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
@@ -20,18 +20,15 @@ import org.apache.gluten.GlutenColumnarWriteTestSupport
import org.apache.gluten.execution.GlutenPlan
import org.apache.gluten.execution.SortExecTransformer
-import org.apache.spark.{SparkConf, SparkException}
+import org.apache.spark.SparkConf
import org.apache.spark.executor.OutputMetrics
import org.apache.spark.scheduler.{SparkListener, SparkListenerTaskEnd}
import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.TableIdentifier
-import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat,
CatalogTable, CatalogTableType}
import org.apache.spark.sql.execution.{CommandResultExec, GlutenImplicits,
QueryExecution, SparkPlan}
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.execution.command.DataWritingCommandExec
import org.apache.spark.sql.execution.metric.SQLMetric
-import org.apache.spark.sql.internal.SQLConf
-import org.apache.spark.sql.types.{ArrayType, IntegerType, MapType,
StringType, StructType}
import org.apache.spark.sql.util.QueryExecutionListener
import org.apache.hadoop.fs.{Path, RawLocalFileSystem}
@@ -275,183 +272,6 @@ class GlutenInsertSuite
checkWriteFilesAndGetChild(df)
}
}
- // Spark's SPARK-55716 tests expect a
SparkRuntimeException(NOT_NULL_ASSERT_VIOLATION).
- // Velox assert_not_null throws a VeloxUserError instead, which fails the
query with a
- // SparkException.
- private def assertNotNullViolation(f: => Unit): Unit = {
- val exception = intercept[SparkException](f)
- val messages = Iterator
- .iterate[Throwable](exception)(_.getCause)
- .takeWhile(_ != null)
- .flatMap(e => Option(e.getMessage))
-
- assert(messages.exists(_.contains("Null value appeared in non-nullable
field")))
- }
-
- testGluten("SPARK-55716: V1 INSERT rejects null into NOT NULL column for
file sources") {
- Seq("parquet", "orc", "json").foreach {
- format =>
- withSQLConf(SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true")
{
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL, s STRING NOT NULL) USING
$format")
- assertNotNullViolation {
- sql("INSERT INTO t VALUES(null, 'a')")
- }
- assertNotNullViolation {
- sql("INSERT INTO t VALUES(1, null)")
- }
- sql("INSERT INTO t VALUES(1, 'a')")
- checkAnswer(spark.table("t"), Seq(Row(1, "a")))
- }
- }
- }
- }
-
- testGluten("SPARK-55716: V1 INSERT NOT NULL enforcement respects
storeAssignmentPolicy") {
- Seq("parquet", "orc").foreach {
- format =>
- // ANSI mode (default): rejects null
- withSQLConf(
- SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true",
- SQLConf.STORE_ASSIGNMENT_POLICY.key ->
SQLConf.StoreAssignmentPolicy.ANSI.toString) {
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL) USING $format")
- assertNotNullViolation {
- sql("INSERT INTO t VALUES(null)")
- }
- }
- }
- // STRICT mode: also rejects null (fails at analysis with type
mismatch)
- withSQLConf(
- SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true",
- SQLConf.STORE_ASSIGNMENT_POLICY.key ->
SQLConf.StoreAssignmentPolicy.STRICT.toString) {
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL) USING $format")
- intercept[AnalysisException] {
- sql("INSERT INTO t VALUES(null)")
- }
- }
- }
- // LEGACY mode: allows null (no AssertNotNull injected)
- withSQLConf(
- SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true",
- SQLConf.STORE_ASSIGNMENT_POLICY.key ->
SQLConf.StoreAssignmentPolicy.LEGACY.toString) {
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL) USING $format")
- sql("INSERT INTO t VALUES(null)")
- checkAnswer(spark.table("t"), Seq(Row(null)))
- }
- }
- // Legacy config: allows null even in ANSI mode
- withSQLConf(
- SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "false",
- SQLConf.STORE_ASSIGNMENT_POLICY.key ->
SQLConf.StoreAssignmentPolicy.ANSI.toString) {
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL) USING $format")
- sql("INSERT INTO t VALUES(null)")
- checkAnswer(spark.table("t"), Seq(Row(null)))
- }
- }
- }
- }
-
- testGluten("SPARK-55716: V1 INSERT rejects null with V2 file source path") {
- Seq("parquet", "orc").foreach {
- format =>
- withSQLConf(
- SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true",
- SQLConf.USE_V1_SOURCE_LIST.key -> "") {
- withTable("t") {
- sql(s"CREATE TABLE t(i INT NOT NULL, s STRING NOT NULL) USING
$format")
- assertNotNullViolation {
- sql("INSERT INTO t VALUES(null, 'a')")
- }
- }
- }
- }
- }
-
- testGluten("SPARK-55716: V1 INSERT rejects null array element for NOT NULL
element type") {
- Seq("parquet", "orc").foreach {
- format =>
- withSQLConf(SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true")
{
- withTable("t") {
- val schema = new StructType()
- .add("a", ArrayType(IntegerType, containsNull = false))
- spark.sessionState.catalog.createTable(
- CatalogTable(
- identifier = TableIdentifier("t"),
- tableType = CatalogTableType.MANAGED,
- storage = CatalogStorageFormat.empty,
- schema = schema,
- provider = Some(format)),
- ignoreIfExists = false
- )
- assertNotNullViolation {
- sql("INSERT INTO t SELECT array(1, null, 3)")
- }
- sql("INSERT INTO t SELECT array(1, 2, 3)")
- checkAnswer(spark.table("t"), Seq(Row(Seq(1, 2, 3))))
- }
- }
- }
- }
-
- testGluten("SPARK-55716: V1 INSERT rejects null struct field for NOT NULL
field") {
- Seq("parquet", "orc").foreach {
- format =>
- withSQLConf(SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true")
{
- withTable("t") {
- val schema = new StructType()
- .add(
- "s",
- new StructType()
- .add("x", IntegerType, nullable = false)
- .add("y", StringType, nullable = false))
- spark.sessionState.catalog.createTable(
- CatalogTable(
- identifier = TableIdentifier("t"),
- tableType = CatalogTableType.MANAGED,
- storage = CatalogStorageFormat.empty,
- schema = schema,
- provider = Some(format)),
- ignoreIfExists = false
- )
- assertNotNullViolation {
- sql("INSERT INTO t SELECT named_struct('x', null, 'y', 'hello')")
- }
- sql("INSERT INTO t SELECT named_struct('x', 1, 'y', 'hello')")
- checkAnswer(spark.table("t"), Seq(Row(Row(1, "hello"))))
- }
- }
- }
- }
-
- testGluten("SPARK-55716: V1 INSERT rejects null map value for NOT NULL value
type") {
- Seq("parquet", "orc").foreach {
- format =>
- withSQLConf(SQLConf.FILE_SOURCE_INSERT_ENFORCE_NOT_NULL.key -> "true")
{
- withTable("t") {
- val schema = new StructType()
- .add("m", MapType(StringType, IntegerType, valueContainsNull =
false))
- spark.sessionState.catalog.createTable(
- CatalogTable(
- identifier = TableIdentifier("t"),
- tableType = CatalogTableType.MANAGED,
- storage = CatalogStorageFormat.empty,
- schema = schema,
- provider = Some(format)),
- ignoreIfExists = false
- )
- assertNotNullViolation {
- sql("INSERT INTO t SELECT map('a', 1, 'b', null)")
- }
- sql("INSERT INTO t SELECT map('a', 1, 'b', 2)")
- checkAnswer(spark.table("t"), Seq(Row(Map("a" -> 1, "b" -> 2))))
- }
- }
- }
- }
}
class GlutenRenameFromSparkStagingToFinalDirAlwaysTurnsFalseFilesystem extends
RawLocalFileSystem {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]