AvailableExpressions
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
| Function | Signature | Description |
col | col(name: &str) -> Expr | Reference a column by name. |
lit | lit(value: impl Into<Literal>) -> Expr | Create a literal constant expression. |
expr | expr(sql: &str) -> Result<Expr> | Parse a SQL expression string into an Expr. |
Aggregate Functions
| Function | Signature | Description |
count | count(expr: Expr) -> Expr | Count non-null values. |
count_all | count_all() -> Expr | Count all rows (COUNT(*)). |
sum | sum(expr: Expr) -> Expr | Sum of numeric values. |
avg | avg(expr: Expr) -> Expr | Arithmetic mean. |
min | min(expr: Expr) -> Expr | Minimum value. |
max | max(expr: Expr) -> Expr | Maximum value. |
function | function(name: &str, args: Vec<Expr>) -> Expr | Call a named SQL function or registered UDF. |
Expr Methods
| Method | Description |
.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?;