Skip to content

Align scalar UDF literal args with coerced return fields#23232

Open
Kevin-Li-2025 wants to merge 1 commit into
apache:mainfrom
Kevin-Li-2025:kevin/return-field-scalar-arg-types
Open

Align scalar UDF literal args with coerced return fields#23232
Kevin-Li-2025 wants to merge 1 commit into
apache:mainfrom
Kevin-Li-2025:kevin/return-field-scalar-arg-types

Conversation

@Kevin-Li-2025

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ReturnFieldArgs exposes both coerced arg_fields and optional scalar literal arguments to scalar UDFs. For coerced literal calls such as test_udf(1) where the UDF signature coerces the argument to Int16, the field metadata is Int16 but the scalar argument was not aligned with that field. On current main, the coerced expression can also appear as Cast(Literal), causing scalar_arguments to be None even though the argument is still a literal.

What changes are included in this PR?

  • Build scalar UDF ReturnFieldArgs.scalar_arguments from literals after aligning them to the verified/coerced argument fields.
  • Recognize literals wrapped in Cast / TryCast so coerced constants are still reported as scalar arguments.
  • Add a regression test that asserts arg_fields[0].data_type() matches the scalar argument data type for a coercible scalar UDF.

Are these changes tested?

  • cargo fmt --all --check
  • CARGO_HOME=/Users/yinxiaogou/Documents/github/.cargo-home CARGO_TARGET_DIR=/Users/yinxiaogou/Documents/github/datafusion-target cargo test -p datafusion --test user_defined_integration user_defined::user_defined_scalar_functions::test_return_field_args_scalar_argument_types_match_arg_fields -- --exact

I also ran cargo test -p datafusion --test user_defined_integration user_defined::user_defined_scalar_functions; the new test and 22 other tests passed, while 3 existing tests failed locally because ARROW_TEST_DATA / PARQUET_TEST_DATA submodule data was unavailable in this checkout.

Signed-off-by: Kevin-Li-2025 <2242139@qq.com>
@github-actions github-actions Bot added logical-expr Logical plan and expressions core Core DataFusion crate labels Jun 29, 2026
@Kevin-Li-2025 Kevin-Li-2025 marked this pull request as ready for review June 29, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReturnFieldArgs.scalar_arguments type doesn't match with arg_fields

1 participant