Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions datafusion/physical-expr/src/window/window_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@ pub struct WindowState {
pub state: WindowAggState,
pub window_fn: WindowFn,
}

impl WindowState {
/// `Accumulator::state()` if this window function is an aggregate, `None`
/// otherwise (built-in functions like `row_number`, `rank`, `lead`/`lag`
/// have no serializable accumulator state).
pub fn aggregate_state(&mut self) -> Result<Option<Vec<ScalarValue>>> {
match &mut self.window_fn {
WindowFn::Aggregate(accumulator) => accumulator.state().map(Some),
WindowFn::Builtin(_) => Ok(None),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused about what BuiltIn was -- it turns out I think it is just a normal window function (the name probably dates to the time when we had built in and user defined window functions)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed a PR to improve the docs

}
}
}

pub type PartitionWindowAggStates = IndexMap<PartitionKey, WindowState, RandomState>;

/// The IndexMap (i.e. an ordered HashMap) where record batches are separated for each partition.
Expand Down
Loading
Loading