You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c857382
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Align scalar UDF literal args with coerced return fields (apache#23232)
## Which issue does this PR close?
- Closesapache#19982.
## Rationale for this change
`ReturnFieldArgs` exposes both coerced `arg_fields` and optional scalar
literal arguments. A coercible UDF could receive an `Int16` field but an
original `Int64` literal, or lose the literal behind an implicit cast.
That makes return-field decisions inconsistent and forced UDF
implementations to compensate for planner internals.
## What changes are included in this PR?
- Materialize successful implicit casts of scalar-function literals
during type coercion, so literal values and `arg_fields` always have the
same type.
- Keep user-written `Cast` and `TryCast` expressions as expressions
rather than reporting them as literals.
- Preserve execution-time errors for invalid literal casts.
- Simplify return-field scalar extraction to accept only genuine
post-coercion literals.
- Update `round` to use the strengthened contract and document it on
`ReturnFieldArgs`.
- Add unit and integration regressions for coerced integers, typed
nulls, list literals, invalid values, explicit casts, expression
arguments, and `arrow_cast`'s required literal type argument.
This follows the approach discussed in apache#20012: materialize implicit
literal coercion in the type-coercion pass without changing
explicit-cast semantics.
## Are these changes tested?
- `cargo fmt --all --check`
- `cargo test -p datafusion --test user_defined_integration
test_return_field_args_scalar_argument_types_match_arg_fields` (1
passed)
- `cargo test -p datafusion --test core_integration
test_fn_arrow_cast_requires_literal_type_arg` (1 passed)
- `cargo test -p datafusion-expr scalar_arguments_` (2 passed)
- `cargo clippy --all-targets --all-features -- -D warnings`
- `git diff --check`
The validation process caught and fixed two semantic regressions before
push: explicit casts being folded into scalar literals, and `arrow_cast`
reporting its existing error during planning rather than collection.
## AI assistance
AI tooling assisted with implementation and test iteration. I reviewed
the final diff, the related apache#20012 design discussion, and the
scalar-function coercion/return-field flow end to end, and ran the
validations listed above.
---------
Signed-off-by: Kevin-Li-2025 <[email protected]>
Signed-off-by: Kevin-Li-2025 <[email protected]>
Co-authored-by: Kevin-Li-2025 <[email protected]>
Co-authored-by: Jeffrey Vo <[email protected]>
0 commit comments