docs: show struct-returning aggregate window metadata pattern#23248
Open
ametel01 wants to merge 9 commits into
Open
docs: show struct-returning aggregate window metadata pattern#23248ametel01 wants to merge 9 commits into
ametel01 wants to merge 9 commits into
Conversation
Contributor
Author
alamb
approved these changes
Jun 30, 2026
17bba51 to
e928e25
Compare
Contributor
Author
|
Thanks again for the suggestions. I updated the example to use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Issue #16453 asks how an extension can expose window metadata such as
window_start,window_end, andwindow_durationwhen grouping with a custom window assignment function.The earlier nullary aggregate UDF direction in #23038 turned out to be the wrong abstraction: generic aggregate accumulators need real input arrays for row context and normal multi-stage aggregate execution. In the issue and PR discussion, @alamb suggested modeling this as a selector-style aggregate that receives real input columns and returns a struct containing both the metadata and aggregate result.
What changes are included in this PR?
This PR documents and tests that struct-returning aggregate pattern:
augmented_avg(time, value)aggregate returning a struct withwindow_start,window_end,window_duration, andavg_value.augmented_avg(time, value)['window_start'].session_window(time, INTERVAL ...)grouping UDF to demonstrate how an extension can assign rows to windows while the aggregate derives metadata from real input columns.datafusion-examplesUDF example for the same pattern.This intentionally does not add nullary aggregate UDF support and does not add first-class planner support for bare virtual columns such as
SELECT window_start.Are these changes tested?
Yes. I ran:
cargo run --example udf -- struct_udafci/scripts/check_examples_docs.shcargo test -p datafusion --test user_defined_integration test_augmented_avgcargo fmt --all -- --checkci/scripts/doc_prettier_check.shgit diff --checkcargo clippy --all-targets --all-features -- -D warnings./dev/rust_lint.shAre there any user-facing changes?
Yes. This adds documentation and an example for aggregate UDF authors. There are no public API changes.