aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/sql/functions.py10
-rw-r--r--python/pyspark/sql/tests.py7
2 files changed, 17 insertions, 0 deletions
diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py
index 719e623a1a..d930f7db25 100644
--- a/python/pyspark/sql/functions.py
+++ b/python/pyspark/sql/functions.py
@@ -541,6 +541,16 @@ def sparkPartitionId():
return Column(sc._jvm.functions.sparkPartitionId())
+def expr(str):
+ """Parses the expression string into the column that it represents
+
+ >>> df.select(expr("length(name)")).collect()
+ [Row('length(name)=5), Row('length(name)=3)]
+ """
+ sc = SparkContext._active_spark_context
+ return Column(sc._jvm.functions.expr(str))
+
+
@ignore_unicode_prefix
@since(1.5)
def length(col):
diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py
index ea821f486f..5aa6135dc1 100644
--- a/python/pyspark/sql/tests.py
+++ b/python/pyspark/sql/tests.py
@@ -846,6 +846,13 @@ class SQLTests(ReusedPySparkTestCase):
result = df.select(functions.bitwiseNOT(df.b)).collect()[0].asDict()
self.assertEqual(~75, result['~b'])
+ def test_expr(self):
+ from pyspark.sql import functions
+ row = Row(a="length string", b=75)
+ df = self.sqlCtx.createDataFrame([row])
+ result = df.select(functions.expr("length(a)")).collect()[0].asDict()
+ self.assertEqual(13, result["'length(a)"])
+
def test_replace(self):
schema = StructType([
StructField("name", StringType(), True),