mustafasrepo commented on code in PR #4777:
URL: https://github.com/apache/arrow-datafusion/pull/4777#discussion_r1061231290
##########
datafusion/physical-expr/src/window/built_in.rs:
##########
@@ -122,6 +127,102 @@ impl WindowExpr for BuiltInWindowExpr {
}
}
+ /// Evaluate the window function against the batch. This function
facilitates
+ /// stateful, bounded-memory implementations.
+ fn evaluate_stateful(
+ &self,
+ partition_batches: &PartitionBatches,
+ window_agg_state: &mut PartitionWindowAggStates,
+ ) -> Result<()> {
+ let field = self.expr.field()?;
+ let out_type = field.data_type();
+ let sort_options = self.order_by.iter().map(|o|
o.options).collect::<Vec<_>>();
+ for (partition_row, partition_batch_state) in partition_batches.iter()
{
+ if !window_agg_state.contains_key(partition_row) {
+ let evaluator = self.expr.create_evaluator()?;
+ window_agg_state.insert(
+ partition_row.clone(),
+ WindowState {
+ state: WindowAggState::new(
+ out_type,
+ WindowFunctionState::BuiltinWindowState(
+ BuiltinWindowState::Default,
+ ),
+ )?,
+ window_fn: WindowFn::Builtin(evaluator),
+ },
+ );
+ };
+ let window_state =
+ window_agg_state.get_mut(partition_row).ok_or_else(|| {
+ DataFusionError::Execution("Cannot find state".to_string())
+ })?;
+ let evaluator = match &mut window_state.window_fn {
+ WindowFn::Builtin(evaluator) => evaluator,
+ _ => unreachable!(),
Review Comment:
`sum` and `count` should have the type `WindowFn::Aggregate`. However, they
are handled under `SlidingAggregateWindowExpr`. If we are inside
`BuiltInWindowExpr` state should be `WindowFn::Builtin`. Similarly, if we are
inside `SlidingAggregateWindowExpr` window function state should be
`WindowFn::Aggregate`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]