You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2015/07/21 01:12:00 UTC
spark git commit: [SPARK-9160][SQL] codegen encode, decode
Repository: spark
Updated Branches:
refs/heads/master c9db8eaa4 -> dac7dbf5a
[SPARK-9160][SQL] codegen encode, decode
Jira: https://issues.apache.org/jira/browse/SPARK-9160
Author: Tarek Auel <ta...@googlemail.com>
Closes #7543 from tarekauel/SPARK-9160 and squashes the following commits:
7528f0e [Tarek Auel] [SPARK-9160][SQL] codegen encode, decode
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/dac7dbf5
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/dac7dbf5
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/dac7dbf5
Branch: refs/heads/master
Commit: dac7dbf5a6bd663ef3acaa5b2249b31140fa6857
Parents: c9db8ea
Author: Tarek Auel <ta...@googlemail.com>
Authored: Mon Jul 20 16:11:56 2015 -0700
Committer: Reynold Xin <rx...@databricks.com>
Committed: Mon Jul 20 16:11:56 2015 -0700
----------------------------------------------------------------------
.../catalyst/expressions/stringOperations.scala | 25 ++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/dac7dbf5/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
index e660d49..a568242 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
@@ -818,7 +818,7 @@ case class UnBase64(child: Expression) extends UnaryExpression with ImplicitCast
* If either argument is null, the result will also be null.
*/
case class Decode(bin: Expression, charset: Expression)
- extends BinaryExpression with ImplicitCastInputTypes with CodegenFallback {
+ extends BinaryExpression with ImplicitCastInputTypes {
override def left: Expression = bin
override def right: Expression = charset
@@ -829,6 +829,17 @@ case class Decode(bin: Expression, charset: Expression)
val fromCharset = input2.asInstanceOf[UTF8String].toString
UTF8String.fromString(new String(input1.asInstanceOf[Array[Byte]], fromCharset))
}
+
+ override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
+ nullSafeCodeGen(ctx, ev, (bytes, charset) =>
+ s"""
+ try {
+ ${ev.primitive} = UTF8String.fromString(new String($bytes, $charset.toString()));
+ } catch (java.io.UnsupportedEncodingException e) {
+ org.apache.spark.unsafe.PlatformDependent.throwException(e);
+ }
+ """)
+ }
}
/**
@@ -837,7 +848,7 @@ case class Decode(bin: Expression, charset: Expression)
* If either argument is null, the result will also be null.
*/
case class Encode(value: Expression, charset: Expression)
- extends BinaryExpression with ImplicitCastInputTypes with CodegenFallback {
+ extends BinaryExpression with ImplicitCastInputTypes {
override def left: Expression = value
override def right: Expression = charset
@@ -848,6 +859,16 @@ case class Encode(value: Expression, charset: Expression)
val toCharset = input2.asInstanceOf[UTF8String].toString
input1.asInstanceOf[UTF8String].toString.getBytes(toCharset)
}
+
+ override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
+ nullSafeCodeGen(ctx, ev, (string, charset) =>
+ s"""
+ try {
+ ${ev.primitive} = $string.toString().getBytes($charset.toString());
+ } catch (java.io.UnsupportedEncodingException e) {
+ org.apache.spark.unsafe.PlatformDependent.throwException(e);
+ }""")
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org