This is an automated email from the ASF dual-hosted git repository.

zhouyuan 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 e73679bdb2 [GLUTEN-13671][VL] Pass Spark's default for 
returnNullStructIfAllFieldsMissing to the native Parquet scan (#13672)
e73679bdb2 is described below

commit e73679bdb2add6ecd3703546f92504ab97254601
Author: Shivadarshan Devadiga <[email protected]>
AuthorDate: Mon Nov 23 15:35:19 2026 +0530

    [GLUTEN-13671][VL] Pass Spark's default for 
returnNullStructIfAllFieldsMissing to the native Parquet scan (#13672)
    
    * [GLUTEN-13671][VL] Pass Spark's default for 
returnNullStructIfAllFieldsMissing to the native Parquet scan
    
    * Add JVM-only test for the forwarded returnNullStructIfAllFieldsMissing 
default
---
 .../apache/gluten/config/VeloxConfigSuite.scala    | 18 +++++++++++++++++
 .../apache/gluten/execution/VeloxScanSuite.scala   | 23 ++++++++++++++++++++++
 .../org/apache/gluten/config/GlutenConfig.scala    | 13 ++++++++++--
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git 
a/backends-velox/src/test/scala/org/apache/gluten/config/VeloxConfigSuite.scala 
b/backends-velox/src/test/scala/org/apache/gluten/config/VeloxConfigSuite.scala
index f91724dbcc..94c2412b75 100644
--- 
a/backends-velox/src/test/scala/org/apache/gluten/config/VeloxConfigSuite.scala
+++ 
b/backends-velox/src/test/scala/org/apache/gluten/config/VeloxConfigSuite.scala
@@ -17,6 +17,7 @@
 package org.apache.gluten.config
 
 import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.util.SparkVersionUtil
 
 import org.scalatest.funsuite.AnyFunSuite
 
@@ -54,4 +55,21 @@ class VeloxConfigSuite extends AnyFunSuite {
   test("build hash table once per executor can still be disabled explicitly") {
     assert(!veloxConfig(buildOncePerExecutor -> 
"false").enableBroadcastBuildOncePerExecutor)
   }
+
+  private val nullStructKey = 
"spark.sql.legacy.parquet.returnNullStructIfAllFieldsMissing"
+
+  test("native session conf passes Spark's default for 
returnNullStructIfAllFieldsMissing") {
+    // Spark 4.1 added the conf with default false (SPARK-53535). Earlier 
versions behave as if it
+    // is true.
+    val native = GlutenConfig.getNativeSessionConf("velox", Map.empty)
+    
assert(native.get(nullStructKey).contains((!SparkVersionUtil.gteSpark41).toString))
+  }
+
+  test("returnNullStructIfAllFieldsMissing set in the session overrides the 
default") {
+    Seq("true", "false").foreach {
+      value =>
+        val native = GlutenConfig.getNativeSessionConf("velox", 
Map(nullStructKey -> value))
+        assert(native.get(nullStructKey).contains(value))
+    }
+  }
 }
diff --git 
a/backends-velox/src/test/scala/org/apache/gluten/execution/VeloxScanSuite.scala
 
b/backends-velox/src/test/scala/org/apache/gluten/execution/VeloxScanSuite.scala
index 117bea4333..aeba9d3d82 100644
--- 
a/backends-velox/src/test/scala/org/apache/gluten/execution/VeloxScanSuite.scala
+++ 
b/backends-velox/src/test/scala/org/apache/gluten/execution/VeloxScanSuite.scala
@@ -27,6 +27,7 @@ import org.apache.spark.sql.catalyst.expressions.GreaterThan
 import org.apache.spark.sql.execution.ScalarSubquery
 import org.apache.spark.sql.internal.SQLConf
 import org.apache.spark.sql.types._
+import org.apache.spark.util.SparkVersionUtil
 
 import org.apache.hadoop.fs.{FileSystem, Path}
 
@@ -382,4 +383,26 @@ class VeloxScanSuite extends 
VeloxWholeStageTransformerSuite {
         }
     }
   }
