ProductDocsArchitectureBlogGitHubGitHubGet Started
Available

Expressions

Builder functions for constructing typed Expr values.

Overview

The Expr type is the versioned expression AST used throughout DataFrame, GroupedDataFrame, and streaming operators. Build expressions using the provided constructor functions rather than constructing Expr directly.

Column and Literal

FunctionSignatureDescription
colcol(name: &str) -> ExprReference a column by name.
litlit(value: impl Into<Literal>) -> ExprCreate a literal constant expression.
exprexpr(sql: &str) -> Result<Expr>Parse a SQL expression string into an Expr.

Aggregate Functions

FunctionSignatureDescription
countcount(expr: Expr) -> ExprCount non-null values.
count_allcount_all() -> ExprCount all rows (COUNT(*)).
sumsum(expr: Expr) -> ExprSum of numeric values.
avgavg(expr: Expr) -> ExprArithmetic mean.
minmin(expr: Expr) -> ExprMinimum value.
maxmax(expr: Expr) -> ExprMaximum value.
functionfunction(name: &str, args: Vec<Expr>) -> ExprCall a named SQL function or registered UDF.

Expr Methods

MethodDescription
.alias(name)Give an output alias to the expression.
.gt(rhs)Greater-than comparison.
.lt(rhs)Less-than comparison.
.eq(rhs)Equality comparison.
.and(rhs)Boolean AND.
.or(rhs)Boolean OR.
.not()Boolean NOT.
.cast(data_type)Explicit type cast.
.is_null()IS NULL predicate.
.is_not_null()IS NOT NULL predicate.
.asc()Wrap in ascending sort order.
.desc()Wrap in descending sort order.

Example

use krishiv_api::{col, lit, sum, count_all};

let df = session.sql("SELECT * FROM sales").await?;
let result = df
    .filter(col("amount").gt(lit(100i64)))?
    .group_by(vec![col("region")])?
    .agg(vec![
        sum(col("amount")).alias("total"),
        count_all().alias("count"),
    ])?
    .sort(vec![col("total").desc()])?
    .collect().await?;