ueshin commented on code in PR #42422:
URL: https://github.com/apache/spark/pull/42422#discussion_r1291753341
##########
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:
Updated to raise the following errors:
> 1. duplicated input argument names: a => 10, a => 10
It will be checked in the analysis phase and an error with the error class
`DUPLICATE_ROUTINE_PARAMETER_ASSIGNMENT.DOUBLE_NAMED_ARGUMENT_REFERENCE` will
be raised.
> 2. non-existing argument name: c => 10
It will be handled in Python runtime and an error will be raised.
```
...PySparkRuntimeError: [UDTF_EXEC_ERROR] User defined table function
encountered an error in the 'eval' method: eval() got an unexpected keyword
argument 'c'
```
> 3. incorrect combination of positional and named arguments: test_udtf(a =>
10, 'x')
It will be checked in the analysis phase and an error with the error class
`UNEXPECTED_POSITIONAL_ARGUMENT` will be raised.
--
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]