feat(physical-plan): expose finalized Accumulator state on BoundedWindowAggExec - #24031
Draft
avantgardnerio wants to merge 1 commit into
Draft
feat(physical-plan): expose finalized Accumulator state on BoundedWindowAggExec#24031avantgardnerio wants to merge 1 commit into
avantgardnerio wants to merge 1 commit into
Conversation
…dowAggExec Per-output-partition slots hold each aggregate window function's final Accumulator::state() at partition-close, plus a getter that operators can call once a task has drained. Intended to support prefix scans over ordered window aggregates. The stream snapshots state at the top of prune_state — the last moment state.is_end entries are live before either prune_out_columns or prune_partition_batches drops them — so both mid-stream partition close (as SQL PARTITION BY groups end) and EOS are covered by one write site. Non-aggregate window functions (row_number, rank, lead/lag, ...) occupy None at their slot. Storage is Arc<[OnceLock<Vec<Option<Vec<ScalarValue>>>>]> — one slot per output partition, first-close-wins. The getter is scoped to the at-most-one-PARTITION-BY-group case; additional groups are silently dropped rather than merged (no well-defined semantics for combining). No trait changes: uses the existing Accumulator::state() surface already relied on by the group-by Partial/Final protocol, exposed through a new method on the already-public WindowState so no internal enum leaks into the public API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Adds per-output-partition slots on
BoundedWindowAggExecthat capture each aggregate window function's finalAccumulator::state()at partition-close, plus a getter (finalized_partition_state) for downstream operators to read once a task has drained. Intended to support prefix scans over ordered window aggregates.Slim re-do of #24007 addressing the review there. Public surface is a single new
pub fnon BWAG plus one method on the already-publicWindowState; no new pub types or re-exports.What changed vs. #24007
pub use window_expr::WindowFnleaked internal enum withBox<dyn Accumulator>/Box<dyn PartitionEvaluator>variantsWindowState::aggregate_state() -> Result<Option<Vec<ScalarValue>>>on the already-public type.pub type FinalizedPartitionStatealiastype_complexity.Empty/Single/Multistate machine + out-of-range error + mutex-poison errorOption<&[Option<Vec<ScalarValue>>]>.Arc<[Mutex<FinalStateSlot>]>Arc<[OnceLock<Vec<Option<Vec<ScalarValue>>>>]>— no Mutex, no state machine, first-close-wins.Diff: 429 → 168 lines.
Test plan
cargo test -p datafusion-physical-plan --lib windows::bounded_window_agg_exec::tests::finalized_partition_state_returns_single_group_statecargo test -p datafusion-physical-plan --lib windows(11 passed)cargo clippy -p datafusion-physical-plan -p datafusion-physical-expr --all-targets(clean)cargo fmt --all --check