Skip to content

feat: support nullary aggregate UDFs#23038

Open
ametel01 wants to merge 12 commits into
apache:mainfrom
ametel01:issue-16453-nullary-udaf
Open

feat: support nullary aggregate UDFs#23038
ametel01 wants to merge 12 commits into
apache:mainfrom
ametel01:issue-16453-nullary-udaf

Conversation

@ametel01

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

This partially addresses #16453 by supporting the window_start() / window_end() style zero-argument aggregate UDF workaround discussed in the issue thread. It does not implement projection of non-table virtual columns such as SELECT window_start, window_end, ....

Rationale for this change

DataFusion already rewrites SQL count() / count(*) to a physical count over COUNT_STAR_EXPANSION, but user-defined aggregate functions with explicit nullary signatures could not reliably flow through planning and physical execution. This blocked using aggregate metadata functions that naturally take no input arguments.

What changes are included in this PR?

  • Allow physical aggregate expressions with empty argument lists when the UDAF signature supports TypeSignature::Nullary.
  • Keep direct empty physical count construction rejected, so callers must use the existing COUNT_STAR_EXPANSION representation for count(*).
  • Support nullary UDAFs through no-group, grouped, filtered, and adapter-backed aggregate execution paths.
  • Disable row-to-state conversion for adapter-backed nullary aggregates because there is no value array to provide input row cardinality.

Are these changes tested?

Yes. Added coverage for:

  • SQL planning of a nullary aggregate UDF.
  • No-group execution of a nullary aggregate UDF.
  • No-group nullary aggregate UDF with a filter that removes all rows.
  • Grouped execution of a nullary aggregate UDF.
  • Direct physical empty-argument count construction returning a planning error.

Local checks run:

  • cargo fmt --all -- --check
  • cargo test -p datafusion-functions-aggregate-common groups_accumulator
  • cargo test -p datafusion --test user_defined_integration test_zero_argument_udaf
  • cargo test -p datafusion-physical-plan count_requires_physical_argument
  • cargo test -p datafusion-sql --test sql_integration plan_zero_argument_aggregate_udf
  • cargo clippy --all-targets --all-features -- -D warnings

Are there any user-facing changes?

Yes. DataFusion can now plan and execute aggregate UDFs declared with Signature::nullary(...), including grouped and filtered aggregate queries.

@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates core Core DataFusion crate functions Changes to functions implementation physical-plan Changes to the physical-plan crate labels Jun 19, 2026
@github-actions github-actions Bot added the common Related to common crate label Jun 19, 2026
@ametel01 ametel01 marked this pull request as ready for review June 19, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant