dongjoon-hyun opened a new pull request, #60768:
URL: https://github.com/apache/spark/pull/60768
### What changes were proposed in this pull request?
This PR makes the functions registered with `spark.udf.register` reject
named arguments, as the built-in functions and the Python UDFs without named
argument support do.
The builder of such a function passes the arguments of a call as they are.
So for `f(x => 1L)`, the call gets a `NamedArgumentExpression` as its argument,
which is `Unevaluable`, and the query passes analysis and fails during
execution. This PR wraps the builders that the classic `UDFRegistration`
registers, so that a call with a named argument fails with
`NAMED_PARAMETERS_NOT_SUPPORTED`, which `FunctionRegistryBase.build` raises for
a built-in function and `UserDefinedPythonFunction.builder` for a Python UDF.
The wrapped builders are those of:
- Scala and Java UDFs and typed `Aggregator`s, registered through
`register(name, udf, source, validateParameterCount)`.
- `UserDefinedAggregateFunction`s, registered through the deprecated
`register(name, udaf)`.
Spark Connect registers these functions with the same methods
(`SparkConnectPlanner`), so it gets the same error.
### Why are the changes needed?
A call of such a function with a named argument fails with an
INTERNAL_ERROR, instead of a user-facing error.
```scala
scala> spark.udf.register("f1", (x: Long) => x + 1)
scala> spark.sql("SELECT f1(x => 1L)").collect()
org.apache.spark.SparkException: [INTERNAL_ERROR] Cannot generate code for
expression: x => 1 SQLSTATE: XX000
```
### Does this PR introduce _any_ user-facing change?
Yes. Such a call fails during analysis with
`NAMED_PARAMETERS_NOT_SUPPORTED`, instead of failing with `INTERNAL_ERROR`
during execution.
```
[NAMED_PARAMETERS_NOT_SUPPORTED] Named parameters are not supported for
function `f1`; please retry the query with positional arguments to the function
call instead. SQLSTATE: 4274K
```
The builders have not checked named arguments since #41796 (SPARK-43922)
added them in [v3.5.0](https://github.com/apache/spark/releases/tag/v3.5.0)
(2023-09-09). I confirmed the INTERNAL_ERROR above on the released
[v4.0.5](https://github.com/apache/spark/releases/tag/v4.0.5) (2026-10-21),
[v4.1.4](https://github.com/apache/spark/releases/tag/v4.1.4) (2026-10-21),
[v4.2.1](https://github.com/apache/spark/releases/tag/v4.2.1) (2026-10-21) and
[v4.3.0](https://github.com/apache/spark/releases/tag/v4.3.0) (2026-10-27).
### How was this patch tested?
Pass the CIs with the newly added test case, which fails without this PR.
- `UDFSuite`: a call with a named argument fails with
`NAMED_PARAMETERS_NOT_SUPPORTED`, with the query context of the call, for a
Scala function, a `UserDefinedFunction`, a typed `Aggregator` and a
`UserDefinedAggregateFunction` registered with `spark.udf.register`.
I also ran `UDFSuite`, `JavaUDFSuite`, `JavaUDAFSuite`,
`FunctionQualificationSuite` and `named-function-arguments.sql` of
`SQLQueryTestSuite` locally.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]