mbutrovich commented on code in PR #6709:
URL: https://github.com/apache/datafusion-comet/pull/6709#discussion_r4199339243


##########
spark/src/main/scala/org/apache/comet/serde/CometScalaUDF.scala:
##########
@@ -145,12 +145,17 @@ object CometScalaUDF extends 
CometExpressionSerde[ScalaUDF] {
               s"(${e.getClass.getSimpleName}: ${e.getMessage})")
           return None
       }
-    val exprArg = exprToProtoInternal(Literal(bytes, BinaryType), inputs, 
binding).getOrElse {
-      withFallbackReason(
-        expr,
-        s"$exprName: codegen dispatch: could not serialize closure-serialized 
bound " +
-          "expression payload")
-      return None
+    // Arg 0 is a digest of the bytes. The dispatcher finds each batch's 
kernel by it, so it reads
+    // the bytes only to compile on a cache miss instead of copying and 
hashing them for every
+    // batch.
+    val exprArgs = Seq(CometScalaUDFCodegen.digest(bytes), bytes).map { 
payload =>

Review Comment:
   Should a test check what the serde emits here, that arg 0 is the digest of 
arg 1? The dispatcher trusts a cache hit without comparing the bytes, so this 
line is what keeps two different expressions from sharing a kernel. The new 
test in `CometCodegenSuite` builds its own digest with 
`CometScalaUDFCodegen.digest` and calls the dispatcher directly. It would keep 
passing if the digest the serde ships stopped matching the bytes it ships next 
to it.
   
   The test `codegen dispatch coverage survives the decimal promotion rewrite` 
already builds the proto through `QueryPlanSerde.exprToProto` 
([L601-L617](https://github.com/apache/datafusion-comet/blob/1a5797fe83601d388dd2fd3928048719ba646173/spark/src/test/scala/org/apache/comet/CometCodegenSuite.scala#L601-L617)),
 so it could check this with a few lines, something like:
   
   ```scala
   val args = proto.getJvmScalarUdf.getArgsList
   val bytes = args.get(1).getLiteral.getBytesVal.toByteArray
   assert(
     
args.get(0).getLiteral.getBytesVal.toByteArray.sameElements(CometScalaUDFCodegen.digest(bytes)))
   ```



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