aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src
diff options
context:
space:
mode:
authorzhichao.li <zhichao.li@intel.com>2015-06-29 12:25:16 -0700
committerDavies Liu <davies@databricks.com>2015-06-29 12:25:16 -0700
commit637b4eedad84dcff1769454137a64ac70c7f2397 (patch)
treea021502f4b7e65bf252fb22e721c2cb529c7f54c /sql/core/src
parent94e040d05996111b2b448bcdee1cda184c6d039b (diff)
downloadspark-637b4eedad84dcff1769454137a64ac70c7f2397.tar.gz
spark-637b4eedad84dcff1769454137a64ac70c7f2397.tar.bz2
spark-637b4eedad84dcff1769454137a64ac70c7f2397.zip
[SPARK-8214] [SQL] Add function hex
cc chenghao-intel adrian-wang Author: zhichao.li <zhichao.li@intel.com> Closes #6976 from zhichao-li/hex and squashes the following commits: e218d1b [zhichao.li] turn off scalastyle for non-ascii de3f5ea [zhichao.li] non-ascii char cf9c936 [zhichao.li] give separated buffer for each hex method 967ec90 [zhichao.li] Make 'value' as a feild of Hex 3b2fa13 [zhichao.li] tiny fix a647641 [zhichao.li] remove duplicate null check 7cab020 [zhichao.li] tiny refactoring 35ecfe5 [zhichao.li] add function hex
Diffstat (limited to 'sql/core/src')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/functions.scala16
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala13
2 files changed, 29 insertions, 0 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
index ef92801548..5422e066af 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
@@ -1047,6 +1047,22 @@ object functions {
def floor(columnName: String): Column = floor(Column(columnName))
/**
+ * Computes hex value of the given column
+ *
+ * @group math_funcs
+ * @since 1.5.0
+ */
+ def hex(column: Column): Column = Hex(column.expr)
+
+ /**
+ * Computes hex value of the given input
+ *
+ * @group math_funcs
+ * @since 1.5.0
+ */
+ def hex(colName: String): Column = hex(Column(colName))
+
+ /**
* Computes `sqrt(a^2^ + b^2^)` without intermediate overflow or underflow.
*
* @group math_funcs
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala
index 2768d7dfc8..d6331aa4ff 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala
@@ -212,6 +212,19 @@ class MathExpressionsSuite extends QueryTest {
)
}
+ test("hex") {
+ val data = Seq((28, -28, 100800200404L, "hello")).toDF("a", "b", "c", "d")
+ checkAnswer(data.select(hex('a)), Seq(Row("1C")))
+ checkAnswer(data.select(hex('b)), Seq(Row("FFFFFFFFFFFFFFE4")))
+ checkAnswer(data.select(hex('c)), Seq(Row("177828FED4")))
+ checkAnswer(data.select(hex('d)), Seq(Row("68656C6C6F")))
+ checkAnswer(data.selectExpr("hex(a)"), Seq(Row("1C")))
+ checkAnswer(data.selectExpr("hex(b)"), Seq(Row("FFFFFFFFFFFFFFE4")))
+ checkAnswer(data.selectExpr("hex(c)"), Seq(Row("177828FED4")))
+ checkAnswer(data.selectExpr("hex(d)"), Seq(Row("68656C6C6F")))
+ checkAnswer(data.selectExpr("hex(cast(d as binary))"), Seq(Row("68656C6C6F")))
+ }
+
test("hypot") {
testTwoToOneMathFunction(hypot, hypot, math.hypot)
}