aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/sql/functions.py
diff options
context:
space:
mode:
authorTarek Auel <tarek.auel@googlemail.com>2015-07-02 10:02:19 -0700
committerDavies Liu <davies@databricks.com>2015-07-02 10:02:19 -0700
commit5b3338130dfd9db92c4894a348839a62ebb57ef3 (patch)
tree13b6289381caca923444107940da2ed5abba7628 /python/pyspark/sql/functions.py
parent0a468a46bf5b905e9b0205e98b862570b2ac556e (diff)
downloadspark-5b3338130dfd9db92c4894a348839a62ebb57ef3.tar.gz
spark-5b3338130dfd9db92c4894a348839a62ebb57ef3.tar.bz2
spark-5b3338130dfd9db92c4894a348839a62ebb57ef3.zip
[SPARK-8223] [SPARK-8224] [SQL] shift left and shift right
Jira: https://issues.apache.org/jira/browse/SPARK-8223 https://issues.apache.org/jira/browse/SPARK-8224 ~~I am aware of #7174 and will update this pr, if it's merged.~~ Done I don't know if #7034 can simplify this, but we can have a look on it, if it gets merged rxin In the Jira ticket the function as no second argument. I added a `numBits` argument that allows to specify the number of bits. I guess this improves the usability. I wanted to add `shiftleft(value)` as well, but the `selectExpr` dataframe tests crashes, if I have both. I order to do this, I added the following to the functions.scala `def shiftRight(e: Column): Column = ShiftRight(e.expr, lit(1).expr)`, but as I mentioned this doesn't pass tests like `df.selectExpr("shiftRight(a)", ...` (not enough arguments exception). If we need the bitwise shift in order to be hive compatible, I suggest to add `shiftLeft` and something like `shiftLeftX` Author: Tarek Auel <tarek.auel@googlemail.com> Closes #7178 from tarekauel/8223 and squashes the following commits: 8023bb5 [Tarek Auel] [SPARK-8223][SPARK-8224] fixed test f3f64e6 [Tarek Auel] [SPARK-8223][SPARK-8224] Integer -> Int f628706 [Tarek Auel] [SPARK-8223][SPARK-8224] removed toString; updated function description 3b56f2a [Tarek Auel] Merge remote-tracking branch 'origin/master' into 8223 5189690 [Tarek Auel] [SPARK-8223][SPARK-8224] minor fix and style fix 9434a28 [Tarek Auel] Merge remote-tracking branch 'origin/master' into 8223 44ee324 [Tarek Auel] [SPARK-8223][SPARK-8224] docu fix ac7fe9d [Tarek Auel] [SPARK-8223][SPARK-8224] right and left bit shift
Diffstat (limited to 'python/pyspark/sql/functions.py')
-rw-r--r--python/pyspark/sql/functions.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py
index f9a15d4a66..bccde6083c 100644
--- a/python/pyspark/sql/functions.py
+++ b/python/pyspark/sql/functions.py
@@ -412,6 +412,30 @@ def sha2(col, numBits):
return Column(jc)
+@since(1.5)
+def shiftLeft(col, numBits):
+ """Shift the the given value numBits left.
+
+ >>> sqlContext.createDataFrame([(21,)], ['a']).select(shiftLeft('a', 1).alias('r')).collect()
+ [Row(r=42)]
+ """
+ sc = SparkContext._active_spark_context
+ jc = sc._jvm.functions.shiftLeft(_to_java_column(col), numBits)
+ return Column(jc)
+
+
+@since(1.5)
+def shiftRight(col, numBits):
+ """Shift the the given value numBits right.
+
+ >>> sqlContext.createDataFrame([(42,)], ['a']).select(shiftRight('a', 1).alias('r')).collect()
+ [Row(r=21)]
+ """
+ sc = SparkContext._active_spark_context
+ jc = sc._jvm.functions.shiftRight(_to_java_column(col), numBits)
+ return Column(jc)
+
+
@since(1.4)
def sparkPartitionId():
"""A column for partition ID of the Spark task.