diff options
author | Tarek Auel <tarek.auel@googlemail.com> | 2015-07-20 16:11:56 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2015-07-20 16:11:56 -0700 |
commit | dac7dbf5a6bd663ef3acaa5b2249b31140fa6857 (patch) | |
tree | da4c4481aa4daa5ea2e42bb4d6f691fc6f4369c0 /sql | |
parent | c9db8eaa42387c03cde12c1d145a6f72872def71 (diff) | |
download | spark-dac7dbf5a6bd663ef3acaa5b2249b31140fa6857.tar.gz spark-dac7dbf5a6bd663ef3acaa5b2249b31140fa6857.tar.bz2 spark-dac7dbf5a6bd663ef3acaa5b2249b31140fa6857.zip |
[SPARK-9160][SQL] codegen encode, decode
Jira: https://issues.apache.org/jira/browse/SPARK-9160
Author: Tarek Auel <tarek.auel@googlemail.com>
Closes #7543 from tarekauel/SPARK-9160 and squashes the following commits:
7528f0e [Tarek Auel] [SPARK-9160][SQL] codegen encode, decode
Diffstat (limited to 'sql')
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala | 25 |
1 files changed, 23 insertions, 2 deletions
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 e660d499fa..a5682428b3 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); + }""") + } } /** |