Skip to content

Commit

Permalink
address commments
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies Liu committed Jul 2, 2015
1 parent 1a24082 commit c3af78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ case class Hex(child: Expression) extends UnaryExpression with Serializable {
* Resulting characters are returned as a byte array.
*/
case class Unhex(child: Expression)
extends UnaryExpression with AutoCastInputTypes with Serializable {
extends UnaryExpression with ExpectsInputTypes with Serializable {

override def nullable: Boolean = true
override def dataType: DataType = BinaryType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.types.{DataType, DoubleType, LongType}
import org.apache.spark.sql.types._

class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {

Expand Down Expand Up @@ -226,11 +226,15 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
}

test("hex") {
checkEvaluation(Hex(Literal.create(null, IntegerType)), null)
checkEvaluation(Hex(Literal(28)), "1C")
checkEvaluation(Hex(Literal(-28)), "FFFFFFFFFFFFFFE4")
checkEvaluation(Hex(Literal.create(null, LongType)), null)
checkEvaluation(Hex(Literal(100800200404L)), "177828FED4")
checkEvaluation(Hex(Literal(-100800200404L)), "FFFFFFE887D7012C")
checkEvaluation(Hex(Literal.create(null, StringType)), null)
checkEvaluation(Hex(Literal("helloHex")), "68656C6C6F486578")
checkEvaluation(Hex(Literal.create(null, BinaryType)), null)
checkEvaluation(Hex(Literal("helloHex".getBytes())), "68656C6C6F486578")
// scalastyle:off
// Turn off scala style for non-ascii chars
Expand All @@ -239,10 +243,15 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
}

test("unhex") {
checkEvaluation(Unhex(Literal.create(null, StringType)), null)
checkEvaluation(Unhex(Literal("737472696E67")), "string".getBytes)
checkEvaluation(Unhex(Literal("")), new Array[Byte](0))
checkEvaluation(Unhex(Literal("F")), Array[Byte](15))
checkEvaluation(Unhex(Literal("ff")), Array[Byte](-1))
// scalastyle:off
// Turn off scala style for non-ascii chars
checkEvaluation(Unhex(Literal("E4B889E9878DE79A84")), "三重的".getBytes("UTF-8"))
// scalastyle:on
}

test("hypot") {
Expand Down

0 comments on commit c3af78c

Please sign in to comment.