sam-1112 commented on code in PR #5359:
URL: https://github.com/apache/datafusion-comet/pull/5359#discussion_r3791876431


##########
spark/src/main/scala/org/apache/comet/serde/CometScalarFunction.scala:
##########
@@ -21,14 +21,53 @@ package org.apache.comet.serde
 
 import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
 
+import org.apache.comet.CometSparkSessionExtensions.withFallbackReason
 import org.apache.comet.serde.ExprOuterClass.Expr
 import org.apache.comet.serde.QueryPlanSerde.{exprToProtoInternal, 
scalarFunctionExprToProto}
 
 /** Serde for scalar function. */
 case class CometScalarFunction[T <: Expression](name: String) extends 
CometExpressionSerde[T] {
   override def convert(expr: T, inputs: Seq[Attribute], binding: Boolean): 
Option[Expr] = {
+    if (CometScalarFunction.isAnsiSensitive(expr)) {
+      withFallbackReason(
+        expr,
+        s"${expr.nodeName} carries failOnError/evalMode/nullOnOverflow and 
cannot use " +
+          s"CometScalarFunction('$name'). Prefer name-based ANSI/try variants 
" +
+          "(e.g. parse_url / try_parse_url), or a custom serde with " +
+          "scalarFunctionExprToProtoWithReturnType plus a native match arm 
that " +
+          "consumes fail_on_error.")
+      return None
+    }
     val childExpr = expr.children.map(exprToProtoInternal(_, inputs, binding))
     val optExpr = scalarFunctionExprToProto(name, childExpr: _*)
     optExpr
   }
 }
+
+object CometScalarFunction {
+
+  /** Product field names that indicate ANSI / eval-mode sensitive Spark 
expressions. */
+  private val AnsiSensitiveFields: Set[String] =
+    Set("failOnError", "evalMode", "nullOnOverflow")

Review Comment:
   Yeah, good catch. Both fields are in `AnsiSensitiveFields` now. `Round` / 
`BRound` / `Conv` keep ANSI in `ansiEnabled`, and Spark 4.1+ arithmetic uses 
`evalContext` instead of an `evalMode` field, so the old set would miss them 
and the audit would still pass. Coverage is a real Spark `Round` in 
`CometScalarFunctionSuite`, and a real Spark 4.1+ `Add(..., 
NumericEvalContext(...))` in `CometDecimalArithmeticViewSuite` (that 
constructor only exists on 4.1+).



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