Trait datafusion_expr::expr_fn::ExprFunctionExt

source ·
pub trait ExprFunctionExt {
    // Required methods
    fn order_by(self, order_by: Vec<Expr>) -> ExprFuncBuilder;
    fn filter(self, filter: Expr) -> ExprFuncBuilder;
    fn distinct(self) -> ExprFuncBuilder;
    fn null_treatment(
        self,
        null_treatment: impl Into<Option<NullTreatment>>,
    ) -> ExprFuncBuilder;
    fn partition_by(self, partition_by: Vec<Expr>) -> ExprFuncBuilder;
    fn window_frame(self, window_frame: WindowFrame) -> ExprFuncBuilder;
}
Expand description

Extensions for configuring Expr::AggregateFunction or Expr::WindowFunction

Adds methods to Expr that make it easy to set optional options such as ORDER BY, FILTER and DISTINCT

§Example

unimplemented!() }
// Create an aggregate count, filtering on column y > 5
let agg = count(col("x")).filter(col("y").gt(lit(5))).build()?;

// Find the first value in an aggregate sorted by column y
// equivalent to:
// `FIRST_VALUE(x ORDER BY y ASC IGNORE NULLS)`
let sort_expr = col("y").sort(true, true);
let agg = first_value(col("x"))
    .order_by(vec![sort_expr])
    .null_treatment(NullTreatment::IgnoreNulls)
    .build()?;

// Create a window expression for percent rank partitioned on column a
// equivalent to:
// `PERCENT_RANK() OVER (PARTITION BY a ORDER BY b ASC NULLS LAST IGNORE NULLS)`
let window = percent_rank()
    .partition_by(vec![col("a")])
    .order_by(vec![col("b").sort(true, true)])
    .null_treatment(NullTreatment::IgnoreNulls)
    .build()?;

Required Methods§

source

fn order_by(self, order_by: Vec<Expr>) -> ExprFuncBuilder

Add ORDER BY <order_by>

Note: order_by must be Expr::Sort

source

fn filter(self, filter: Expr) -> ExprFuncBuilder

Add FILTER <filter>

source

fn distinct(self) -> ExprFuncBuilder

Add DISTINCT

source

fn null_treatment( self, null_treatment: impl Into<Option<NullTreatment>>, ) -> ExprFuncBuilder

Add RESPECT NULLS or IGNORE NULLS

source

fn partition_by(self, partition_by: Vec<Expr>) -> ExprFuncBuilder

Add PARTITION BY

source

fn window_frame(self, window_frame: WindowFrame) -> ExprFuncBuilder

Add appropriate window frame conditions

Object Safety§

This trait is not object safe.

Implementors§