Skip to content

feat: add coerce_arguments flag to UDTFs to allow skipping automatic …#20376

Open
evangelisilva wants to merge 3 commits intoapache:mainfrom
evangelisilva:fix/20293-udtf-arg-coercion
Open

feat: add coerce_arguments flag to UDTFs to allow skipping automatic …#20376
evangelisilva wants to merge 3 commits intoapache:mainfrom
evangelisilva:fix/20293-udtf-arg-coercion

Conversation

@evangelisilva
Copy link
Contributor

@evangelisilva evangelisilva commented Feb 15, 2026

UDTF Argument Coercion Suppression

Which issue does this PR close?

Closes #20293.

Rationale for this change

Currently, User-Defined Table Functions (UDTFs) in DataFusion automatically undergo argument coercion and simplification before being passed to the function creator. This process happens against an empty schema (DFSchema::empty()).

If a UDTF uses arguments that contain identifiers (e.g., scan_with(index=['a', 'b'])), the simplifier fails with a Schema error: No field named index because it attempts to resolve index as a column reference. This prevents UDTFs from implementing custom argument parsing logic that relies on identifiers or complex expressions.

What changes are included in this PR?

  1. Modified TableFunctionImpl trait: Added a new method coerce_arguments(&self) -> bool that defaults to true. This allows UDTF authors to opt-out of automatic coercion.
  2. Updated TableFunction struct: Exposed coerce_arguments on the wrapper struct.
  3. Updated SessionContextProvider: Modified the SQL planner integration in session_state.rs to check the coerce_arguments flag. If false, the raw Expr arguments are passed directly to the UDTF creator without modification.
  4. Unit Tests: Added comprehensive tests in session_state.rs to verify both the default behavior (automatic coercion/failure on identifiers) and the new suppressed behavior (allowing identifiers).

Are these changes tested?

Yes. I've added a new test module udtf_tests in datafusion/core/src/execution/session_state.rs containing:

  • test_udtf_no_coercion: Verifies that identifiers survive when coercion is disabled.
  • test_udtf_default_coercion: Verifies that the existing behavior (failing on identifiers) is preserved by default to ensure no regressions.

Are there any user-facing changes?

Yes. There is a new method on the TableFunctionImpl trait. However, because it has a default implementation that returns true, it is backward compatible and will not break existing UDTF implementations. UDTF authors who need the new behavior simply need to override this method.

cc: @askalt @alamb

…coercion

This allows UDTFs to handle complex arguments (like identifiers) that would otherwise
fail planning when coerced against an empty schema.

Fixes apache#20293
@github-actions github-actions bot added core Core DataFusion crate catalog Related to the catalog crate labels Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

catalog Related to the catalog crate core Core DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UDTF arguments preserving

1 participant