You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by GitBox <gi...@apache.org> on 2021/09/16 02:08:23 UTC

[GitHub] [incubator-kyuubi] yaooqinn commented on a change in pull request #1109: [WIP][KYUUBI #1105] Zorder codegen support

yaooqinn commented on a change in pull request #1109:
URL: https://github.com/apache/incubator-kyuubi/pull/1109#discussion_r709697384



##########
File path: dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/Zorder.scala
##########
@@ -42,21 +46,61 @@ case class Zorder(children: Seq[Expression]) extends Expression with CodegenFall
   }
 
   @transient
-  private lazy val defaultNullValues: Seq[Any] = {
-    children.map(child => ZorderBytesUtils.defaultValue(child.dataType))
+  private lazy val defaultNullValues: JMap[Int, Array[Byte]] = {
+    val map = new JHashMap[Int, Array[Byte]](children.length)
+    children.zipWithIndex
+      .foreach {
+        case (child, index) =>
+          map.put(index, ZorderBytesUtils.toByte(
+            ZorderBytesUtils.defaultValue(child.dataType)))
+      }
+    map
   }
 
   override def eval(input: InternalRow): Any = {
-    val evaluated = children.zipWithIndex.map { case (child: Expression, index) =>
-      val v = child.eval(input)
-      if (v == null) {
-        defaultNullValues(index)
-      } else {
-        v
-      }
+    val binaryArr = children.zipWithIndex.map {
+      case (child: Expression, index) =>
+        val v = child.eval(input)
+        if (v == null) {
+          defaultNullValues.get(index)
+        } else {
+          ZorderBytesUtils.toByte(v)
+        }
     }
+    ZorderBytesUtils.interleaveMultiByteArray(binaryArr.toArray)
+  }
 
-    val binaryArr = evaluated.map(ZorderBytesUtils.toByte).toArray
-    ZorderBytesUtils.interleaveMultiByteArray(binaryArr)
+  override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+    val evals = children.map(_.genCode(ctx))
+    val defaultValues = ctx.addReferenceObj("defaultValues", defaultNullValues)
+    val binaryArray = ctx.freshName("binaryArray")
+    val util = ZorderBytesUtils.getClass.getName + ".MODULE$"

Review comment:
       ZorderBytesUtils.getClass.getName.stripSuffix("$")




-- 
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: commits-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org