pub trait WindowExpr:
Send
+ Sync
+ Debug {
Show 15 methods
// Required methods
fn as_any(&self) -> &dyn Any;
fn field(&self) -> Result<Field>;
fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>;
fn evaluate(&self, batch: &RecordBatch) -> Result<ArrayRef>;
fn partition_by(&self) -> &[Arc<dyn PhysicalExpr>];
fn order_by(&self) -> LexOrderingRef<'_>;
fn get_window_frame(&self) -> &Arc<WindowFrame>;
fn uses_bounded_memory(&self) -> bool;
fn get_reverse_expr(&self) -> Option<Arc<dyn WindowExpr>>;
// Provided methods
fn name(&self) -> &str { ... }
fn evaluate_args(&self, batch: &RecordBatch) -> Result<Vec<ArrayRef>> { ... }
fn evaluate_stateful(
&self,
_partition_batches: &PartitionBatches,
_window_agg_state: &mut PartitionWindowAggStates,
) -> Result<()> { ... }
fn order_by_columns(&self, batch: &RecordBatch) -> Result<Vec<SortColumn>> { ... }
fn all_expressions(&self) -> WindowPhysicalExpressions { ... }
fn with_new_expressions(
&self,
_args: Vec<Arc<dyn PhysicalExpr>>,
_partition_bys: Vec<Arc<dyn PhysicalExpr>>,
_order_by_exprs: Vec<Arc<dyn PhysicalExpr>>,
) -> Option<Arc<dyn WindowExpr>> { ... }
}
Expand description
Common trait for window function implementations
§Aggregate Window Expressions
These expressions take the form
OVER({ROWS | RANGE| GROUPS} BETWEEN UNBOUNDED PRECEDING AND ...)
For example, cumulative window frames uses PlainAggregateWindowExpr
.
§Non Aggregate Window Expressions
The expressions have the form
OVER({ROWS | RANGE| GROUPS} BETWEEN M {PRECEDING| FOLLOWING} AND ...)
For example, sliding window frames use SlidingAggregateWindowExpr
.
Required Methods§
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the window expression as Any
so that it can be
downcast to a specific implementation.
Sourcefn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>
fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>
Expressions that are passed to the WindowAccumulator.
Functions which take a single input argument, such as sum
, return a single datafusion_expr::expr::Expr
,
others (e.g. cov
) return many.
Sourcefn evaluate(&self, batch: &RecordBatch) -> Result<ArrayRef>
fn evaluate(&self, batch: &RecordBatch) -> Result<ArrayRef>
Evaluate the window function values against the batch
Sourcefn partition_by(&self) -> &[Arc<dyn PhysicalExpr>]
fn partition_by(&self) -> &[Arc<dyn PhysicalExpr>]
Expressions that’s from the window function’s partition by clause, empty if absent
Sourcefn order_by(&self) -> LexOrderingRef<'_>
fn order_by(&self) -> LexOrderingRef<'_>
Expressions that’s from the window function’s order by clause, empty if absent
Sourcefn get_window_frame(&self) -> &Arc<WindowFrame>
fn get_window_frame(&self) -> &Arc<WindowFrame>
Get the window frame of this WindowExpr.
Sourcefn uses_bounded_memory(&self) -> bool
fn uses_bounded_memory(&self) -> bool
Return a flag indicating whether this WindowExpr can run with bounded memory.
Sourcefn get_reverse_expr(&self) -> Option<Arc<dyn WindowExpr>>
fn get_reverse_expr(&self) -> Option<Arc<dyn WindowExpr>>
Get the reverse expression of this WindowExpr.
Provided Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Human readable name such as "MIN(c2)"
or "RANK()"
. The default
implementation returns placeholder text.
Sourcefn evaluate_args(&self, batch: &RecordBatch) -> Result<Vec<ArrayRef>>
fn evaluate_args(&self, batch: &RecordBatch) -> Result<Vec<ArrayRef>>
Evaluate the window function arguments against the batch and return
array ref, normally the resulting Vec
is a single element one.
Sourcefn evaluate_stateful(
&self,
_partition_batches: &PartitionBatches,
_window_agg_state: &mut PartitionWindowAggStates,
) -> Result<()>
fn evaluate_stateful( &self, _partition_batches: &PartitionBatches, _window_agg_state: &mut PartitionWindowAggStates, ) -> Result<()>
Evaluate the window function against the batch. This function facilitates stateful, bounded-memory implementations.
Sourcefn order_by_columns(&self, batch: &RecordBatch) -> Result<Vec<SortColumn>>
fn order_by_columns(&self, batch: &RecordBatch) -> Result<Vec<SortColumn>>
Get order by columns, empty if absent
Sourcefn all_expressions(&self) -> WindowPhysicalExpressions
fn all_expressions(&self) -> WindowPhysicalExpressions
Returns all expressions used in the WindowExpr
.
These expressions are (1) function arguments, (2) partition by expressions, (3) order by expressions.
Sourcefn with_new_expressions(
&self,
_args: Vec<Arc<dyn PhysicalExpr>>,
_partition_bys: Vec<Arc<dyn PhysicalExpr>>,
_order_by_exprs: Vec<Arc<dyn PhysicalExpr>>,
) -> Option<Arc<dyn WindowExpr>>
fn with_new_expressions( &self, _args: Vec<Arc<dyn PhysicalExpr>>, _partition_bys: Vec<Arc<dyn PhysicalExpr>>, _order_by_exprs: Vec<Arc<dyn PhysicalExpr>>, ) -> Option<Arc<dyn WindowExpr>>
Rewrites WindowExpr
, with new expressions given. The argument should be consistent
with the return value of the WindowExpr::all_expressions
method.
Returns Some(Arc<dyn WindowExpr>)
if re-write is supported, otherwise returns None
.
Implementors§
impl WindowExpr for BuiltInWindowExpr
impl WindowExpr for PlainAggregateWindowExpr
peer based evaluation based on the fact that batch is pre-sorted given the sort columns and then per partition point we’ll evaluate the peer group (e.g. SUM or MAX gives the same results for peers) and concatenate the results.
impl WindowExpr for SlidingAggregateWindowExpr
Incrementally update window function using the fact that batch is pre-sorted given the sort columns and then per partition point.
Evaluates the peer group (e.g. SUM
or MAX
gives the same results
for peers) and concatenate the results.