aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavies Liu <davies@databricks.com>2015-07-06 13:31:31 -0700
committerReynold Xin <rxin@databricks.com>2015-07-06 13:31:31 -0700
commit37e4d92142a6309e2df7d36883e0c7892c3d792d (patch)
tree20a23e5a565ebe20919cb20be03e9335d4088dc8 /python
parent57c72fcce75907c08a1ae53a0d85447176fc3c69 (diff)
downloadspark-37e4d92142a6309e2df7d36883e0c7892c3d792d.tar.gz
spark-37e4d92142a6309e2df7d36883e0c7892c3d792d.tar.bz2
spark-37e4d92142a6309e2df7d36883e0c7892c3d792d.zip
[SPARK-8784] [SQL] Add Python API for hex and unhex
Add Python API for hex/unhex, also cleanup Hex/Unhex Author: Davies Liu <davies@databricks.com> Closes #7223 from davies/hex and squashes the following commits: 6f1249d [Davies Liu] no explicit rule to cast string into binary 711a6ed [Davies Liu] fix test f9fe5a3 [Davies Liu] Merge branch 'master' of github.com:apache/spark into hex f032fbb [Davies Liu] Merge branch 'hex' of github.com:davies/spark into hex 49e325f [Davies Liu] Merge branch 'master' of github.com:apache/spark into hex b31fc9a [Davies Liu] Update math.scala 25156b7 [Davies Liu] address comments and fix test c3af78c [Davies Liu] address commments 1a24082 [Davies Liu] Add Python API for hex and unhex
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/sql/functions.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py
index 49dd0332af..dca39fa833 100644
--- a/python/pyspark/sql/functions.py
+++ b/python/pyspark/sql/functions.py
@@ -397,6 +397,34 @@ def randn(seed=None):
@ignore_unicode_prefix
@since(1.5)
+def hex(col):
+ """Computes hex value of the given column, which could be StringType,
+ BinaryType, IntegerType or LongType.
+
+ >>> sqlContext.createDataFrame([('ABC', 3)], ['a', 'b']).select(hex('a'), hex('b')).collect()
+ [Row(hex(a)=u'414243', hex(b)=u'3')]
+ """
+ sc = SparkContext._active_spark_context
+ jc = sc._jvm.functions.hex(_to_java_column(col))
+ return Column(jc)
+
+
+@ignore_unicode_prefix
+@since(1.5)
+def unhex(col):
+ """Inverse of hex. Interprets each pair of characters as a hexadecimal number
+ and converts to the byte representation of number.
+
+ >>> sqlContext.createDataFrame([('414243',)], ['a']).select(unhex('a')).collect()
+ [Row(unhex(a)=bytearray(b'ABC'))]
+ """
+ sc = SparkContext._active_spark_context
+ jc = sc._jvm.functions.unhex(_to_java_column(col))
+ return Column(jc)
+
+
+@ignore_unicode_prefix
+@since(1.5)
def sha1(col):
"""Returns the hex string result of SHA-1.