pub trait BuiltInWindowFunctionExpr:
Send
+ Sync
+ Debug {
// Required methods
fn as_any(&self) -> &dyn Any;
fn field(&self) -> Result<Field>;
fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>;
fn create_evaluator(&self) -> Result<Box<dyn PartitionEvaluator>>;
// Provided methods
fn name(&self) -> &str { ... }
fn evaluate_args(&self, batch: &RecordBatch) -> Result<Vec<ArrayRef>> { ... }
fn reverse_expr(&self) -> Option<Arc<dyn BuiltInWindowFunctionExpr>> { ... }
fn get_result_ordering(
&self,
_schema: &SchemaRef,
) -> Option<PhysicalSortExpr> { ... }
}
Expand description
Evaluates a window function by instantiating a
[PartitionEvaluator]
for calculating the function’s output in
that partition.
Note that unlike aggregation based window functions, some window
functions such as rank
ignore the values in the window frame,
but others such as first_value
, last_value
, and
nth_value
need the value.
Required Methods§
sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the aggregate expression as Any
so that it can be
downcast to a specific implementation.
sourcefn field(&self) -> Result<Field>
fn field(&self) -> Result<Field>
The field of the final result of evaluating this window function.
sourcefn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>
fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>
Expressions that are passed to the PartitionEvaluator
.
sourcefn create_evaluator(&self) -> Result<Box<dyn PartitionEvaluator>>
fn create_evaluator(&self) -> Result<Box<dyn PartitionEvaluator>>
Create a PartitionEvaluator
for evaluating the function on
a particular partition.
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 window function’s arguments against the input window
batch and return an ArrayRef
.
Typically, the resulting vector is a single element vector.
sourcefn reverse_expr(&self) -> Option<Arc<dyn BuiltInWindowFunctionExpr>>
fn reverse_expr(&self) -> Option<Arc<dyn BuiltInWindowFunctionExpr>>
Construct a new BuiltInWindowFunctionExpr
that produces
the same result as this function on a window with reverse
order. The return value of this function is used by the
DataFusion optimizer to avoid re-sorting the data when
possible.
Returns None
(the default) if no reverse is known (or possible).
For example, the reverse of lead(10)
is lag(10)
.
sourcefn get_result_ordering(&self, _schema: &SchemaRef) -> Option<PhysicalSortExpr>
fn get_result_ordering(&self, _schema: &SchemaRef) -> Option<PhysicalSortExpr>
Returns the ordering introduced by the window function, if applicable.
Most window functions don’t introduce an ordering, hence the default
value is None
. Note that this information is used to update ordering
equivalences.