philo-he commented on code in PR #13667:
URL: https://github.com/apache/gluten/pull/13667#discussion_r4661773250


##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala:
##########
@@ -183,6 +183,12 @@ abstract class FileSourceScanExecTransformerBase(
   }
 
   override protected def doValidateInternal(): ValidationResult = {
+    if (hasNonNullExistenceDefaults) {
+      // Missing fields need their original default, while explicitly stored 
nulls must stay null.
+      return ValidationResult.failed(
+        "Native file scans do not support non-null existence defaults 
(EXISTS_DEFAULT).")

Review Comment:
   Nit: it would help debugging if the reason listed the affected columns, e.g. 
`"Native file scans do not support non-null existence defaults (EXISTS_DEFAULT) 
on columns: value, s"`. That makes the fallback summary much easier to act on 
for wide tables.



##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/FileSourceScanExecTransformer.scala:
##########
@@ -183,6 +183,12 @@ abstract class FileSourceScanExecTransformerBase(
   }
 
   override protected def doValidateInternal(): ValidationResult = {

Review Comment:
   This guard only covers scans built on `FileSourceScanExecTransformerBase`. 
Two other paths look like they could hit the same bug:
   - `BatchScanExecTransformer` over a DSv2 `FileScan` (the new tests force V1 
with `USE_V1_SOURCE_LIST=parquet`, so this path isn't exercised).
   - Any subclass that overrides `doValidateInternal` without calling `super`.
   
   Could you confirm these are unreachable or out of scope, or add a guard or a 
TODO?



##########
gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDefaultColumnScanTests.scala:
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql
+
+import org.apache.gluten.config.GlutenConfig
+import org.apache.gluten.execution.FileSourceScanExecTransformerBase
+
+import org.apache.spark.sql.execution.FileSourceScanExec
+import org.apache.spark.sql.internal.SQLConf
+
+trait GlutenDefaultColumnScanTests extends GlutenSQLTestsBaseTrait {

Review Comment:
   Could we drop this trait and revert the `GlutenFileScanSuite` changes? 
Spark's `FileScanSuite` only covers DSv2 `FileScan` equality, and suites that 
extend Spark suites should hold only Spark's tests and Gluten rewrites of them.
   
   Read correctness is already covered by Spark's `InsertSuite` default-column 
tests once they're re-enabled (see my comment on `GlutenInsertSuite`). What's 
left is the plan shape: the scan falls back when the query reads or filters on 
a column with a non-null default, and stays native for pruned scans, `count(*)` 
and NULL defaults. A few simple tests for that in a Gluten-owned suite under 
`backends-velox/src/test` would be enough, e.g. next to the existing fallback 
tests.



##########
gluten-ut/spark35/src/test/scala/org/apache/spark/sql/sources/GlutenInsertSuite.scala:
##########
@@ -422,9 +422,9 @@ class GlutenInsertSuite
             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))
+          checkAnswer(spark.table("t"), Row(false, Seq(1, 2)))

Review Comment:
   With the fallback in place, could we re-enable Spark's original 
default-column tests instead of keeping these Gluten copies? The Velox and 
ClickHouse test settings exclude them because native scans didn't backfill old 
rows:
   - `INSERT rows, ALTER TABLE ADD COLUMNS with DEFAULTs, then SELECT them` 
(the Gluten copy only inserts rows after adding the column, so it never checks 
old rows)
   - `SPARK-39557 INSERT INTO statements with tables with array defaults`
   - `SPARK-39557 INSERT INTO statements with tables with struct defaults`
   - `SPARK-39557 INSERT INTO statements with tables with map defaults` (the 
Gluten copy is `ignoreGluten`, so it never runs)
   
   Removing those `.exclude(...)` entries for each Spark version and deleting 
the matching `testGluten` copies would give coverage of Parquet and ORC, SQL 
and DataFrame inserts, and primitive, array, struct and map defaults on old 
rows, with less duplicated test code than editing the copies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to