-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-8238][SPARK-8239][SPARK-8242][SPARK-8243][SPARK-8268][SQL]Add ascii/base64/unbase64/encode/decode functions #6843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
491ce7b
e2df768
96170fc
ed5c19c
9d6f9f4
78dee7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,7 +304,7 @@ case class StringLength(child: Expression) extends UnaryExpression with ExpectsI | |
| */ | ||
| case class Ascii(child: Expression) extends UnaryExpression with ExpectsInputTypes { | ||
| override def dataType: DataType = IntegerType | ||
| override def expectedChildTypes: Seq[DataType] = Seq(StringType) | ||
| override def inputTypes: Seq[DataType] = Seq(StringType) | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
| val string = child.eval(input) | ||
|
|
@@ -320,15 +320,15 @@ case class Ascii(child: Expression) extends UnaryExpression with ExpectsInputTyp | |
| } | ||
| } | ||
|
|
||
| override def toString: String = s"ascii($child)" | ||
| override def toString: String = s"ASCII($child)" | ||
| } | ||
|
|
||
| /** | ||
| * Converts the argument from binary to a base 64 string. | ||
| */ | ||
| case class Base64(child: Expression) extends UnaryExpression with ExpectsInputTypes { | ||
| override def dataType: DataType = StringType | ||
| override def expectedChildTypes: Seq[DataType] = Seq(BinaryType) | ||
| override def inputTypes: Seq[DataType] = Seq(BinaryType) | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
| val bytes = child.eval(input) | ||
|
|
@@ -341,15 +341,15 @@ case class Base64(child: Expression) extends UnaryExpression with ExpectsInputTy | |
| } | ||
| } | ||
|
|
||
| override def toString: String = s"base64($child)" | ||
| override def toString: String = s"BASE64($child)" | ||
| } | ||
|
|
||
| /** | ||
| * Converts the argument from a base 64 string to BINARY. | ||
| */ | ||
| case class UnBase64(child: Expression) extends UnaryExpression with ExpectsInputTypes { | ||
| override def dataType: DataType = BinaryType | ||
| override def expectedChildTypes: Seq[DataType] = Seq(StringType) | ||
| override def inputTypes: Seq[DataType] = Seq(StringType) | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
| val string = child.eval(input) | ||
|
|
@@ -360,21 +360,20 @@ case class UnBase64(child: Expression) extends UnaryExpression with ExpectsInput | |
| } | ||
| } | ||
|
|
||
| override def toString: String = s"unbase64($child)" | ||
| override def toString: String = s"UNBASE64($child)" | ||
| } | ||
|
|
||
| /** | ||
| * Decodes the first argument into a String using the provided character set | ||
| * (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). | ||
| * If either argument is null, the result will also be null. (As of Hive 0.12.0.). | ||
| */ | ||
| case class Decode(bin: Expression, charset: Expression) | ||
| extends Expression with ExpectsInputTypes { | ||
| case class Decode(bin: Expression, charset: Expression) extends Expression with ExpectsInputTypes { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make this extend BinaryExpression? You can just define def bin = left, and def charset = right.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually that's my intention, as I think the parameters is asymmetric semantically. Not sure if you are thinking the code impovement like #7157? |
||
| override def children: Seq[Expression] = bin :: charset :: Nil | ||
| override def foldable: Boolean = bin.foldable && charset.foldable | ||
| override def nullable: Boolean = bin.nullable || charset.nullable | ||
| override def dataType: DataType = StringType | ||
| override def expectedChildTypes: Seq[DataType] = Seq(BinaryType, StringType) | ||
| override def inputTypes: Seq[DataType] = Seq(BinaryType, StringType) | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
| val l = bin.eval(input) | ||
|
|
@@ -391,11 +390,11 @@ case class Decode(bin: Expression, charset: Expression) | |
| } | ||
| } | ||
|
|
||
| override def toString: String = s"decode($bin, $charset)" | ||
| override def toString: String = s"DECODE($bin, $charset)" | ||
| } | ||
|
|
||
| /** | ||
| * Encodes the first argument into a BINARY using the provided character set | ||
| * Encodes the first argument into a BINARY using the provided character set | ||
| * (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). | ||
| * If either argument is null, the result will also be null. (As of Hive 0.12.0.) | ||
| */ | ||
|
|
@@ -405,7 +404,7 @@ case class Encode(value: Expression, charset: Expression) | |
| override def foldable: Boolean = value.foldable && charset.foldable | ||
| override def nullable: Boolean = value.nullable || charset.nullable | ||
| override def dataType: DataType = BinaryType | ||
| override def expectedChildTypes: Seq[DataType] = Seq(StringType, StringType) | ||
| override def inputTypes: Seq[DataType] = Seq(StringType, StringType) | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
| val l = value.eval(input) | ||
|
|
@@ -422,7 +421,7 @@ case class Encode(value: Expression, charset: Expression) | |
| } | ||
| } | ||
|
|
||
| override def toString: String = s"encode($value, $charset)" | ||
| override def toString: String = s"ENCODE($value, $charset)" | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "As of Hive 0.12.0"