+
+  test("struct with all requested fields missing follows Spark's default 
nullness") {
+    // Since Spark 4.1 (SPARK-53535), such a struct is null only where the 
struct in the file is
+    // null. Before, it was always null. The conf is left unset to check the 
default.
+    withTempPath {
+      dir =>
+        val path = dir.getCanonicalPath
+        spark
+          .range(3)
+          .selectExpr("if(id = 1, null, named_struct('a', id, 'b', id)) as s")
+          .write
+          .parquet(path)
+        val df = spark.read.schema("s struct<x: int>").parquet(path)
+        val expected = if (SparkVersionUtil.gteSpark41) {
+          Seq(Row(Row(null)), Row(null), Row(Row(null)))
+        } else {
+          Seq(Row(null), Row(null), Row(null))
+        }
+        checkAnswer(df, expected)
+        checkGlutenPlan[FileSourceScanExecTransformer](df)
+    }
+  }
 }
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 4620afef59..a1e6051d9d 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
@@ -21,6 +21,7 @@ import org.apache.gluten.shuffle.SupportsColumnarShuffle
 
 import org.apache.spark.network.util.{ByteUnit, JavaUtils}
 import org.apache.spark.sql.internal.{GlutenConfigUtil, SQLConf}
+import org.apache.spark.util.SparkVersionUtil
 
 import org.apache.hadoop.security.UserGroupInformation
 
@@ -500,6 +501,11 @@ object GlutenConfig extends ConfigRegistry {
   val SPARK_SHUFFLE_SPILL_COMPRESS_DEFAULT: Boolean = true
   val SPARK_IO_COMPRESSION_CODEC = "spark.io.compression.codec"
   val SPARK_MAX_BROADCAST_TABLE_SIZE = "spark.sql.maxBroadcastTableSize"
+  // Added in Spark 4.1 with default false (SPARK-53535). Earlier versions 
behave as if it is true.
+  val SPARK_LEGACY_PARQUET_RETURN_NULL_STRUCT_IF_ALL_FIELDS_MISSING =
+    "spark.sql.legacy.parquet.returnNullStructIfAllFieldsMissing"
+  val SPARK_LEGACY_PARQUET_RETURN_NULL_STRUCT_IF_ALL_FIELDS_MISSING_DEFAULT: 
Boolean =
+    !SparkVersionUtil.gteSpark41
 
   def get: GlutenConfig = {
     new GlutenConfig(GlutenCoreConfig.activeSQLConf)
@@ -524,7 +530,7 @@ object GlutenConfig extends ConfigRegistry {
     SQLConf.RUNTIME_BLOOM_FILTER_MAX_NUM_BITS.key,
     SQLConf.RUNTIME_BLOOM_FILTER_MAX_NUM_ITEMS.key,
     "spark.sql.decimalOperations.allowPrecisionLoss",
-    "spark.sql.legacy.parquet.returnNullStructIfAllFieldsMissing",
+    SPARK_LEGACY_PARQUET_RETURN_NULL_STRUCT_IF_ALL_FIELDS_MISSING,
     // s3 config
     SPARK_S3_ACCESS_KEY,
     SPARK_S3_SECRET_KEY,
@@ -592,7 +598,10 @@ object GlutenConfig extends ConfigRegistry {
         GLUTEN_COLUMNAR_TO_ROW_MEM_THRESHOLD.defaultValue.get.toString),
       (SPARK_SHUFFLE_SPILL_COMPRESS, 
SPARK_SHUFFLE_SPILL_COMPRESS_DEFAULT.toString),
       (SQLConf.SESSION_LOCAL_TIMEZONE.key, 
SQLConf.SESSION_LOCAL_TIMEZONE.defaultValueString),
-      (SQLConf.ANSI_ENABLED.key, SQLConf.ANSI_ENABLED.defaultValueString)
+      (SQLConf.ANSI_ENABLED.key, SQLConf.ANSI_ENABLED.defaultValueString),
+      (
+        SPARK_LEGACY_PARQUET_RETURN_NULL_STRUCT_IF_ALL_FIELDS_MISSING,
+        
SPARK_LEGACY_PARQUET_RETURN_NULL_STRUCT_IF_ALL_FIELDS_MISSING_DEFAULT.toString)
     ).foreach { case (k, defaultValue) => nativeConfMap.put(k, 
conf.getOrElse(k, defaultValue)) }
 
     Seq(


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to