Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update code as comments
  • Loading branch information
chenghao-intel committed Jul 3, 2015
commit ed5c19cc5974d207340910ded2e36957b39ae377
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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.).
Copy link
Contributor

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"

*/
case class Decode(bin: Expression, charset: Expression)
extends Expression with ExpectsInputTypes {
case class Decode(bin: Expression, charset: Expression) extends Expression with ExpectsInputTypes {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand All @@ -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.)
*/
Expand All @@ -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)
Expand All @@ -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)"
}