spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wenc...@apache.org
Subject spark git commit: [SPARK-16640][SQL] Add codegen for Elt function
Date Thu, 21 Jul 2016 12:54:06 GMT
Repository: spark
Updated Branches:
  refs/heads/master 8674054d3 -> 6203668d5


[SPARK-16640][SQL] Add codegen for Elt function

## What changes were proposed in this pull request?

Elt function doesn't support codegen execution now. We should add the support.

## How was this patch tested?

Jenkins tests.

Author: Liang-Chi Hsieh <simonh@tw.ibm.com>

Closes #14277 from viirya/elt-codegen.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/6203668d
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/6203668d
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/6203668d

Branch: refs/heads/master
Commit: 6203668d50c1193cde20b0c35f95cf12dabc0805
Parents: 8674054
Author: Liang-Chi Hsieh <simonh@tw.ibm.com>
Authored: Thu Jul 21 20:54:17 2016 +0800
Committer: Wenchen Fan <wenchen@databricks.com>
Committed: Thu Jul 21 20:54:17 2016 +0800

----------------------------------------------------------------------
 .../expressions/stringExpressions.scala         | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/6203668d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
index 61549c9..fc13845 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
@@ -171,7 +171,7 @@ case class ConcatWs(children: Seq[Expression])
   usage = "_FUNC_(n, str1, str2, ...) - returns the n-th string, e.g. returns str2 when n
is 2",
   extended = "> SELECT _FUNC_(1, 'scala', 'java') FROM src LIMIT 1;\n" + "'scala'")
 case class Elt(children: Seq[Expression])
-  extends Expression with ImplicitCastInputTypes with CodegenFallback {
+  extends Expression with ImplicitCastInputTypes {
 
   private lazy val indexExpr = children.head
   private lazy val stringExprs = children.tail.toArray
@@ -204,6 +204,29 @@ case class Elt(children: Seq[Expression])
       }
     }
   }
+
+  override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+    val index = indexExpr.genCode(ctx)
+    val strings = stringExprs.map(_.genCode(ctx))
+    val assignStringValue = strings.zipWithIndex.map { case (eval, index) =>
+      s"""
+        case ${index + 1}:
+          ${ev.value} = ${eval.isNull} ? null : ${eval.value};
+          break;
+      """
+    }.mkString("\n")
+    val indexVal = ctx.freshName("index")
+    val stringArray = ctx.freshName("strings");
+
+    ev.copy(index.code + "\n" + strings.map(_.code).mkString("\n") + s"""
+      final int $indexVal = ${index.value};
+      UTF8String ${ev.value} = null;
+      switch ($indexVal) {
+        $assignStringValue
+      }
+      final boolean ${ev.isNull} = ${ev.value} == null;
+    """)
+  }
 }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message