aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavies Liu <davies.liu@gmail.com>2016-06-20 20:50:30 -0700
committerDavies Liu <davies.liu@gmail.com>2016-06-20 20:53:45 -0700
commita46553cbacf0e4012df89fe55385dec5beaa680a (patch)
treebd5dd15504006d5580f3dcb7d9aaa859ca6eb685 /python
parente2b7eba87cdf67fa737c32f5f6ca075445ff28cb (diff)
downloadspark-a46553cbacf0e4012df89fe55385dec5beaa680a.tar.gz
spark-a46553cbacf0e4012df89fe55385dec5beaa680a.tar.bz2
spark-a46553cbacf0e4012df89fe55385dec5beaa680a.zip
[SPARK-16086] [SQL] fix Python UDF without arguments (for 1.6)
Fix the bug for Python UDF that does not have any arguments. Added regression tests. Author: Davies Liu <davies.liu@gmail.com> Closes #13793 from davies/fix_no_arguments. (cherry picked from commit abe36c53d126bb580e408a45245fd8e81806869c) Signed-off-by: Davies Liu <davies.liu@gmail.com>
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/sql/tests.py5
-rw-r--r--python/pyspark/sql/types.py9
2 files changed, 8 insertions, 6 deletions
diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py
index c631ad8a46..ecd1a0563e 100644
--- a/python/pyspark/sql/tests.py
+++ b/python/pyspark/sql/tests.py
@@ -318,6 +318,11 @@ class SQLTests(ReusedPySparkTestCase):
[row] = self.spark.sql("SELECT double(add(1, 2)), add(double(2), 1)").collect()
self.assertEqual(tuple(row), (6, 5))
+ def test_udf_without_arguments(self):
+ self.sqlCtx.registerFunction("foo", lambda: "bar")
+ [row] = self.sqlCtx.sql("SELECT foo()").collect()
+ self.assertEqual(row[0], "bar")
+
def test_udf_with_array_type(self):
d = [Row(l=list(range(3)), d={"key": list(range(5))})]
rdd = self.sc.parallelize(d)
diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py
index bb2b95404a..f0b56be8da 100644
--- a/python/pyspark/sql/types.py
+++ b/python/pyspark/sql/types.py
@@ -1401,11 +1401,7 @@ class Row(tuple):
if args and kwargs:
raise ValueError("Can not use both args "
"and kwargs to create Row")
- if args:
- # create row class or objects
- return tuple.__new__(self, args)
-
- elif kwargs:
+ if kwargs:
# create row objects
names = sorted(kwargs.keys())
row = tuple.__new__(self, [kwargs[n] for n in names])
@@ -1413,7 +1409,8 @@ class Row(tuple):
return row
else:
- raise ValueError("No args or kwargs")
+ # create row class or objects
+ return tuple.__new__(self, args)
def asDict(self, recursive=False):
"""