Enum datafusion::logical_plan::Expr [−][src]
pub enum Expr {
Show 22 variants
Alias(Box<Expr>, String),
Column(Column),
ScalarVariable(Vec<String>),
Literal(ScalarValue),
BinaryExpr {
left: Box<Expr>,
op: Operator,
right: Box<Expr>,
},
Not(Box<Expr>),
IsNotNull(Box<Expr>),
IsNull(Box<Expr>),
Negative(Box<Expr>),
GetIndexedField {
expr: Box<Expr>,
key: ScalarValue,
},
Between {
expr: Box<Expr>,
negated: bool,
low: Box<Expr>,
high: Box<Expr>,
},
Case {
expr: Option<Box<Expr>>,
when_then_expr: Vec<(Box<Expr>, Box<Expr>)>,
else_expr: Option<Box<Expr>>,
},
Cast {
expr: Box<Expr>,
data_type: DataType,
},
TryCast {
expr: Box<Expr>,
data_type: DataType,
},
Sort {
expr: Box<Expr>,
asc: bool,
nulls_first: bool,
},
ScalarFunction {
fun: BuiltinScalarFunction,
args: Vec<Expr>,
},
ScalarUDF {
fun: Arc<ScalarUDF>,
args: Vec<Expr>,
},
AggregateFunction {
fun: AggregateFunction,
args: Vec<Expr>,
distinct: bool,
},
WindowFunction {
fun: WindowFunction,
args: Vec<Expr>,
partition_by: Vec<Expr>,
order_by: Vec<Expr>,
window_frame: Option<WindowFrame>,
},
AggregateUDF {
fun: Arc<AggregateUDF>,
args: Vec<Expr>,
},
InList {
expr: Box<Expr>,
list: Vec<Expr>,
negated: bool,
},
Wildcard,
}
Expand description
Expr
is a central struct of DataFusion’s query API, and
represent logical expressions such as A + 1
, or CAST(c1 AS int)
.
An Expr
can compute its DataType
and nullability, and has functions for building up complex
expressions.
Examples
Create an expression c1
referring to column named “c1”
let expr = col("c1");
assert_eq!(expr, Expr::Column(Column::from_name("c1")));
Create the expression c1 + c2
to add columns “c1” and “c2” together
let expr = col("c1") + col("c2");
assert!(matches!(expr, Expr::BinaryExpr { ..} ));
if let Expr::BinaryExpr { left, right, op } = expr {
assert_eq!(*left, col("c1"));
assert_eq!(*right, col("c2"));
assert_eq!(op, Operator::Plus);
}
Create expression c1 = 42
to compare the value in coumn “c1” to the literal value 42
let expr = col("c1").eq(lit(42));
assert!(matches!(expr, Expr::BinaryExpr { ..} ));
if let Expr::BinaryExpr { left, right, op } = expr {
assert_eq!(*left, col("c1"));
let scalar = ScalarValue::Int32(Some(42));
assert_eq!(*right, Expr::Literal(scalar));
assert_eq!(op, Operator::Eq);
}
Variants
An expression with a specific name.
Column(Column)
A named reference to a qualified filed in a schema.
Tuple Fields of Column
0: Column
A named reference to a variable in a registry.
Literal(ScalarValue)
A constant value.
Tuple Fields of Literal
0: ScalarValue
A binary expression such as “age > 21”
Fields of BinaryExpr
Negation of an expression. The expression’s type must be a boolean to make sense.
Whether an expression is not Null. This expression is never null.
Whether an expression is Null. This expression is never null.
arithmetic negation of an expression, the operand must be of a signed numeric data type
Returns the field of a [ListArray
] or [StructArray
] by key
Fields of GetIndexedField
Whether an expression is between a given range.
Fields of Between
The CASE expression is similar to a series of nested if/else and there are two forms that can be used. The first form consists of a series of boolean “when” expressions with corresponding “then” expressions, and an optional “else” expression.
CASE WHEN condition THEN result [WHEN …] [ELSE result] END
The second form uses a base expression and then a series of “when” clauses that match on a literal value.
CASE expression WHEN value THEN result [WHEN …] [ELSE result] END
Fields of Case
Casts the expression to a given type and will return a runtime error if the expression cannot be cast. This expression is guaranteed to have a fixed type.
Fields of Cast
Casts the expression to a given type and will return a null value if the expression cannot be cast. This expression is guaranteed to have a fixed type.
Fields of TryCast
A sort expression, that can be used to sort values.
Fields of Sort
Represents the call of a built-in scalar function with a set of arguments.
Fields of ScalarFunction
fun: BuiltinScalarFunction
The function
args: Vec<Expr>
List of expressions to feed to the functions as arguments
Represents the call of a user-defined scalar function with arguments.
Fields of ScalarUDF
Represents the call of an aggregate built-in function with arguments.
Fields of AggregateFunction
fun: AggregateFunction
Name of the function
args: Vec<Expr>
List of expressions to feed to the functions as arguments
distinct: bool
Whether this is a DISTINCT aggregation or not
Represents the call of a window function with arguments.
Fields of WindowFunction
fun: WindowFunction
Name of the function
args: Vec<Expr>
List of expressions to feed to the functions as arguments
partition_by: Vec<Expr>
List of partition by expressions
order_by: Vec<Expr>
List of order by expressions
window_frame: Option<WindowFrame>
Window frame
aggregate function
Fields of AggregateUDF
fun: Arc<AggregateUDF>
The function
args: Vec<Expr>
List of expressions to feed to the functions as arguments
Returns whether the list contains the expr value.
Fields of InList
Represents a reference to all fields in a schema.
Implementations
Returns the arrow::datatypes::DataType of the expression based on arrow::datatypes::Schema.
Errors
This function errors when it is not possible to compute its arrow::datatypes::DataType.
This happens when e.g. the expression refers to a column that does not exist in the schema, or when
the expression is incorrectly typed (e.g. [utf8] + [bool]
).
Returns the nullability of the expression based on arrow::datatypes::Schema.
Errors
This function errors when it is not possible to compute its nullability. This happens when the expression refers to a column that does not exist in the schema.
Returns the name of this expression based on crate::logical_plan::DFSchema.
This represents how a column with this expression is named when no alias is chosen
Returns a arrow::datatypes::Field compatible with this expression.
Wraps this expression in a cast to a target arrow::datatypes::DataType.
Errors
This function errors when it is impossible to cast the expression to the target arrow::datatypes::DataType.
Calculate the modulus of two expressions.
Return self % other
Return self IN <list>
if negated
is false, otherwise
return self NOT IN <list>
.a
Return `IsNotNull(Box(self))
Create a sort expression from an existing expression.
let sort_expr = col("foo").sort(true, true); // SORT ASC NULLS_FIRST
Performs a depth first walk of an expression and
its children, calling ExpressionVisitor::pre_visit
and
visitor.post_visit
.
Implements the visitor pattern to
separate expression algorithms from the structure of the
Expr
tree and make it easier to add new types of expressions
and algorithms that walk the tree.
For an expression tree such as
BinaryExpr (GT)
left: Column("foo")
right: Column("bar")
The nodes are visited using the following order
pre_visit(BinaryExpr(GT))
pre_visit(Column("foo"))
pre_visit(Column("bar"))
post_visit(Column("bar"))
post_visit(Column("bar"))
post_visit(BinaryExpr(GT))
If an Err result is returned, recursion is stopped immediately
If Recursion::Stop
is returned on a call to pre_visit, no
children of that expression are visited, nor is post_visit
called on that expression
Performs a depth first walk of an expression and its children
to rewrite an expression, consuming self
producing a new
Expr
.
Implements a modified version of the visitor
pattern to
separate algorithms from the structure of the Expr
tree and
make it easier to write new, efficient expression
transformation algorithms.
For an expression tree such as
BinaryExpr (GT)
left: Column("foo")
right: Column("bar")
The nodes are visited using the following order
pre_visit(BinaryExpr(GT))
pre_visit(Column("foo"))
mutatate(Column("foo"))
pre_visit(Column("bar"))
mutate(Column("bar"))
mutate(BinaryExpr(GT))
If an Err result is returned, recursion is stopped immediately
If false
is returned on a call to pre_visit, no
children of that expression are visited, nor is mutate
called on that expression
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Expr
impl !UnwindSafe for Expr
Blanket Implementations
Mutably borrows from an owned value. Read more