sam-1112 commented on code in PR #5359:
URL: https://github.com/apache/datafusion-comet/pull/5359#discussion_r3791848205
##########
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")
+
+ /**
+ * True when the Spark expression case class declares an ANSI-related
constructor field. Used to
+ * reject miswiring via plain [[CometScalarFunction]].
+ */
+ private[serde] def isAnsiSensitive(expr: Expression): Boolean = {
+ expr match {
+ case p: Product =>
+ p.productElementNames.exists(AnsiSensitiveFields.contains)
Review Comment:
Fixed. I removed `Product.productElementNames` and now detect ANSI-sensitive
fields with Java reflection (`Class.getDeclaredFields`, walking superclasses).
That compiles on both Scala 2.12 and 2.13. Verified with `./mvnw -pl spark -am
compile -DskipTests -Pspark-3.4` using JDK 11.
--
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]