LinSimon-901101 commented on code in PR #7155:
URL: https://github.com/apache/datafusion-comet/pull/7155#discussion_r4771693232


##########
spark/src/test/scala/org/apache/comet/CometIcebergWriteActionSuite.scala:
##########
@@ -104,6 +111,702 @@ class CometIcebergWriteActionSuite
     }
   }
 
+  Seq(false, true).foreach { adaptive =>
+    Seq(
+      "id INT NOT NULL, s STRUCT<a: INT, b: STRING>",
+      "id INT NOT NULL, s STRUCT<a: INT NOT NULL, b: STRING>",
+      "id INT, s STRUCT<a: INT, b: STRING> NOT NULL").zipWithIndex.foreach {
+      case (schema, index) =>
+        test(s"native Iceberg writer: Spark validates nullable input $index, 
AQE=$adaptive") {
+          assume(icebergAvailable)
+          withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> 
adaptive.toString) {
+            withIcebergCatalog { _ =>
+              withTempPath { path =>
+                sql("SELECT 1 AS id, named_struct('a', 2, 'b', 'value') AS 
s").write.parquet(
+                  path.toString)
+                val input = spark.read.parquet(path.toString)
+                withTempView("required_write_source") {
+                  input.createOrReplaceTempView("required_write_source")
+                  Seq("", "PARTITIONED BY (bucket(4, 
id))").zipWithIndex.foreach {
+                    case (partition, partIndex) =>
+                      val table = 
s"required_input_${index}_${partIndex}_$adaptive"
+                      val reference = s"${table}_jvm"
+                      Seq(table, reference).foreach { name =>
+                        sql(s"""CREATE TABLE cat.db.$name ($schema) USING 
iceberg $partition
+                          |TBLPROPERTIES 
('write.distribution-mode'='none')""".stripMargin)
+                      }
+                      def appendBoth(name: String): Unit = {
+                        sql(s"INSERT INTO cat.db.$name SELECT * FROM 
required_write_source")
+                        input.writeTo(s"cat.db.$name").append()
+                      }
+                      val snapshot = withNativeEnabled {
+                        captureWrite(table)(appendBoth(table))
+                      }
+                      assert(snapshot.snapshotDelta == 2)
+                      assertSparkRequiredWrite(snapshot.plans)
+                      assert(
+                        snapshot.plans.count(p =>
+                          collectWithSubqueries(p) { case w: 
CometIcebergWriteExec =>
+                            w
+                          }.nonEmpty) == 2,
+                        snapshot.plans.mkString("\n"))
+                      withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+                        appendBoth(reference)
+                      }
+                      checkAnswer(
+                        sql(s"SELECT * FROM cat.db.$table"),
+                        sql(s"SELECT * FROM cat.db.$reference"))
+                  }
+                }
+              }
+            }
+          }
+        }
+    }
+
+    test(s"native Iceberg writer: required input keeps the default shuffle, 
AQE=$adaptive") {
+      assume(icebergAvailable)
+      withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> adaptive.toString) 
{
+        withIcebergCatalog { _ =>
+          withTempPath { path =>
+            sql("SELECT 1 AS id UNION ALL SELECT 
2").write.parquet(path.toString)
+            val table = s"required_shuffle_$adaptive"
+            sql(s"""CREATE TABLE cat.db.$table (id INT NOT NULL)
+              |USING iceberg PARTITIONED BY (bucket(4, id))""".stripMargin)
+            val snapshot = withNativeEnabled {
+              captureWrite(table) {
+                
spark.read.parquet(path.toString).writeTo(s"cat.db.$table").append()
+              }
+            }
+            assert(snapshot.snapshotDelta == 1)
+            assertSparkRequiredWrite(snapshot.plans, requireBridge = false)

Review Comment:
   I add a no-extra-bridge assertion to existing shuffle tests, and I test it 
by removing the protective conditions, those assertions fail in both Spark 3.5 
and 4.1, but both version pass when I restore them.



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