wForget commented on code in PR #10968:
URL: 
https://github.com/apache/incubator-gluten/pull/10968#discussion_r2471563071


##########
gluten-arrow/src/main/scala/org/apache/gluten/expression/GenerateArrowProjection.scala:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.expression
+
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
+import org.apache.spark.sql.catalyst.expressions.BindReferences.bindReferences
+import org.apache.spark.sql.catalyst.expressions.aggregate.NoOp
+import org.apache.spark.sql.catalyst.expressions.codegen._
+
+// ArrowProjection is not accessible in Java
+abstract class BaseArrowProjection extends ArrowProjection
+
+/**
+ * Generates byte code that produces a [[InternalRow]] object that can update 
itself based on a new
+ * input [[InternalRow]] for a fixed set of [[Expression Expressions]]. It 
exposes a `target`
+ * method, which is used to set the row that will be updated. The internal 
[[InternalRow]] object
+ * created internally is used only when `target` is not used.
+ */
+object GenerateArrowProjection extends CodeGenerator[Seq[Expression], 
ArrowProjection] {
+
+  protected def canonicalize(in: Seq[Expression]): Seq[Expression] =
+    in.map(ExpressionCanonicalizer.execute)
+
+  protected def bind(in: Seq[Expression], inputSchema: Seq[Attribute]): 
Seq[Expression] =
+    bindReferences(in, inputSchema)
+
+  def generate(
+      expressions: Seq[Expression],
+      inputSchema: Seq[Attribute],
+      useSubexprElimination: Boolean): ArrowProjection = {
+    create(canonicalize(bind(expressions, inputSchema)), useSubexprElimination)
+  }
+
+  def generate(expressions: Seq[Expression], useSubexprElimination: Boolean): 
ArrowProjection = {
+    create(canonicalize(expressions), useSubexprElimination)
+  }
+
+  protected def create(expressions: Seq[Expression]): ArrowProjection = {
+    create(expressions, false)
+  }
+
+  private def create(
+      expressions: Seq[Expression],
+      useSubexprElimination: Boolean): ArrowProjection = {
+    val ctx = newCodeGenContext()
+    val validExpr = expressions.zipWithIndex.filter {
+      case (NoOp, _) => false
+      case _ => true
+    }
+    val exprVals = ctx.generateExpressions(validExpr.map(_._1), 
useSubexprElimination)
+
+    // 4-tuples: (code for projection, isNull variable name, value variable 
name, column index)
+    val projectionCodes: Seq[(String, String)] = validExpr.zip(exprVals).map {
+      case ((e, i), ev) =>
+        val value = JavaCode
+          .global(ctx.addMutableState(CodeGenerator.javaType(e.dataType), 
"value"), e.dataType)
+        val (code, isNull) = if (e.nullable) {
+          val isNull = ctx.addMutableState(CodeGenerator.JAVA_BOOLEAN, 
"isNull")
+          (
+            s"""
+               |${ev.code}
+               |$isNull = ${ev.isNull};
+               |$value = ${ev.value};
+            """.stripMargin,
+            JavaCode.isNullGlobal(isNull))
+        } else {
+          (
+            s"""
+               |${ev.code}
+               |$value = ${ev.value};
+            """.stripMargin,
+            FalseLiteral)
+        }
+        val update = CodeGenerator.updateColumn(
+          "mutableRow",
+          e.dataType,
+          i,
+          ExprCode(isNull, value),
+          e.nullable,
+          isVectorized = true)

Review Comment:
   set `isVectorized=true`



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