Skip to content

feat: attach Diagnostic to "invalid function argument types" error#23063

Open
choplin wants to merge 1 commit into
apache:mainfrom
choplin:feat/issue-14431-diagnostic
Open

feat: attach Diagnostic to "invalid function argument types" error#23063
choplin wants to merge 1 commit into
apache:mainfrom
choplin:feat/issue-14431-diagnostic

Conversation

@choplin

@choplin choplin commented Jun 21, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

When a scalar or aggregate function is called with argument types that don't match any supported signature (e.g. SELECT sum('a')), the error message is a raw text dump with no source location. This PR attaches a Diagnostic so downstream consumers can highlight the offending call site in the original SQL query.

What changes are included in this PR?

  • Add spans: Spans field to ScalarFunction and AggregateFunction so function-call source locations survive planning and optimization.
  • Populate spans from sqlparser in the SQL planner when collect_spans is enabled, following the same pattern used for Column.
  • In verify_function_arguments, attach a Diagnostic with:
    • message: the function name (invalid argument type(s) for 'sum')
    • span: the function call site in the original SQL
    • note: the actual argument types (called with argument type(s): Utf8)
    • help: the candidate signatures (candidate function(s): sum(Decimal), sum(UInt64), ...)
  • Update all pattern matches, tree-node transforms, and serialization code for the new spans field.

Are there any user-facing changes?

No breaking API changes. ScalarFunction and AggregateFunction gain a spans: Spans field, but Spans is ignored in PartialEq / Hash and defaults to empty, so existing code using ScalarFunction::new_udf / AggregateFunction::new_udf is unaffected.

When an error occurs, a diagnositc is attached in the error message.

Before (no Diagnostic attached):

Error during planning: No function matches the given name and argument types 'sum(Utf8)'. You might need to add explicit type casts.
	Candidate functions:
	sum(Decimal)
	sum(UInt64)
	sum(Int64)
	sum(Float64)
	sum(Duration)

After (same error message, with Diagnostic now attached):

Error during planning: No function matches the given name and argument types 'sum(Utf8)'. You might need to add explicit type casts.
	Candidate functions:
	sum(Decimal)
	sum(UInt64)
	sum(Int64)
	sum(Float64)
	sum(Duration)

Diagnostic:
  message: invalid argument type(s) for 'sum'
  span:    1:8 - 1:11
  note:    called with argument type(s): Utf8
  help:    candidate function(s): sum(Decimal), sum(UInt64), sum(Int64), sum(Float64), sum(Duration)

Add span-aware Diagnostic to the error produced by
`verify_function_arguments` when a scalar or aggregate function is
called with argument types that do not match any supported signature.

- Add `spans: Spans` field to `ScalarFunction` and `AggregateFunction`
  so function-call source locations survive planning and optimization.
- Populate spans from sqlparser in the SQL planner when
  `collect_spans` is enabled.
- Pass the function-call span to `Diagnostic::new_error` so
  downstream consumers can highlight the offending call site.
- Update all pattern matches, tree-node transforms, and serialization
  code for the new field.

Closes apache#14431
@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates optimizer Optimizer rules core Core DataFusion crate proto Related to proto crate functions Changes to functions implementation labels Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate functions Changes to functions implementation logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Changes to the physical-expr crates proto Related to proto crate sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attach Diagnostic to "invalid function argument types" error

1 participant