Add PostgreSQL-style named arguments support for scalar functions #18019
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #17379.
Rationale for this change
PostgreSQL supports named arguments for function calls using the syntax
function_name(param => value)
, which improves code readability and allows arguments to be specified in any order. DataFusion should support this syntax to enhance the user experience, especially for functions with many optional parameters.What changes are included in this PR?
This PR implements PostgreSQL-style named arguments for scalar functions.
Features:
Limitations:
concat
) cannot use named arguments as they accept variable numbers of argumentsExact
,Uniform
,Any
,Coercible
,Comparable
,Numeric
,String
,Nullary
,ArraySignature
, andOneOf
(combinations of these)Variadic
,VariadicAny
,UserDefined
Implementation:
Example usage:
Improved error messages:
Before this PR, error messages showed generic types:
After this PR, error messages show parameter names:
Example error output:
Are these changes tested?
Yes, comprehensive tests are included:
Unit tests (18 tests total):
udf.rs
)utils.rs
)signature.rs
)Integration tests (
named_arguments.slt
):All tests pass successfully.
Are there any user-facing changes?
Yes, this PR adds new user-facing functionality:
param => value
syntax (only for functions with fixed arity)Potential breaking change (very unlikely): Added new public field
parameter_names: Option<Vec<String>>
toSignature
struct. This is technically a breaking change if code constructsSignature
using struct literal syntax. However, this is extremely unlikely in practice because:Signature
is almost always constructed using builder methods (Signature::exact()
,Signature::uniform()
, etc.)None
, maintaining existing behaviorNo other breaking changes: The feature is purely additive - existing SQL queries and UDF implementations work without modification.