This is an automated email from the ASF dual-hosted git repository.
philo-he 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 2e7da69400 [GLUTEN-11494][CORE] Fall back on file-scan existence
defaults (#13667)
2e7da69400 is described below
commit 2e7da69400dff9a6d77ef733630dce8e270cea88
Author: Felipe Pessoto <[email protected]>
AuthorDate: Wed Nov 25 15:31:27 2026 -0800
[GLUTEN-11494][CORE] Fall back on file-scan existence defaults (#13667)
---
.../util/delta-spark-ut/known-failures.txt | 1 -
.../apache/gluten/execution/VeloxDeltaSuite.scala | 30 +-
docs/Configuration.md | 1 +
docs/backends/velox/get-started/VeloxDelta.md | 2 +-
.../org/apache/gluten/config/GlutenConfig.scala | 14 +
.../execution/BasicScanExecTransformer.scala | 19 ++
.../execution/BatchScanExecTransformer.scala | 9 +
.../execution/FileSourceScanExecTransformer.scala | 5 +
.../gluten/utils/bolt/BoltTestSettings.scala | 8 -
.../gluten/utils/velox/VeloxTestSettings.scala | 8 -
.../spark/sql/sources/GlutenInsertSuite.scala | 316 --------------------
.../gluten/utils/bolt/BoltTestSettings.scala | 8 -
.../utils/clickhouse/ClickHouseTestSettings.scala | 9 -
.../gluten/utils/velox/VeloxTestSettings.scala | 8 -
.../spark/sql/sources/GlutenInsertSuite.scala | 317 --------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 9 -
.../gluten/utils/velox/VeloxTestSettings.scala | 8 -
.../spark/sql/sources/GlutenInsertSuite.scala | 319 ---------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 9 -
.../gluten/utils/velox/VeloxTestSettings.scala | 8 -
.../spark/sql/sources/GlutenInsertSuite.scala | 319 ---------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 9 -
.../gluten/utils/velox/VeloxTestSettings.scala | 8 -
.../spark/sql/sources/GlutenInsertSuite.scala | 319 ---------------------
.../execution/GlutenFailOnFallbackSuite.scala | 72 +++++
25 files changed, 150 insertions(+), 1685 deletions(-)
diff --git a/.github/workflows/util/delta-spark-ut/known-failures.txt
b/.github/workflows/util/delta-spark-ut/known-failures.txt
index 4f6b8311f0..58748da6e0 100644
--- a/.github/workflows/util/delta-spark-ut/known-failures.txt
+++ b/.github/workflows/util/delta-spark-ut/known-failures.txt
@@ -48,7 +48,6 @@
org.apache.spark.sql.delta.DeltaSinkNameColumnMappingSuite#partitioned writing a
org.apache.spark.sql.delta.DeltaSuite#SC-8810: skipping deleted file still
throws on corrupted file
org.apache.spark.sql.delta.DeltaSuite#all operations with special characters
in path
org.apache.spark.sql.delta.DeltaSuite#deleted files cause failure by default
-org.apache.spark.sql.delta.DeltaTableCreationSuite#Default column values:
CONVERT TO DELTA keeps EXISTS_DEFAULT
org.apache.spark.sql.delta.DeltaVacuumSuite#vacuum for cdc - delete tombstones
org.apache.spark.sql.delta.DeltaVacuumSuite#vacuum for cdc - update/merge
org.apache.spark.sql.delta.DeltaWithCatalogOwnedBatch100Suite#SC-8810:
skipping deleted file still throws on corrupted file
diff --git
a/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
b/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
index 64407fcaba..cbd6ace935 100644
---
a/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
+++
b/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
@@ -16,12 +16,40 @@
*/
package org.apache.gluten.execution
-import org.apache.gluten.config.VeloxDeltaConfig
+import org.apache.gluten.config.{GlutenConfig, VeloxDeltaConfig}
import org.apache.spark.sql.{DataFrame, Row}
+import org.apache.spark.sql.execution.FileSourceScanExec
+import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.util.SparkVersionUtil
class VeloxDeltaSuite extends DeltaSuite {
+ testWithMinSparkVersion("delta: converted existence defaults fall back only
when read", "4.0") {
+ withSQLConf(
+ SQLConf.ENABLE_DEFAULT_COLUMNS.key -> "true",
+ "spark.databricks.delta.properties.defaults.columnMapping.mode" ->
"none",
+ GlutenConfig.NATIVE_WRITER_ENABLED.key -> "false"
+ ) {
+ withTable("converted_defaults") {
+ spark.sql("CREATE TABLE converted_defaults (id INT) USING parquet")
+ spark.sql("INSERT INTO converted_defaults VALUES (0)")
+ spark.sql("ALTER TABLE converted_defaults ADD COLUMN value INT DEFAULT
1")
+ spark.sql("INSERT INTO converted_defaults VALUES (1, NULL), (2, 5)")
+ spark.sql("CONVERT TO DELTA converted_defaults")
+
+ val allColumns = spark.table("converted_defaults")
+ checkAnswer(allColumns, Seq(Row(0, 1), Row(1, null), Row(2, 5)))
+ val fallbackPlan = getExecutedPlan(allColumns)
+ assert(fallbackPlan.exists(_.isInstanceOf[FileSourceScanExec]))
+ assert(!fallbackPlan.exists(_.isInstanceOf[DeltaScanTransformer]))
+
+ val pruned = spark.sql("SELECT id FROM converted_defaults")
+ checkAnswer(pruned, Seq(Row(0), Row(1), Row(2)))
+
assert(getExecutedPlan(pruned).exists(_.isInstanceOf[DeltaScanTransformer]))
+ }
+ }
+ }
+
test("delta: change data feed scan offload can be disabled") {
withTable("delta_cdf_disabled") {
spark.sql("""
diff --git a/docs/Configuration.md b/docs/Configuration.md
index c2d69de600..17372334ff 100644
--- a/docs/Configuration.md
+++ b/docs/Configuration.md
@@ -147,6 +147,7 @@ Type: ⚓ Static - can only be set before the Spark
application starts; 🔄 Dyn
| spark.gluten.sql.removeNativeWriteFilesSortAndProject | 🔄 |
true | When true, Gluten will remove the vanilla Spark V1Writes
added sort and project for velox backend.
[...]
| spark.gluten.sql.rewrite.dateTimestampComparison | 🔄 |
true | Rewrite the comparision between date and timestamp to
timestamp comparison.For example `from_unixtime(ts) > date` will be rewritten
to `ts > to_unixtime(date)`
[...]
| spark.gluten.sql.scan.detailedMetrics.enabled | 🔄 |
true | When true (default), Velox backend scan operators register
all detailed SQL metrics. When false, only essential scan metrics are
registered to reduce driver memory usage. Also enabled automatically when
spark.gluten.sql.debug is true. Does not affect the ClickHouse backend.
[...]
+| spark.gluten.sql.scan.fallbackOnExistenceDefaults.enabled | 🔄 |
true | When true, V1/V2 file scans reading non-null EXISTS_DEFAULT
columns fall back to Spark, including Parquet/ORC and Delta. Metadata persists
after file rewrites, so fully populated files also fall back. Set false only if
all read files contain the columns or incorrect results for missing fields are
acceptable. Native readers do not materialize these defaults; other fallback
checks still apply. [...]
| spark.gluten.sql.scan.fileSchemeValidation.enabled | 🔄 |
true | When true, enable file path scheme validation for scan.
Validation will fail if file scheme is not supported by registered file
systems, which will cause scan operator fall back.
[...]
| spark.gluten.sql.supported.flattenNestedFunctions | 🔄 |
and,or | Flatten nested functions as one for optimization.
[...]
| spark.gluten.sql.text.input.empty.as.default | 🔄 |
false | treat empty fields in CSV input as default values.
[...]
diff --git a/docs/backends/velox/get-started/VeloxDelta.md
b/docs/backends/velox/get-started/VeloxDelta.md
index 8802476e01..0f534e7292 100644
--- a/docs/backends/velox/get-started/VeloxDelta.md
+++ b/docs/backends/velox/get-started/VeloxDelta.md
@@ -429,7 +429,7 @@ The `mergeSchema` and `overwriteSchema` rows need native
write on Spark 3.5 or 4
| Problem | Status | Versions | Issue |
|---|---|---|---|
-| A column default stored as `EXISTS_DEFAULT` metadata, for example after
`CONVERT TO DELTA`, reads as NULL for rows in files without that column. |
ResultMismatch | Seen on 4.1. #11494 reports the same bug for plain Parquet on
3.4 to 4.1. | [#11494](https://github.com/apache/gluten/issues/11494) |
+| Native readers do not materialize non-null `EXISTS_DEFAULT` values,
including after `CONVERT TO DELTA`. By default, scans reading these columns
fall back to Spark even after all files have been rewritten to store the
column, because the metadata persists. Null existence defaults and pruned-away
columns do not trigger this fallback. Setting
`spark.gluten.sql.scan.fallbackOnExistenceDefaults.enabled=false` disables only
this check and can produce incorrect results for missing fields; see [...]
| Native scans do not support Delta column mapping id mode. These scans fall
back to Spark before physical schema translation, preserving missing-field and
redirected-field ID semantics instead of matching by physical name. | Fallback
| 3.4 to 4.2, from code |
[#12241](https://github.com/apache/gluten/issues/12241) |
| On a TIMESTAMP-partitioned table with six partition values from .1 to
.123456 seconds, `count(DISTINCT ts)` returns 3, as if the values were
truncated to milliseconds. Equality filters on the column still return the
right rows. | ResultMismatch | Seen on 4.1 | |
| Reading a data column widened from DATE to TIMESTAMP_NTZ fails on files
written before the change with `Converted type DATE is not allowed for
requested type TIMESTAMP UTC`. A partition column widened the same way reads
correctly. | Exception | Seen on 4.1 | |
diff --git
a/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
b/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
index 8797e5b787..8a010762e1 100644
---
a/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
+++
b/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
@@ -177,6 +177,9 @@ class GlutenConfig(conf: SQLConf) extends
GlutenCoreConfig(conf) {
def scanFileSchemeValidationEnabled: Boolean =
getConf(VELOX_SCAN_FILE_SCHEME_VALIDATION_ENABLED)
+ def scanFallbackOnExistenceDefaultsEnabled: Boolean =
+ getConf(SCAN_FALLBACK_ON_EXISTENCE_DEFAULTS_ENABLED)
+
// Whether to use GlutenShuffleManager (experimental).
def isUseGlutenShuffleManager: Boolean =
conf
@@ -1681,6 +1684,17 @@ object GlutenConfig extends ConfigRegistry {
.booleanConf
.createWithDefault(true)
+ val SCAN_FALLBACK_ON_EXISTENCE_DEFAULTS_ENABLED =
+ buildConf("spark.gluten.sql.scan.fallbackOnExistenceDefaults.enabled")
+ .doc(
+ "When true, V1/V2 file scans reading non-null EXISTS_DEFAULT columns
fall back to Spark, " +
+ "including Parquet/ORC and Delta. Metadata persists after file
rewrites, so fully " +
+ "populated files also fall back. Set false only if all read files
contain the columns " +
+ "or incorrect results for missing fields are acceptable. Native
readers do not " +
+ "materialize these defaults; other fallback checks still apply.")
+ .booleanConf
+ .createWithDefault(true)
+
val COLUMNAR_NATIVE_CAST_AGGREGATE_ENABLED =
buildConf("spark.gluten.sql.columnar.cast.avg").booleanConf
.createWithDefault(true)
diff --git
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala
index e552f1953f..34cfef26e9 100644
---
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala
+++
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala
@@ -31,6 +31,7 @@ import org.apache.spark.sql.catalyst.FileSourceOptions
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.execution.adaptive.InputStats
import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.StructType
import com.google.protobuf.StringValue
import io.substrait.proto.NamedStruct
@@ -123,6 +124,24 @@ trait BasicScanExecTransformer extends
LeafTransformSupport with BaseDataSource
def getInputStats: Option[InputStats] = Option.empty
+ protected def validateExistenceDefaults(readSchema: StructType):
ValidationResult = {
+ if (!GlutenConfig.get.scanFallbackOnExistenceDefaultsEnabled) {
+ return ValidationResult.succeeded
+ }
+
+ val columns = readSchema.fields
+ .zip(ResolveDefaultColumns.getExistenceDefaultValues(readSchema))
+ .collect { case (field, value) if value != null => field.name }
+ if (columns.nonEmpty) {
+ // Missing fields need their original default, while explicitly stored
nulls must stay null.
+ ValidationResult.failed(
+ "Native file scans do not support non-null existence defaults
(EXISTS_DEFAULT) " +
+ s"on columns: ${columns.mkString(", ")}.")
+ } else {
+ ValidationResult.succeeded
+ }
+ }
+
protected def neededInputFileRelatedMetadataKeys: Seq[String] = {
val inputFileRelatedMetadataKeys = Seq(
InputFileName().prettyName,
diff --git
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala
index 645b3fc6a0..0f212f6621 100644
---
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala
+++
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala
@@ -172,6 +172,15 @@ abstract class BatchScanExecTransformerBase(
return ValidationResult.failed(s"Unsupported scan $scan")
}
+ scan match {
+ case fileScan: FileScan =>
+ val defaultsValidation =
validateExistenceDefaults(fileScan.readDataSchema)
+ if (!defaultsValidation.ok()) {
+ return defaultsValidation
+ }
+ case _ =>
+ }
+
if (pushedAggregate.nonEmpty) {
return ValidationResult.failed(s"Unsupported aggregation push down for
$scan.")
}
diff --git
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala
index 2fb4e5c303..d128162d58 100644
---
a/gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala
+++
b/gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala
@@ -183,6 +183,11 @@ abstract class FileSourceScanExecTransformerBase(
}
override protected def doValidateInternal(): ValidationResult = {
+ val defaultsValidation = validateExistenceDefaults(requiredSchema)
+ if (!defaultsValidation.ok()) {
+ return defaultsValidation
+ }
+
if (
!metadataColumns.isEmpty &&
!BackendsApiManager.getSettings.supportNativeMetadataColumns()
) {
diff --git
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
index 0ac3b4ac05..231c950d65 100644
---
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
+++
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
@@ -609,14 +609,6 @@ class BoltTestSettings extends BackendTestSettings {
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Bolt supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 23872dfafe..c43c27da9d 100644
---
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -625,14 +625,6 @@ class VeloxTestSettings extends BackendTestSettings {
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
index 7a5c6a53bb..0bee439023 100644
---
a/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
+++
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
@@ -301,322 +301,6 @@ class GlutenInsertSuite
checkAndGetWriteFiles(df)
}
}
-
- testGluten("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them") {
- import testImplicits._
- case class Config(sqlConf: Option[(String, String)], useDataFrames:
Boolean = false)
- def runTest(dataSource: String, config: Config): Unit = {
- def insertIntoT(): Unit = {
- sql("insert into t(a, i) values('xyz', 42)")
- }
- def withTableT(f: => Unit): Unit = {
- sql(s"create table t(a string, i int) using $dataSource")
- withTable("t")(f)
- }
- // Positive tests:
- // Adding a column with a valid default value into a table containing
existing data
- // returns null while it works successfully for newly added rows in
Velox.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef"))
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- // Now alter the column to change the default value.
- // This still returns the previous value, not the new value.
- sql("alter table t alter column s set default concat('ghi', 'jkl')")
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- }
- // Adding a column with a default value and then inserting explicit NULL
values works.
- // Querying data back from the table differentiates between the explicit
NULL values and
- // default values.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- if (config.useDataFrames) {
- Seq((null, null, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t values(null, null, null)")
- }
-
- checkAnswer(spark.table("t"), Seq(Row("xyz", 42, "abcdef"), Row(null,
null, null)))
- checkAnswer(sql("select i, s from t"), Seq(Row(42, "abcdef"),
Row(null, null)))
- }
- // Adding two columns where only the first has a valid default value
works successfully.
- // Querying data from the altered table returns the default value as
well as NULL for the
- // second column.+
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- sql("alter table t add column (x string)")
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef", null))
- checkAnswer(sql("select i, s, x from t"), Row(42, "abcdef", null))
- }
- // Test other supported data types.
- withTableT {
- sql(
- "alter table t add columns (" +
- "s boolean default true, " +
- "t byte default cast(null as byte), " +
- "u short default cast(42 as short), " +
- "v float default 0, " +
- "w double default 0, " +
- "x date default cast('2021-01-02' as date), " +
- "y timestamp default cast('2021-01-02 01:01:01' as timestamp), " +
- "z timestamp_ntz default cast('2021-01-02 01:01:01' as
timestamp_ntz), " +
- "a1 timestamp_ltz default cast('2021-01-02 01:01:01' as
timestamp_ltz), " +
- "a2 decimal(5, 2) default 123.45," +
- "a3 bigint default 43," +
- "a4 smallint default cast(5 as smallint)," +
- "a5 tinyint default cast(6 as tinyint))")
- insertIntoT()
- // Manually inspect the result row values rather than using the
'checkAnswer' helper method
- // in order to ensure the values' correctness while avoiding minor
type incompatibilities.
- val result: Array[Row] =
- sql("select s, t, u, v, w, x, y, z, a1, a2, a3, a4, a5 from
t").collect()
- for (row <- result) {
- assert(row.length == 13)
- assert(row(0) == true)
- assert(row(1) == null)
- assert(row(2) == 42)
- assert(row(3) == 0.0f)
- assert(row(4) == 0.0d)
- assert(row(5).toString == "2021-01-02")
- assert(row(6).toString == "2021-01-02 01:01:01.0")
- assert(row(7).toString.startsWith("2021-01-02"))
- assert(row(8).toString == "2021-01-02 01:01:01.0")
- assert(row(9).toString == "123.45")
- assert(row(10) == 43L)
- assert(row(11) == 5)
- assert(row(12) == 6)
- }
- }
- }
-
- // This represents one test configuration over a data source.
- case class TestCase(dataSource: String, configs: Seq[Config])
- // Run the test several times using each configuration.
- Seq(
- TestCase(
- dataSource = "csv",
- Seq(Config(None), Config(Some(SQLConf.CSV_PARSER_COLUMN_PRUNING.key ->
"false")))),
- TestCase(
- dataSource = "json",
- Seq(Config(None),
Config(Some(SQLConf.JSON_GENERATOR_IGNORE_NULL_FIELDS.key -> "false")))),
- TestCase(
- dataSource = "orc",
- Seq(Config(None),
Config(Some(SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "false")))),
- TestCase(
- dataSource = "parquet",
- Seq(Config(None),
Config(Some(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false"))))
- ).foreach {
- testCase: TestCase =>
- testCase.configs.foreach {
- config: Config =>
- // Run the test twice, once using SQL for the INSERT operations
- // and again using DataFrames.
- for (useDataFrames <- Seq(false, true)) {
- config.sqlConf
- .map {
- kv: (String, String) =>
- withSQLConf(kv) {
- // Run the test with the pair of custom SQLConf values.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- .getOrElse {
- // Run the test with default settings.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- }
- }
- }
-
- testGluten("SPARK-39557 INSERT INTO statements with tables with array
defaults") {
- import testImplicits._
- // Positive tests: array types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s array<int> default array(1, 2)")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true, Seq(1,
2))))
- }
- }
- // Negative tests: provided array element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column s has a DEFAULT value with type"
- Seq(Config("parquet"), Config("parquet", true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s array<int> default array('abc',
'def')")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- testGluten("SPARK-39557 INSERT INTO statements with tables with struct
defaults") {
-
- import testImplicits._
- // Positive tests: struct types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql(
- "alter table t add column s struct<x boolean, y string> default
struct(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Row(true, "abc"))))
- }
- }
-
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column s has a DEFAULT value with type"
- Seq(Config("parquet"), Config("parquet", true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s struct<x boolean, y string>
default struct(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with map
defaults") {
-
- import testImplicits._
- // Positive tests: map types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s map<boolean, string> default
map(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) select true")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Map(true -> "abc"))))
- }
- withTable("t") {
- sql(s"""
- create table t(
- i int,
- s struct<
- x array<
- struct<a int, b int>>,
- y array<
- map<boolean, string>>>
- default struct(
- array(
- struct(1, 2)),
- array(
- map(false, 'def', true, 'jkl'))))
- using ${config.dataSource}""")
- sql("insert into t select 1, default")
- sql("alter table t alter column s drop default")
- if (config.useDataFrames) {
- Seq((2, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t select 2, default")
- }
- sql("""
- alter table t alter column s
- set default struct(
- array(
- struct(3, 4)),
- array(
- map(false, 'mno', true, 'pqr')))""")
- sql("insert into t select 3, default")
- sql("""
- alter table t
- add column t array<
- map<boolean, string>>
- default array(
- map(true, 'xyz'))""")
- sql("insert into t(i, s) select 4, default")
- checkAnswer(
- spark.table("t"),
- Seq(
- Row(1, Row(Seq(Row(1, 2)), Seq(Map(false -> "def", true ->
"jkl"))), null),
- Row(2, null, null),
- Row(3, Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true ->
"pqr"))), null),
- Row(
- 4,
- Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true -> "pqr"))),
- Seq(Map(true -> "xyz")))
- )
- )
- }
- }
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column s has a DEFAULT value with type"
- Seq(Config("parquet"), Config("parquet", true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s map<boolean, string> default
map(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
}
class GlutenRenameFromSparkStagingToFinalDirAlwaysTurnsFalseFilesystem extends
RawLocalFileSystem {
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
index e9bad0745b..db6240bd18 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/bolt/BoltTestSettings.scala
@@ -669,14 +669,6 @@ class BoltTestSettings extends BackendTestSettings {
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Bolt supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index ca81410bb5..ea5c7e517e 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -1044,14 +1044,6 @@ class ClickHouseTestSettings extends BackendTestSettings
{
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
.excludeCH("Gluten - insert partition table")
.excludeCH("Gluten - remove v1writes sort and project")
.excludeCH("Gluten - remove v1writes sort")
@@ -1061,7 +1053,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.excludeCH(
"Gluten - Do not fallback write files if output columns contain Spark
internal metadata")
.excludeCH("Gluten - Add metadata white list to allow native write files")
- .excludeCH("Gluten - INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs,
then SELECT them")
enableSuite[GlutenIntervalExpressionsSuite]
enableSuite[GlutenIntervalFunctionsSuite]
enableSuite[GlutenJoinSuite]
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 08f9467e47..741343a1d1 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -595,14 +595,6 @@ class VeloxTestSettings extends BackendTestSettings {
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
index 75e2c39f79..ef4f92c2a3 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
@@ -29,7 +29,6 @@ import org.apache.spark.sql.execution.{CommandResultExec,
GlutenImplicits, Query
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.util.QueryExecutionListener
import org.apache.hadoop.fs.{Path, RawLocalFileSystem}
@@ -273,322 +272,6 @@ class GlutenInsertSuite
checkWriteFilesAndGetChild(df)
}
}
-
- testGluten("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them") {
- import testImplicits._
- case class Config(sqlConf: Option[(String, String)], useDataFrames:
Boolean = false)
- def runTest(dataSource: String, config: Config): Unit = {
- def insertIntoT(): Unit = {
- sql("insert into t(a, i) values('xyz', 42)")
- }
- def withTableT(f: => Unit): Unit = {
- sql(s"create table t(a string, i int) using $dataSource")
- withTable("t")(f)
- }
- // Positive tests:
- // Adding a column with a valid default value into a table containing
existing data
- // returns null while it works successfully for newly added rows in
Velox.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef"))
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- // Now alter the column to change the default value.
- // This still returns the previous value, not the new value.
- sql("alter table t alter column s set default concat('ghi', 'jkl')")
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- }
- // Adding a column with a default value and then inserting explicit NULL
values works.
- // Querying data back from the table differentiates between the explicit
NULL values and
- // default values.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- if (config.useDataFrames) {
- Seq((null, null, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t values(null, null, null)")
- }
-
- checkAnswer(spark.table("t"), Seq(Row("xyz", 42, "abcdef"), Row(null,
null, null)))
- checkAnswer(sql("select i, s from t"), Seq(Row(42, "abcdef"),
Row(null, null)))
- }
- // Adding two columns where only the first has a valid default value
works successfully.
- // Querying data from the altered table returns the default value as
well as NULL for the
- // second column.+
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- sql("alter table t add column (x string)")
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef", null))
- checkAnswer(sql("select i, s, x from t"), Row(42, "abcdef", null))
- }
- // Test other supported data types.
- withTableT {
- sql(
- "alter table t add columns (" +
- "s boolean default true, " +
- "t byte default cast(null as byte), " +
- "u short default cast(42 as short), " +
- "v float default 0, " +
- "w double default 0, " +
- "x date default cast('2021-01-02' as date), " +
- "y timestamp default cast('2021-01-02 01:01:01' as timestamp), " +
- "z timestamp_ntz default cast('2021-01-02 01:01:01' as
timestamp_ntz), " +
- "a1 timestamp_ltz default cast('2021-01-02 01:01:01' as
timestamp_ltz), " +
- "a2 decimal(5, 2) default 123.45," +
- "a3 bigint default 43," +
- "a4 smallint default cast(5 as smallint)," +
- "a5 tinyint default cast(6 as tinyint))")
- insertIntoT()
- // Manually inspect the result row values rather than using the
'checkAnswer' helper method
- // in order to ensure the values' correctness while avoiding minor
type incompatibilities.
- val result: Array[Row] =
- sql("select s, t, u, v, w, x, y, z, a1, a2, a3, a4, a5 from
t").collect()
- for (row <- result) {
- assert(row.length == 13)
- assert(row(0) == true)
- assert(row(1) == null)
- assert(row(2) == 42)
- assert(row(3) == 0.0f)
- assert(row(4) == 0.0d)
- assert(row(5).toString == "2021-01-02")
- assert(row(6).toString == "2021-01-02 01:01:01.0")
- assert(row(7).toString.startsWith("2021-01-02"))
- assert(row(8).toString == "2021-01-02 01:01:01.0")
- assert(row(9).toString == "123.45")
- assert(row(10) == 43L)
- assert(row(11) == 5)
- assert(row(12) == 6)
- }
- }
- }
-
- // This represents one test configuration over a data source.
- case class TestCase(dataSource: String, configs: Seq[Config])
- // Run the test several times using each configuration.
- Seq(
- TestCase(
- dataSource = "csv",
- Seq(Config(None), Config(Some(SQLConf.CSV_PARSER_COLUMN_PRUNING.key ->
"false")))),
- TestCase(
- dataSource = "json",
- Seq(Config(None),
Config(Some(SQLConf.JSON_GENERATOR_IGNORE_NULL_FIELDS.key -> "false")))),
- TestCase(
- dataSource = "orc",
- Seq(Config(None),
Config(Some(SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "false")))),
- TestCase(
- dataSource = "parquet",
- Seq(Config(None),
Config(Some(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false"))))
- ).foreach {
- testCase: TestCase =>
- testCase.configs.foreach {
- config: Config =>
- // Run the test twice, once using SQL for the INSERT operations
- // and again using DataFrames.
- for (useDataFrames <- Seq(false, true)) {
- config.sqlConf
- .map {
- kv: (String, String) =>
- withSQLConf(kv) {
- // Run the test with the pair of custom SQLConf values.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- .getOrElse {
- // Run the test with default settings.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- }
- }
- }
-
- testGluten("SPARK-39557 INSERT INTO statements with tables with array
defaults") {
- import testImplicits._
- // Positive tests: array types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s array<int> default array(1, 2)")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true, Seq(1,
2))))
- }
- }
- // Negative tests: provided array element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s array<int> default array('abc',
'def')")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- testGluten("SPARK-39557 INSERT INTO statements with tables with struct
defaults") {
-
- import testImplicits._
- // Positive tests: struct types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql(
- "alter table t add column s struct<x boolean, y string> default
struct(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Row(true, "abc"))))
- }
- }
-
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s struct<x boolean, y string>
default struct(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with map
defaults") {
-
- import testImplicits._
- // Positive tests: map types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s map<boolean, string> default
map(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) select true")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Map(true -> "abc"))))
- }
- withTable("t") {
- sql(s"""
- create table t(
- i int,
- s struct<
- x array<
- struct<a int, b int>>,
- y array<
- map<boolean, string>>>
- default struct(
- array(
- struct(1, 2)),
- array(
- map(false, 'def', true, 'jkl'))))
- using ${config.dataSource}""")
- sql("insert into t select 1, default")
- sql("alter table t alter column s drop default")
- if (config.useDataFrames) {
- Seq((2, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t select 2, default")
- }
- sql("""
- alter table t alter column s
- set default struct(
- array(
- struct(3, 4)),
- array(
- map(false, 'mno', true, 'pqr')))""")
- sql("insert into t select 3, default")
- sql("""
- alter table t
- add column t array<
- map<boolean, string>>
- default array(
- map(true, 'xyz'))""")
- sql("insert into t(i, s) select 4, default")
- checkAnswer(
- spark.table("t"),
- Seq(
- Row(1, Row(Seq(Row(1, 2)), Seq(Map(false -> "def", true ->
"jkl"))), null),
- Row(2, null, null),
- Row(3, Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true ->
"pqr"))), null),
- Row(
- 4,
- Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true -> "pqr"))),
- Seq(Map(true -> "xyz")))
- )
- )
- }
- }
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s map<boolean, string> default
map(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
}
class GlutenRenameFromSparkStagingToFinalDirAlwaysTurnsFalseFilesystem extends
RawLocalFileSystem {
diff --git
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index b9afc2225c..7c29cd427b 100644
---
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -1004,14 +1004,6 @@ class ClickHouseTestSettings extends BackendTestSettings
{
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
.excludeCH("Gluten - insert partition table")
.excludeCH("Gluten - remove v1writes sort and project")
.excludeCH("Gluten - remove v1writes sort")
@@ -1021,7 +1013,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.excludeCH(
"Gluten - Do not fallback write files if output columns contain Spark
internal metadata")
.excludeCH("Gluten - Add metadata white list to allow native write files")
- .excludeCH("Gluten - INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs,
then SELECT them")
enableSuite[GlutenIntervalExpressionsSuite]
enableSuite[GlutenIntervalFunctionsSuite]
enableSuite[GlutenJoinSuite]
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 7114414262..604bcdf2ce 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
@@ -853,14 +853,6 @@ class VeloxTestSettings extends BackendTestSettings {
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
index c71e2cdd19..ef4f92c2a3 100644
---
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
+++
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
@@ -29,7 +29,6 @@ import org.apache.spark.sql.execution.{CommandResultExec,
GlutenImplicits, Query
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.util.QueryExecutionListener
import org.apache.hadoop.fs.{Path, RawLocalFileSystem}
@@ -273,324 +272,6 @@ class GlutenInsertSuite
checkWriteFilesAndGetChild(df)
}
}
-
- testGluten("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them") {
- import testImplicits._
- case class Config(sqlConf: Option[(String, String)], useDataFrames:
Boolean = false)
- def runTest(dataSource: String, config: Config): Unit = {
- def insertIntoT(): Unit = {
- sql("insert into t(a, i) values('xyz', 42)")
- }
- def withTableT(f: => Unit): Unit = {
- sql(s"create table t(a string, i int) using $dataSource")
- withTable("t")(f)
- }
- // Positive tests:
- // Adding a column with a valid default value into a table containing
existing data
- // returns null while it works successfully for newly added rows in
Velox.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef"))
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- // Now alter the column to change the default value.
- // This still returns the previous value, not the new value.
- sql("alter table t alter column s set default concat('ghi', 'jkl')")
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- }
- // Adding a column with a default value and then inserting explicit NULL
values works.
- // Querying data back from the table differentiates between the explicit
NULL values and
- // default values.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- if (config.useDataFrames) {
- Seq((null, null, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t values(null, null, null)")
- }
-
- checkAnswer(spark.table("t"), Seq(Row("xyz", 42, "abcdef"), Row(null,
null, null)))
- checkAnswer(sql("select i, s from t"), Seq(Row(42, "abcdef"),
Row(null, null)))
- }
- // Adding two columns where only the first has a valid default value
works successfully.
- // Querying data from the altered table returns the default value as
well as NULL for the
- // second column.+
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- sql("alter table t add column (x string)")
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef", null))
- checkAnswer(sql("select i, s, x from t"), Row(42, "abcdef", null))
- }
- // Test other supported data types.
- withTableT {
- sql(
- "alter table t add columns (" +
- "s boolean default true, " +
- "t byte default cast(null as byte), " +
- "u short default cast(42 as short), " +
- "v float default 0, " +
- "w double default 0, " +
- "x date default cast('2021-01-02' as date), " +
- "y timestamp default cast('2021-01-02 01:01:01' as timestamp), " +
- "z timestamp_ntz default cast('2021-01-02 01:01:01' as
timestamp_ntz), " +
- "a1 timestamp_ltz default cast('2021-01-02 01:01:01' as
timestamp_ltz), " +
- "a2 decimal(5, 2) default 123.45," +
- "a3 bigint default 43," +
- "a4 smallint default cast(5 as smallint)," +
- "a5 tinyint default cast(6 as tinyint))")
- insertIntoT()
- // Manually inspect the result row values rather than using the
'checkAnswer' helper method
- // in order to ensure the values' correctness while avoiding minor
type incompatibilities.
- val result: Array[Row] =
- sql("select s, t, u, v, w, x, y, z, a1, a2, a3, a4, a5 from
t").collect()
- for (row <- result) {
- assert(row.length == 13)
- assert(row(0) == true)
- assert(row(1) == null)
- assert(row(2) == 42)
- assert(row(3) == 0.0f)
- assert(row(4) == 0.0d)
- assert(row(5).toString == "2021-01-02")
- assert(row(6).toString == "2021-01-02 01:01:01.0")
- assert(row(7).toString.startsWith("2021-01-02"))
- assert(row(8).toString == "2021-01-02 01:01:01.0")
- assert(row(9).toString == "123.45")
- assert(row(10) == 43L)
- assert(row(11) == 5)
- assert(row(12) == 6)
- }
- }
- }
-
- // This represents one test configuration over a data source.
- case class TestCase(dataSource: String, configs: Seq[Config])
- // Run the test several times using each configuration.
- Seq(
- TestCase(
- dataSource = "csv",
- Seq(Config(None), Config(Some(SQLConf.CSV_PARSER_COLUMN_PRUNING.key ->
"false")))),
- TestCase(
- dataSource = "json",
- Seq(Config(None),
Config(Some(SQLConf.JSON_GENERATOR_IGNORE_NULL_FIELDS.key -> "false")))),
- TestCase(
- dataSource = "orc",
- Seq(Config(None),
Config(Some(SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "false")))),
- TestCase(
- dataSource = "parquet",
- Seq(Config(None),
Config(Some(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false"))))
- ).foreach {
- testCase: TestCase =>
- testCase.configs.foreach {
- config: Config =>
- // Run the test twice, once using SQL for the INSERT operations
- // and again using DataFrames.
- for (useDataFrames <- Seq(false, true)) {
- config.sqlConf
- .map {
- kv: (String, String) =>
- withSQLConf(kv) {
- // Run the test with the pair of custom SQLConf values.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- .getOrElse {
- // Run the test with default settings.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with array
defaults") {
- import testImplicits._
- // Positive tests: array types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s array<int> default array(1, 2)")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true, Seq(1,
2))))
- }
- }
- // Negative tests: provided array element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s array<int> default array('abc',
'def')")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with struct
defaults") {
-
- import testImplicits._
- // Positive tests: struct types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql(
- "alter table t add column s struct<x boolean, y string> default
struct(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Row(true, "abc"))))
- }
- }
-
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s struct<x boolean, y string>
default struct(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with map
defaults") {
-
- import testImplicits._
- // Positive tests: map types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s map<boolean, string> default
map(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) select true")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Map(true -> "abc"))))
- }
- withTable("t") {
- sql(s"""
- create table t(
- i int,
- s struct<
- x array<
- struct<a int, b int>>,
- y array<
- map<boolean, string>>>
- default struct(
- array(
- struct(1, 2)),
- array(
- map(false, 'def', true, 'jkl'))))
- using ${config.dataSource}""")
- sql("insert into t select 1, default")
- sql("alter table t alter column s drop default")
- if (config.useDataFrames) {
- Seq((2, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t select 2, default")
- }
- sql("""
- alter table t alter column s
- set default struct(
- array(
- struct(3, 4)),
- array(
- map(false, 'mno', true, 'pqr')))""")
- sql("insert into t select 3, default")
- sql("""
- alter table t
- add column t array<
- map<boolean, string>>
- default array(
- map(true, 'xyz'))""")
- sql("insert into t(i, s) select 4, default")
- checkAnswer(
- spark.table("t"),
- Seq(
- Row(1, Row(Seq(Row(1, 2)), Seq(Map(false -> "def", true ->
"jkl"))), null),
- Row(2, null, null),
- Row(3, Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true ->
"pqr"))), null),
- Row(
- 4,
- Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true -> "pqr"))),
- Seq(Map(true -> "xyz")))
- )
- )
- }
- }
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s map<boolean, string> default
map(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
}
class GlutenRenameFromSparkStagingToFinalDirAlwaysTurnsFalseFilesystem extends
RawLocalFileSystem {
diff --git
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index b9afc2225c..7c29cd427b 100644
---
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -1004,14 +1004,6 @@ class ClickHouseTestSettings extends BackendTestSettings
{
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
.excludeCH("Gluten - insert partition table")
.excludeCH("Gluten - remove v1writes sort and project")
.excludeCH("Gluten - remove v1writes sort")
@@ -1021,7 +1013,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.excludeCH(
"Gluten - Do not fallback write files if output columns contain Spark
internal metadata")
.excludeCH("Gluten - Add metadata white list to allow native write files")
- .excludeCH("Gluten - INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs,
then SELECT them")
enableSuite[GlutenIntervalExpressionsSuite]
enableSuite[GlutenIntervalFunctionsSuite]
enableSuite[GlutenJoinSuite]
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 e378f64243..ea6a17c748 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
@@ -836,14 +836,6 @@ class VeloxTestSettings extends BackendTestSettings {
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
enableSuite[GlutenPartitionedWriteSuite]
enableSuite[GlutenPathOptionSuite]
enableSuite[GlutenPrunedScanSuite]
diff --git
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
index c71e2cdd19..ef4f92c2a3 100644
---
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
+++
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala
@@ -29,7 +29,6 @@ import org.apache.spark.sql.execution.{CommandResultExec,
GlutenImplicits, Query
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.util.QueryExecutionListener
import org.apache.hadoop.fs.{Path, RawLocalFileSystem}
@@ -273,324 +272,6 @@ class GlutenInsertSuite
checkWriteFilesAndGetChild(df)
}
}
-
- testGluten("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them") {
- import testImplicits._
- case class Config(sqlConf: Option[(String, String)], useDataFrames:
Boolean = false)
- def runTest(dataSource: String, config: Config): Unit = {
- def insertIntoT(): Unit = {
- sql("insert into t(a, i) values('xyz', 42)")
- }
- def withTableT(f: => Unit): Unit = {
- sql(s"create table t(a string, i int) using $dataSource")
- withTable("t")(f)
- }
- // Positive tests:
- // Adding a column with a valid default value into a table containing
existing data
- // returns null while it works successfully for newly added rows in
Velox.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef"))
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- // Now alter the column to change the default value.
- // This still returns the previous value, not the new value.
- sql("alter table t alter column s set default concat('ghi', 'jkl')")
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- }
- // Adding a column with a default value and then inserting explicit NULL
values works.
- // Querying data back from the table differentiates between the explicit
NULL values and
- // default values.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- if (config.useDataFrames) {
- Seq((null, null, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t values(null, null, null)")
- }
-
- checkAnswer(spark.table("t"), Seq(Row("xyz", 42, "abcdef"), Row(null,
null, null)))
- checkAnswer(sql("select i, s from t"), Seq(Row(42, "abcdef"),
Row(null, null)))
- }
- // Adding two columns where only the first has a valid default value
works successfully.
- // Querying data from the altered table returns the default value as
well as NULL for the
- // second column.+
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- sql("alter table t add column (x string)")
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef", null))
- checkAnswer(sql("select i, s, x from t"), Row(42, "abcdef", null))
- }
- // Test other supported data types.
- withTableT {
- sql(
- "alter table t add columns (" +
- "s boolean default true, " +
- "t byte default cast(null as byte), " +
- "u short default cast(42 as short), " +
- "v float default 0, " +
- "w double default 0, " +
- "x date default cast('2021-01-02' as date), " +
- "y timestamp default cast('2021-01-02 01:01:01' as timestamp), " +
- "z timestamp_ntz default cast('2021-01-02 01:01:01' as
timestamp_ntz), " +
- "a1 timestamp_ltz default cast('2021-01-02 01:01:01' as
timestamp_ltz), " +
- "a2 decimal(5, 2) default 123.45," +
- "a3 bigint default 43," +
- "a4 smallint default cast(5 as smallint)," +
- "a5 tinyint default cast(6 as tinyint))")
- insertIntoT()
- // Manually inspect the result row values rather than using the
'checkAnswer' helper method
- // in order to ensure the values' correctness while avoiding minor
type incompatibilities.
- val result: Array[Row] =
- sql("select s, t, u, v, w, x, y, z, a1, a2, a3, a4, a5 from
t").collect()
- for (row <- result) {
- assert(row.length == 13)
- assert(row(0) == true)
- assert(row(1) == null)
- assert(row(2) == 42)
- assert(row(3) == 0.0f)
- assert(row(4) == 0.0d)
- assert(row(5).toString == "2021-01-02")
- assert(row(6).toString == "2021-01-02 01:01:01.0")
- assert(row(7).toString.startsWith("2021-01-02"))
- assert(row(8).toString == "2021-01-02 01:01:01.0")
- assert(row(9).toString == "123.45")
- assert(row(10) == 43L)
- assert(row(11) == 5)
- assert(row(12) == 6)
- }
- }
- }
-
- // This represents one test configuration over a data source.
- case class TestCase(dataSource: String, configs: Seq[Config])
- // Run the test several times using each configuration.
- Seq(
- TestCase(
- dataSource = "csv",
- Seq(Config(None), Config(Some(SQLConf.CSV_PARSER_COLUMN_PRUNING.key ->
"false")))),
- TestCase(
- dataSource = "json",
- Seq(Config(None),
Config(Some(SQLConf.JSON_GENERATOR_IGNORE_NULL_FIELDS.key -> "false")))),
- TestCase(
- dataSource = "orc",
- Seq(Config(None),
Config(Some(SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "false")))),
- TestCase(
- dataSource = "parquet",
- Seq(Config(None),
Config(Some(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false"))))
- ).foreach {
- testCase: TestCase =>
- testCase.configs.foreach {
- config: Config =>
- // Run the test twice, once using SQL for the INSERT operations
- // and again using DataFrames.
- for (useDataFrames <- Seq(false, true)) {
- config.sqlConf
- .map {
- kv: (String, String) =>
- withSQLConf(kv) {
- // Run the test with the pair of custom SQLConf values.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- .getOrElse {
- // Run the test with default settings.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with array
defaults") {
- import testImplicits._
- // Positive tests: array types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s array<int> default array(1, 2)")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true, Seq(1,
2))))
- }
- }
- // Negative tests: provided array element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s array<int> default array('abc',
'def')")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with struct
defaults") {
-
- import testImplicits._
- // Positive tests: struct types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql(
- "alter table t add column s struct<x boolean, y string> default
struct(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Row(true, "abc"))))
- }
- }
-
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s struct<x boolean, y string>
default struct(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with map
defaults") {
-
- import testImplicits._
- // Positive tests: map types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s map<boolean, string> default
map(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) select true")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Map(true -> "abc"))))
- }
- withTable("t") {
- sql(s"""
- create table t(
- i int,
- s struct<
- x array<
- struct<a int, b int>>,
- y array<
- map<boolean, string>>>
- default struct(
- array(
- struct(1, 2)),
- array(
- map(false, 'def', true, 'jkl'))))
- using ${config.dataSource}""")
- sql("insert into t select 1, default")
- sql("alter table t alter column s drop default")
- if (config.useDataFrames) {
- Seq((2, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t select 2, default")
- }
- sql("""
- alter table t alter column s
- set default struct(
- array(
- struct(3, 4)),
- array(
- map(false, 'mno', true, 'pqr')))""")
- sql("insert into t select 3, default")
- sql("""
- alter table t
- add column t array<
- map<boolean, string>>
- default array(
- map(true, 'xyz'))""")
- sql("insert into t(i, s) select 4, default")
- checkAnswer(
- spark.table("t"),
- Seq(
- Row(1, Row(Seq(Row(1, 2)), Seq(Map(false -> "def", true ->
"jkl"))), null),
- Row(2, null, null),
- Row(3, Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true ->
"pqr"))), null),
- Row(
- 4,
- Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true -> "pqr"))),
- Seq(Map(true -> "xyz")))
- )
- )
- }
- }
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s map<boolean, string> default
map(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
}
class GlutenRenameFromSparkStagingToFinalDirAlwaysTurnsFalseFilesystem extends
RawLocalFileSystem {
diff --git
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index b9afc2225c..7c29cd427b 100644
---
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -1004,14 +1004,6 @@ class ClickHouseTestSettings extends BackendTestSettings
{
// 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")
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
.excludeCH("Gluten - insert partition table")
.excludeCH("Gluten - remove v1writes sort and project")
.excludeCH("Gluten - remove v1writes sort")
@@ -1021,7 +1013,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.excludeCH(
"Gluten - Do not fallback write files if output columns contain Spark
internal metadata")
.excludeCH("Gluten - Add metadata white list to allow native write files")
- .excludeCH("Gluten - INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs,
then SELECT them")
enableSuite[GlutenIntervalExpressionsSuite]
enableSuite[GlutenIntervalFunctionsSuite]
enableSuite[GlutenJoinSuite]
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 6d4f1fe6d5..0a90af2ad3 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
@@ -882,14 +882,6 @@ class VeloxTestSettings extends BackendTestSettings {
// The case expects a SparkException; Gluten surfaces the raw
// FileAlreadyExistsException instead.
.exclude("Stop task set if FileAlreadyExistsException was thrown")
- // Rewrite: Additional support for file scan with default values has been
added in Spark-3.4.
- // It appends the default value in record if it is not present while
scanning.
- // Velox supports default values for new records but it does not backfill
the
- // existing records and provides null for the existing ones.
- .exclude("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them")
- .exclude("SPARK-39557 INSERT INTO statements with tables with array
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with struct
defaults")
- .exclude("SPARK-39557 INSERT INTO statements with tables with map
defaults")
// 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")
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 6068f1fdb6..d3b36feb19 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
@@ -275,325 +275,6 @@ class GlutenInsertSuite
checkWriteFilesAndGetChild(df)
}
}
-
- testGluten("INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT
them") {
- import testImplicits._
- case class Config(sqlConf: Option[(String, String)], useDataFrames:
Boolean = false)
- def runTest(dataSource: String, config: Config): Unit = {
- def insertIntoT(): Unit = {
- sql("insert into t(a, i) values('xyz', 42)")
- }
- def withTableT(f: => Unit): Unit = {
- sql(s"create table t(a string, i int) using $dataSource")
- withTable("t")(f)
- }
- // Positive tests:
- // Adding a column with a valid default value into a table containing
existing data
- // returns null while it works successfully for newly added rows in
Velox.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef"))
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- // Now alter the column to change the default value.
- // This still returns the previous value, not the new value.
- sql("alter table t alter column s set default concat('ghi', 'jkl')")
- checkAnswer(sql("select i, s from t"), Row(42, "abcdef"))
- }
- // Adding a column with a default value and then inserting explicit NULL
values works.
- // Querying data back from the table differentiates between the explicit
NULL values and
- // default values.
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- if (config.useDataFrames) {
- Seq((null, null, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t values(null, null, null)")
- }
-
- checkAnswer(spark.table("t"), Seq(Row("xyz", 42, "abcdef"), Row(null,
null, null)))
- checkAnswer(sql("select i, s from t"), Seq(Row(42, "abcdef"),
Row(null, null)))
- }
- // Adding two columns where only the first has a valid default value
works successfully.
- // Querying data from the altered table returns the default value as
well as NULL for the
- // second column.+
- withTableT {
- sql("alter table t add column (s string default concat('abc', 'def'))")
- insertIntoT()
- sql("alter table t add column (x string)")
- checkAnswer(spark.table("t"), Row("xyz", 42, "abcdef", null))
- checkAnswer(sql("select i, s, x from t"), Row(42, "abcdef", null))
- }
- // Test other supported data types.
- withTableT {
- sql(
- "alter table t add columns (" +
- "s boolean default true, " +
- "t byte default cast(null as byte), " +
- "u short default cast(42 as short), " +
- "v float default 0, " +
- "w double default 0, " +
- "x date default cast('2021-01-02' as date), " +
- "y timestamp default cast('2021-01-02 01:01:01' as timestamp), " +
- "z timestamp_ntz default cast('2021-01-02 01:01:01' as
timestamp_ntz), " +
- "a1 timestamp_ltz default cast('2021-01-02 01:01:01' as
timestamp_ltz), " +
- "a2 decimal(5, 2) default 123.45," +
- "a3 bigint default 43," +
- "a4 smallint default cast(5 as smallint)," +
- "a5 tinyint default cast(6 as tinyint))")
- insertIntoT()
- // Manually inspect the result row values rather than using the
'checkAnswer' helper method
- // in order to ensure the values' correctness while avoiding minor
type incompatibilities.
- val result: Array[Row] =
- sql("select s, t, u, v, w, x, y, z, a1, a2, a3, a4, a5 from
t").collect()
- for (row <- result) {
- assert(row.length == 13)
- assert(row(0) == true)
- assert(row(1) == null)
- assert(row(2) == 42)
- assert(row(3) == 0.0f)
- assert(row(4) == 0.0d)
- assert(row(5).toString == "2021-01-02")
- assert(row(6).toString == "2021-01-02 01:01:01.0")
- assert(row(7).toString.startsWith("2021-01-02"))
- assert(row(8).toString == "2021-01-02 01:01:01.0")
- assert(row(9).toString == "123.45")
- assert(row(10) == 43L)
- assert(row(11) == 5)
- assert(row(12) == 6)
- }
- }
- }
-
- // This represents one test configuration over a data source.
- case class TestCase(dataSource: String, configs: Seq[Config])
- // Run the test several times using each configuration.
- Seq(
- TestCase(
- dataSource = "csv",
- Seq(Config(None), Config(Some(SQLConf.CSV_PARSER_COLUMN_PRUNING.key ->
"false")))),
- TestCase(
- dataSource = "json",
- Seq(Config(None),
Config(Some(SQLConf.JSON_GENERATOR_IGNORE_NULL_FIELDS.key -> "false")))),
- TestCase(
- dataSource = "orc",
- Seq(Config(None),
Config(Some(SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "false")))),
- TestCase(
- dataSource = "parquet",
- Seq(Config(None),
Config(Some(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false"))))
- ).foreach {
- testCase: TestCase =>
- testCase.configs.foreach {
- config: Config =>
- // Run the test twice, once using SQL for the INSERT operations
- // and again using DataFrames.
- for (useDataFrames <- Seq(false, true)) {
- config.sqlConf
- .map {
- kv: (String, String) =>
- withSQLConf(kv) {
- // Run the test with the pair of custom SQLConf values.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- .getOrElse {
- // Run the test with default settings.
- runTest(testCase.dataSource, config.copy(useDataFrames =
useDataFrames))
- }
- }
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with array
defaults") {
- import testImplicits._
- // Positive tests: array types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s array<int> default array(1, 2)")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true, Seq(1,
2))))
- }
- }
- // Negative tests: provided array element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s array<int> default array('abc',
'def')")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- // TODO: fix in Spark-4.0
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with struct
defaults") {
-
- import testImplicits._
- // Positive tests: struct types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql(
- "alter table t add column s struct<x boolean, y string> default
struct(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) values (true)")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Row(true, "abc"))))
- }
- }
-
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s struct<x boolean, y string>
default struct(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
- ignoreGluten("SPARK-39557 INSERT INTO statements with tables with map
defaults") {
-
- import testImplicits._
- // Positive tests: map types are supported as default values.
- case class Config(dataSource: String, useDataFrames: Boolean = false)
- Seq(
- Config("parquet"),
- Config("parquet", useDataFrames = true),
- Config("orc"),
- Config("orc", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- sql("alter table t add column s map<boolean, string> default
map(true, 'abc')")
- checkAnswer(spark.table("t"), Row(false, null))
- sql("insert into t(i) select true")
- checkAnswer(spark.table("t"), Seq(Row(false, null), Row(true,
Map(true -> "abc"))))
- }
- withTable("t") {
- sql(s"""
- create table t(
- i int,
- s struct<
- x array<
- struct<a int, b int>>,
- y array<
- map<boolean, string>>>
- default struct(
- array(
- struct(1, 2)),
- array(
- map(false, 'def', true, 'jkl'))))
- using ${config.dataSource}""")
- sql("insert into t select 1, default")
- sql("alter table t alter column s drop default")
- if (config.useDataFrames) {
- Seq((2, null)).toDF.write.insertInto("t")
- } else {
- sql("insert into t select 2, default")
- }
- sql("""
- alter table t alter column s
- set default struct(
- array(
- struct(3, 4)),
- array(
- map(false, 'mno', true, 'pqr')))""")
- sql("insert into t select 3, default")
- sql("""
- alter table t
- add column t array<
- map<boolean, string>>
- default array(
- map(true, 'xyz'))""")
- sql("insert into t(i, s) select 4, default")
- checkAnswer(
- spark.table("t"),
- Seq(
- Row(1, Row(Seq(Row(1, 2)), Seq(Map(false -> "def", true ->
"jkl"))), null),
- Row(2, null, null),
- Row(3, Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true ->
"pqr"))), null),
- Row(
- 4,
- Row(Seq(Row(3, 4)), Seq(Map(false -> "mno", true -> "pqr"))),
- Seq(Map(true -> "xyz")))
- )
- )
- }
- }
- // Negative tests: provided map element types must match their
corresponding DEFAULT
- // declarations, if applicable.
- val incompatibleDefault =
- "Failed to execute ALTER TABLE ADD COLUMNS command because the
destination " +
- "table column `s` has a DEFAULT value"
- Seq(Config("parquet"), Config("parquet", useDataFrames = true)).foreach {
- config =>
- withTable("t") {
- sql(s"create table t(i boolean) using ${config.dataSource}")
- if (config.useDataFrames) {
- Seq(false).toDF.write.insertInto("t")
- } else {
- sql("insert into t select false")
- }
- assert(intercept[AnalysisException] {
- sql("alter table t add column s map<boolean, string> default
map(42, 56)")
- }.getMessage.contains(incompatibleDefault))
- }
- }
- }
-
// 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.
diff --git
a/gluten-ut/test/src/test/scala/org/apache/gluten/execution/GlutenFailOnFallbackSuite.scala
b/gluten-ut/test/src/test/scala/org/apache/gluten/execution/GlutenFailOnFallbackSuite.scala
index b05b6c952e..02f118b4d2 100644
---
a/gluten-ut/test/src/test/scala/org/apache/gluten/execution/GlutenFailOnFallbackSuite.scala
+++
b/gluten-ut/test/src/test/scala/org/apache/gluten/execution/GlutenFailOnFallbackSuite.scala
@@ -18,9 +18,15 @@ package org.apache.gluten.execution
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.exception.GlutenException
+import org.apache.gluten.extension.columnar.FallbackTags
import org.apache.gluten.utils.BackendTestUtils
import org.apache.spark.SparkConf
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.execution.FileSourceScanExec
+import org.apache.spark.sql.execution.datasources.v2.BatchScanExec
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{IntegerType, LongType, StringType,
StructField, StructType}
import java.util.Locale
@@ -37,6 +43,72 @@ class GlutenFailOnFallbackSuite extends
WholeStageTransformerSuite {
conf
}
+ Seq(true, false).foreach {
+ useV1 =>
+ test(s"existence-default scan fallback and native controls
(useV1=$useV1)") {
+ withSQLConf(
+ SQLConf.ANSI_ENABLED.key -> "false",
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+ SQLConf.USE_V1_SOURCE_LIST.key -> (if (useV1) "parquet" else "")) {
+ withTempPath {
+ dir =>
+ spark.range(1).write.parquet(dir.getCanonicalPath)
+ val readSchema = StructType(Seq(
+ StructField("id", LongType),
+ StructField("value",
IntegerType).withExistenceDefaultValue("7"),
+ StructField("s",
StringType).withExistenceDefaultValue("'abc'"),
+ StructField("null_default", IntegerType)
+ .withExistenceDefaultValue("CAST(NULL AS INT)")
+ ))
+ def read: DataFrame =
spark.read.schema(readSchema).parquet(dir.getCanonicalPath)
+
+ def checkScan(df: DataFrame, defaultColumns: Seq[String]): Unit
= {
+ val plan = getExecutedPlan(df)
+ val nativeScans = plan.filter {
+ case _: FileSourceScanExecTransformer if useV1 => true
+ case _: BatchScanExecTransformer if !useV1 => true
+ case _ => false
+ }
+ val sparkScans = plan.filter {
+ case _: FileSourceScanExec if useV1 => true
+ case _: BatchScanExec if !useV1 => true
+ case _ => false
+ }
+ if (defaultColumns.isEmpty) {
+ assert(nativeScans.size == 1, df.queryExecution.executedPlan)
+ assert(sparkScans.isEmpty, df.queryExecution.executedPlan)
+ } else {
+ assert(nativeScans.isEmpty, df.queryExecution.executedPlan)
+ assert(sparkScans.size == 1, df.queryExecution.executedPlan)
+ val scan = sparkScans.head
+ val reason = FallbackTags.getOption(scan)
+ .orElse(scan.logicalLink.flatMap(FallbackTags.getOption))
+ assert(
+ reason.exists(_.reason().contains(
+ "Native file scans do not support non-null existence
defaults " +
+ s"(EXISTS_DEFAULT) on columns:
${defaultColumns.mkString(", ")}.")),
+ reason.toString
+ )
+ }
+ }
+
+ checkScan(read.select("value", "s", "null_default"),
Seq("value", "s"))
+ checkScan(read.filter("value = 7").select("id"), Seq("value"))
+ checkScan(read.select("id"), Nil)
+ checkScan(read.selectExpr("count(*)"), Nil)
+ checkScan(read.select("id", "null_default"), Nil)
+
+ withSQLConf(
+ GlutenConfig.SCAN_FALLBACK_ON_EXISTENCE_DEFAULTS_ENABLED.key
-> "false") {
+ checkScan(read.select("value", "s", "null_default"), Nil)
+ checkScan(read.filter("value = 7").select("id"), Nil)
+ }
+ checkScan(read.select("value", "s"), Seq("value", "s"))
+ }
+ }
+ }
+ }
+
test("failOnFallback throws only when a fallback is present") {
withTable("t") {
spark.range(10).write.format("parquet").saveAsTable("t")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]