pub enum ScalarExpr<F> {
Show 13 variants
Column(F),
Literal(Literal),
Binary {
left: Box<ScalarExpr<F>>,
op: BinaryOp,
right: Box<ScalarExpr<F>>,
},
Not(Box<ScalarExpr<F>>),
IsNull {
expr: Box<ScalarExpr<F>>,
negated: bool,
},
Aggregate(AggregateCall<F>),
GetField {
base: Box<ScalarExpr<F>>,
field_name: String,
},
Cast {
expr: Box<ScalarExpr<F>>,
data_type: DataType,
},
Compare {
left: Box<ScalarExpr<F>>,
op: CompareOp,
right: Box<ScalarExpr<F>>,
},
Coalesce(Vec<ScalarExpr<F>>),
ScalarSubquery(ScalarSubqueryExpr),
Case {
operand: Option<Box<ScalarExpr<F>>>,
branches: Vec<(ScalarExpr<F>, ScalarExpr<F>)>,
else_expr: Option<Box<ScalarExpr<F>>>,
},
Random,
}Expand description
Arithmetic scalar expression that can reference multiple fields.
Variants§
Column(F)
Literal(Literal)
Binary
Not(Box<ScalarExpr<F>>)
Logical NOT returning 1 for falsey inputs, 0 for truthy inputs, and NULL for NULL inputs.
IsNull
NULL test returning 1 when the operand is NULL (or NOT NULL when negated is true) and 0 otherwise.
Returns NULL when the operand cannot be determined.
Aggregate(AggregateCall<F>)
Aggregate function call (e.g., COUNT(), SUM(col), etc.) This is used in expressions like COUNT() + 1
GetField
Extract a field from a struct expression.
For example: user.address.city would be represented as
GetField { base: GetField { base: Column(user), field_name: “address” }, field_name: “city” }
Cast
Explicit type cast to an Arrow data type.
Compare
Comparison producing a boolean (1/0) result.
Coalesce(Vec<ScalarExpr<F>>)
First non-null expression in the provided list.
ScalarSubquery(ScalarSubqueryExpr)
Scalar subquery evaluated per input row.
Case
SQL CASE expression with optional operand and ELSE branch.
Fields
operand: Option<Box<ScalarExpr<F>>>Optional operand for simple CASE (e.g., CASE x WHEN ...).
branches: Vec<(ScalarExpr<F>, ScalarExpr<F>)>Ordered (WHEN, THEN) branches.
else_expr: Option<Box<ScalarExpr<F>>>Optional ELSE result.
Random
Random number generator returning a float in [0.0, 1.0).
Follows the PostgreSQL/DuckDB standard: each evaluation produces a new pseudo-random value. No seed control is exposed at the SQL level.
Implementations§
Source§impl<F> ScalarExpr<F>
impl<F> ScalarExpr<F>
pub fn column(field: F) -> Self
pub fn literal<L: Into<Literal>>(lit: L) -> Self
pub fn binary(left: Self, op: BinaryOp, right: Self) -> Self
pub fn logical_not(expr: Self) -> Self
pub fn is_null(expr: Self, negated: bool) -> Self
pub fn aggregate(call: AggregateCall<F>) -> Self
pub fn get_field(base: Self, field_name: String) -> Self
pub fn cast(expr: Self, data_type: DataType) -> Self
pub fn compare(left: Self, op: CompareOp, right: Self) -> Self
pub fn coalesce(exprs: Vec<Self>) -> Self
pub fn scalar_subquery(id: SubqueryId, data_type: DataType) -> Self
pub fn case( operand: Option<Self>, branches: Vec<(Self, Self)>, else_expr: Option<Self>, ) -> Self
pub fn random() -> Self
Source§impl<F> ScalarExpr<F>
impl<F> ScalarExpr<F>
Sourcepub fn format_display(&self) -> String
pub fn format_display(&self) -> String
Render a scalar expression as a human-readable string.
Trait Implementations§
Source§impl<F: Clone> Clone for ScalarExpr<F>
impl<F: Clone> Clone for ScalarExpr<F>
Source§fn clone(&self) -> ScalarExpr<F>
fn clone(&self) -> ScalarExpr<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more