Trait datafusion_expr::AggregateExt

source ·
pub trait AggregateExt {
    // Required methods
    fn order_by(self, order_by: Vec<Expr>) -> AggregateBuilder;
    fn filter(self, filter: Expr) -> AggregateBuilder;
    fn distinct(self) -> AggregateBuilder;
    fn null_treatment(self, null_treatment: NullTreatment) -> AggregateBuilder;
}
Expand description

Extensions for configuring Expr::AggregateFunction

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

§Example

use datafusion_expr::AggregateExt;

// Create COUNT(x FILTER y > 5)
let agg = count(col("x"))
   .filter(col("y").gt(lit(5)))
   .build()?;
 // Create FIRST_VALUE(x ORDER BY y 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()?;

Required Methods§

source

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

Add ORDER BY <order_by>

Note: order_by must be Expr::Sort

source

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

Add FILTER <filter>

source

fn distinct(self) -> AggregateBuilder

Add DISTINCT

source

fn null_treatment(self, null_treatment: NullTreatment) -> AggregateBuilder

Add RESPECT NULLS or IGNORE NULLS

Implementors§