dtenedor commented on code in PR #42422:
URL: https://github.com/apache/spark/pull/42422#discussion_r1290457804
##########
python/pyspark/sql/tests/test_udtf.py:
##########
@@ -1795,6 +1796,65 @@ def terminate(self):
assertSchemaEqual(df.schema, StructType().add("col1",
IntegerType()))
assertDataFrameEqual(df, [Row(col1=10), Row(col1=100)])
+ def test_udtf_with_named_arguments(self):
+ @udtf(returnType="a: int")
+ class TestUDTF:
+ def eval(self, a, b):
+ yield a,
+
+ self.spark.udtf.register("test_udtf", TestUDTF)
+
+ for i, df in enumerate(
+ [
+ self.spark.sql("SELECT * FROM test_udtf(a=>10, b=>'x')"),
+ self.spark.sql("SELECT * FROM test_udtf(b=>'x', a=>10)"),
+ ]
+ ):
+ with self.subTest(query_no=i):
+ assertDataFrameEqual(df, [Row(a=10)])
+
+ def test_udtf_with_kwargs(self):
+ @udtf(returnType="a: int, b: string")
+ class TestUDTF:
+ def eval(self, **kwargs):
+ yield kwargs["a"], kwargs["b"]
+
+ self.spark.udtf.register("test_udtf", TestUDTF)
+
+ for i, df in enumerate(
+ [
+ self.spark.sql("SELECT * FROM test_udtf(a=>10, b=>'x')"),
+ self.spark.sql("SELECT * FROM test_udtf(b=>'x', a=>10)"),
Review Comment:
Yeah I believe @learningchess2003 added these checks in [1]. They are
currently in the `FunctionBuilderBase.scala` file in [2]. If we want to reuse
those checks, we could be consistent between error messages for Python UDTFs
and other Spark functions.
[1] https://github.com/apache/spark/pull/42020
[2]
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/FunctionBuilderBase.scala#L107-L128
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]