yaooqinn commented on code in PR #13626:
URL: https://github.com/apache/gluten/pull/13626#discussion_r4735400776


##########
backends-velox/src/main/scala/org/apache/gluten/execution/ColumnarPartialProjectExec.scala:
##########
@@ -329,6 +335,9 @@ object ColumnarPartialProjectExec {
         replaceByAlias(h, replacedAlias)
       case e if isBlacklistExpression(e) =>
         replaceByAlias(e, replacedAlias)
+      case e if e.children.exists(_.isInstanceOf[LambdaFunction]) =>

Review Comment:
   This aliases every higher-order function, including ones Velox runs natively 
when no UDF is involved (`transform`, `filter` and `aggregate` are mapped in 
`ExpressionMappings`, and `ScalarFunctionsValidateSuite` checks that 
`transform(arr, x -> x + 1)` offloads). In the issue's query, `transform(items, 
x -> x + 1)` has no UDF, yet the new test asserts it stays out of 
`ProjectExecTransformer`, so it runs on the JVM through Arrow. To keep each 
lambda and its variable bindings together, would it be enough to alias the 
higher-order function only when its lambda contains a UDF or a blacklisted 
expression, and to stop `traverseUpExpression` from descending into a 
`LambdaFunction`, so that a failed validation aliases the whole function 
instead of a piece that uses the lambda variable?
   



##########
backends-velox/src/main/scala/org/apache/gluten/execution/ColumnarPartialProjectExec.scala:
##########
@@ -231,9 +231,15 @@ case class ColumnarPartialProjectExec(projectList: 
Seq[Expression], child: Spark
 
     val schema =
       ExpressionUtils.structFromAttributes(replacedAlias.map(_.toAttribute))
-    val targetBatch = ArrowColumnVectors.fromRows(
-      schema,
-      (0 until numRows).iterator.map(i => proj(sparkColumnarBatch.getRow(i))))
+    val rows = (0 until numRows).iterator.map(sparkColumnarBatch.getRow)
+    val inputRows = if 
(replacedAlias.exists(_.exists(_.isInstanceOf[LambdaFunction]))) {
+      // Lambda evaluation needs null-aware array access, which 
ColumnarArray.get lacks.
+      // TODO: Remove this conversion once all supported Spark versions handle 
null elements
+      // correctly in ColumnarArray.get.
+      val toUnsafe = UnsafeProjection.create(projectAttributes.toSeq, 
projectAttributes.toSeq)

Review Comment:
   Nit: this creates the `UnsafeProjection` (and runs the 
`replacedAlias.exists` check) for every batch. Could both move next to 
`projection`, which is created once per partition?
   



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