Myx778 commented on code in PR #4105:
URL: https://github.com/apache/datafusion-comet/pull/4105#discussion_r3158231117


##########
spark/src/main/scala/org/apache/comet/serde/strings.scala:
##########
@@ -84,6 +84,20 @@ object CometLength extends 
CometScalarFunction[Length]("length") {
   }
 }
 
+object CometLevenshtein extends 
CometScalarFunction[Levenshtein]("levenshtein") {

Review Comment:
   Fixed! Changed `CometLevenshtein` from extending `CometScalarFunction` to 
`CometExpressionSerde`, and overrode `convert()` to use 
`scalarFunctionExprToProtoWithReturnType`:
   
   ```scala
   override def convert(
       expr: Levenshtein,
       inputs: Seq[Attribute],
       binding: Boolean): Option[Expr] = {
     val childExprs = expr.children.map(exprToProtoInternal(_, inputs, binding))
     val optExpr = scalarFunctionExprToProtoWithReturnType(
       "levenshtein",
       IntegerType,
       false,
       childExprs: _*)
     optExprWithInfo(optExpr, expr, expr.children: _*)
   }
   ```
   
   This ensures the proto includes `return_type = IntegerType`, so the native 
planner uses our registered Comet UDF directly instead of looking up 
DataFusion's built-in 2-arg `LevenshteinFunc`.
   
   Also fixed the Spotless issue (removed unnecessary `s` prefix).
   
   Commit: f099ffeb



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