ueshin opened a new pull request, #42617:
URL: https://github.com/apache/spark/pull/42617

   ### What changes were proposed in this pull request?
   
   Supports named arguments in scalar Python/Pandas UDF.
   
   For example:
   
   ```py
   >>> @udf("int")
   ... def test_udf(a, b):
   ...     return a + 10 * b
   ...
   >>> spark.udf.register("test_udf", test_udf)
   
   >>> spark.range(2).select(test_udf(b=col("id") * 10, a=col("id"))).show()
   +---------------------------------+
   |test_udf(b => (id * 10), a => id)|
   +---------------------------------+
   |                                0|
   |                              101|
   +---------------------------------+
   
   >>> spark.sql("SELECT test_udf(b => id * 10, a => id) FROM range(2)").show()
   +---------------------------------+
   |test_udf(b => (id * 10), a => id)|
   +---------------------------------+
   |                                0|
   |                              101|
   +---------------------------------+
   ```
   
   or:
   
   ```py
   >>> @pandas_udf("int")
   ... def test_udf(a, b):
   ...     return a + 10 * b
   ...
   >>> spark.udf.register("test_udf", test_udf)
   
   >>> spark.range(2).select(test_udf(b=col("id") * 10, a=col("id"))).show()
   +---------------------------------+
   |test_udf(b => (id * 10), a => id)|
   +---------------------------------+
   |                                0|
   |                              101|
   +---------------------------------+
   
   >>> spark.sql("SELECT test_udf(b => id * 10, a => id) FROM range(2)").show()
   +---------------------------------+
   |test_udf(b => (id * 10), a => id)|
   +---------------------------------+
   |                                0|
   |                              101|
   +---------------------------------+
   ```
   
   ### Why are the changes needed?
   
   Now that named arguments support was added 
(https://github.com/apache/spark/pull/41796, 
https://github.com/apache/spark/pull/42020).
   
   Scalar Python/Pandas UDFs can support it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, named arguments will be available for scalar Python/Pandas UDFs.
   
   ### How was this patch tested?
   
   Added related tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.


-- 
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]

Reply via email to