infvg commented on code in PR #12699:
URL: https://github.com/apache/gluten/pull/12699#discussion_r3724337520


##########
gluten-iceberg/src/main/scala/org/apache/gluten/config/GlutenIcebergConfig.scala:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.config
+
+import org.apache.spark.sql.internal.SQLConf
+
+class GlutenIcebergConfig(conf: SQLConf) extends GlutenCoreConfig(conf) {
+  import GlutenIcebergConfig._
+
+  def enableNativeRead: Boolean = getConf(ENABLE_NATIVE_READ)
+
+  def enableNativeWrite: Boolean = getConf(ENABLE_NATIVE_WRITE)
+}
+
+/**
+ * Configurations of the Iceberg component. They are backend-agnostic on 
purpose: the read path
+ * ([[org.apache.gluten.extension.OffloadIcebergScan]]) is shared by all 
backends, and a backend
+ * newly supporting Iceberg write is expected to honor the same write switch 
rather than introduce
+ * its own key.
+ */

Review Comment:
   This comment can be removed; it's talking about the configs that are being 
added



##########
backends-velox/src-iceberg/main/scala/org/apache/gluten/extension/OffloadIcebergWrite.scala:
##########
@@ -28,43 +28,71 @@ import org.apache.spark.sql.execution.datasources.v2._
 
 import org.apache.iceberg.spark.source.IcebergWriteUtil.supportsWrite
 
+// The write switch is checked inside each rule below rather than at rule 
injection time so that

Review Comment:
   This comment can be removed



##########
gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala:
##########
@@ -717,4 +720,54 @@ abstract class IcebergSuite extends 
WholeStageTransformerSuite {
           e.getCause != null && e.getCause.getMessage.contains("null"))
     }
   }
+
+  test("iceberg scan falls back when native read is disabled") {
+    withTable("iceberg_read_switch_tb") {
+      spark.sql("""
+                  |create table iceberg_read_switch_tb using iceberg as
+                  |(select 1 as col1, 2 as col2)
+                  |""".stripMargin)
+
+      withSQLConf(GlutenIcebergConfig.ENABLE_NATIVE_READ.key -> "false") {
+        val df = spark.sql("select * from iceberg_read_switch_tb")
+        checkSparkPlan[BatchScanExec](df)
+        assert(
+          !getExecutedPlan(df).exists(_.isInstanceOf[IcebergScanTransformer]),
+          "Iceberg scan should not be offloaded when native read is disabled")
+        checkAnswer(df, Seq(Row(1, 2)))
+      }
+
+      // The switch is dynamic: offload resumes once it is back to the default.
+      runQueryAndCompare("select * from iceberg_read_switch_tb") {
+        checkGlutenPlan[IcebergScanTransformer]
+      }
+    }
+  }
+
+  test("disabling iceberg native read keeps other scans offloaded") {
+    withTable("iceberg_read_switch_tb") {
+      spark.sql("""
+                  |create table iceberg_read_switch_tb using iceberg as
+                  |(select 1 as col1)
+                  |""".stripMargin)
+
+      withTempPath {
+        path =>
+          spark.range(5).toDF("col1").write.parquet(path.getCanonicalPath)
+
+          withSQLConf(GlutenIcebergConfig.ENABLE_NATIVE_READ.key -> "false") {
+            val icebergDf = spark.sql("select * from iceberg_read_switch_tb")
+            assert(
+              
!getExecutedPlan(icebergDf).exists(_.isInstanceOf[IcebergScanTransformer]),
+              "Iceberg scan should fall back")
+
+            // The switch is scoped to Iceberg: scans of other formats keep 
being offloaded, which
+            // is the whole point of not reusing 
spark.gluten.sql.columnar.batchscan for this.

Review Comment:
   We can remove this too



##########
gluten-iceberg/src/main/scala/org/apache/gluten/extension/OffloadIcebergScan.scala:
##########
@@ -27,10 +27,17 @@ import org.apache.spark.sql.execution.SparkPlan
 import org.apache.spark.sql.execution.datasources.v2.BatchScanExec
 
 case class OffloadIcebergScan() extends OffloadSingleNode {
-  override def offload(plan: SparkPlan): SparkPlan = plan match {
-    case scan: BatchScanExec if 
IcebergScanTransformer.supportsBatchScan(scan.scan) =>
-      IcebergScanTransformer(scan)
-    case other => other
+  override def offload(plan: SparkPlan): SparkPlan = {
+    // The switch is checked here rather than at rule injection time so that 
it stays
+    // modifiable at runtime.

Review Comment:
   This can be removed too



-- 
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