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


##########
spark/src/main/scala/org/apache/spark/sql/comet/CometSparkToColumnarExec.scala:
##########
@@ -129,7 +132,75 @@ case class CometSparkToColumnarExec(child: SparkPlan, 
batchSize: Option[Int] = N
 
 }
 
-object CometSparkToColumnarExec extends CometSink[SparkPlan] with 
DataTypeSupport {
+object CometSparkToColumnarExec
+    extends CometSink[SparkPlan]
+    with DataTypeSupport
+    with CometTypeShim {
+
+  /**
+   * Whether the Iceberg writer may convert this Spark row subtree to Arrow. 
Native import
+   * normalizes invalid UTF-8, while Spark rows can retain those bytes. A new 
conversion is safe
+   * only when its string outputs preserve already valid strings or contain 
validated literals.
+   */
+  def isRowConversionSupported(plan: SparkPlan, fallbackReasons: 
ListBuffer[String]): Boolean = {
+    if (!isSchemaSupported(plan.schema, fallbackReasons)) {
+      false
+    } else if (hasValidStrings(plan)) {
+      true
+    } else {
+      fallbackReasons += "Iceberg writer row conversion cannot prove that 
string outputs contain " +
+        "valid UTF-8; native Arrow import could change their bytes"
+      false
+    }
+  }
+
+  private def containsString(dt: DataType): Boolean =
+    dt.existsRecursively(_.isInstanceOf[StringType])
+
+  private def hasValidStrings(plan: SparkPlan): Boolean = {
+    if (!containsString(plan.schema)) {
+      true
+    } else {
+      plan match {
+        // These planning placeholders disappear without running a native 
import.
+        case CometScanWrapper(_, source) => hasValidStrings(source)

Review Comment:
   Thanks for pointing this out, I added Coalesce, Union and shuffle handling, 
and removed the dead placeholder cases.



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