pub enum Expression {
Show 13 variants
Literal(Scalar),
Column(ColumnName),
Predicate(Box<Predicate>),
Struct(Vec<ExpressionRef>, Option<ExpressionRef>),
StructPatch(ExpressionStructPatch),
Unary(UnaryExpression),
Binary(BinaryExpression),
Variadic(VariadicExpression),
Opaque(OpaqueExpression),
Unknown(String),
ParseJson(ParseJsonExpression),
MapToStruct(MapToStructExpression),
Cast(CastExpression),
}Expand description
A SQL expression.
These expressions do not track or validate data types, other than the type of literals. It is up to the expression evaluator to validate the expression against a schema and add appropriate casts as required.
Variants§
Literal(Scalar)
A literal value.
Column(ColumnName)
A column reference by name. A ColumnName is a path, so a multi-segment name like
add.stats.numRecords descends one nested struct field per segment, matching by name.
Predicate(Box<Predicate>)
A predicate treated as a boolean expression
Struct(Vec<ExpressionRef>, Option<ExpressionRef>)
A struct computed from one expression per output field, in field order.
Field names and nullability come from the surrounding output schema (the evaluator’s
result_type, such as a Project’s target field), and each field expression’s type is
validated against the schema, so building a struct takes both. The expression count must
equal the output field count.
The optional nullability predicate says when to keep the struct: a row survives only where it is true, and nulls entirely where it is false or null.
CASE WHEN keep_pred THEN struct(expr1, expr2, ...) ENDStructPatch(ExpressionStructPatch)
A sparse patch of a struct. More efficient than Struct for wide schemas
where only a few fields change, achieving O(changes) instead of O(schema_width) complexity.
Unary(UnaryExpression)
An expression that takes one expression as input.
Binary(BinaryExpression)
An expression that takes two expressions as input.
Variadic(VariadicExpression)
An expression that takes a variable number of expressions as input.
Opaque(OpaqueExpression)
An expression that the engine defines and implements. Kernel interacts with the expression
only through methods provided by the OpaqueExpressionOp trait.
Unknown(String)
An unknown expression (i.e. one that neither kernel nor engine attempts to evaluate). For
data skipping purposes, kernel treats unknown expressions as if they were literal NULL
values (which may disable skipping if it “poisons” the predicate), but engines MUST NOT
attempt to interpret them as NULL when evaluating query filters because it could produce
incorrect results. For example, converting WHERE <fancy-udf-invocation> IS NULL to WHERE <unknown> IS NULL to WHERE NULL IS NULL is equivalent to WHERE TRUE and would include
all rows – almost certainly NOT what the query author intended. Use Expression::Opaque
for expressions kernel doesn’t understand but which engine can still evaluate.
ParseJson(ParseJsonExpression)
Parse a JSON string expression into a struct with the given schema. Unparseable input,
which includes an empty string, must yield NULL rather than error; see
ParseJsonExpression.
MapToStruct(MapToStructExpression)
Extract keys from a Map<String, String> and parse values into a typed struct. See
MapToStructExpression for how values are parsed.
Cast(CastExpression)
Cast a child expression to a target type. See CastExpression.
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn references(&self) -> HashSet<&ColumnName>
pub fn references(&self) -> HashSet<&ColumnName>
Returns a set of columns referenced by this expression.
Sourcepub fn column(field_names: impl CollectInto<ColumnName>) -> Expression
pub fn column(field_names: impl CollectInto<ColumnName>) -> Expression
Create a new column name expression from input satisfying FromIterator for ColumnName.
Sourcepub const fn null_literal(data_type: DataType) -> Self
pub const fn null_literal(data_type: DataType) -> Self
Creates a NULL literal expression
Sourcepub fn struct_from(
exprs: impl IntoIterator<Item = impl Into<Arc<Self>>>,
) -> Self
pub fn struct_from( exprs: impl IntoIterator<Item = impl Into<Arc<Self>>>, ) -> Self
Create a new struct expression.
The field names and types are supplied by the caller at evaluation time via the
result_type parameter of the expression evaluator. Use this when the schema is
always available from external context (e.g. the expression is the top-level output
of crate::ExpressionEvaluator).
Sourcepub fn struct_with_nullability_from(
exprs: impl IntoIterator<Item = impl Into<Arc<Self>>>,
nullability_predicate: impl Into<Arc<Self>>,
) -> Self
pub fn struct_with_nullability_from( exprs: impl IntoIterator<Item = impl Into<Arc<Self>>>, nullability_predicate: impl Into<Arc<Self>>, ) -> Self
Create a new struct expression with a nullability predicate.
When the predicate evaluates to false or null for a row, the entire struct is null for that row.
Sourcepub fn struct_patch<P>(patch: P) -> DeltaResult<Self>
pub fn struct_patch<P>(patch: P) -> DeltaResult<Self>
Creates a new struct patch expression from a raw patch or patch builder.
Returns an expression that applies the supplied sparse patch to an input struct. Passing a
raw ExpressionStructPatch is infallible; passing an ExpressionStructPatchBuilder
validates and lowers the recorded operations before constructing the expression.
§Errors
Returns an error if the supplied patch builder contains conflicting operations.
Sourcepub fn is_not_null(self) -> Predicate
pub fn is_not_null(self) -> Predicate
Create a new predicate self IS NOT NULL
Sourcepub fn distinct(self, other: impl Into<Self>) -> Predicate
pub fn distinct(self, other: impl Into<Self>) -> Predicate
Create a new predicate DISTINCT(self, other)
Sourcepub fn unary(op: UnaryExpressionOp, expr: impl Into<Expression>) -> Self
pub fn unary(op: UnaryExpressionOp, expr: impl Into<Expression>) -> Self
Creates a new unary expression
Sourcepub fn binary(
op: BinaryExpressionOp,
lhs: impl Into<Expression>,
rhs: impl Into<Expression>,
) -> Self
pub fn binary( op: BinaryExpressionOp, lhs: impl Into<Expression>, rhs: impl Into<Expression>, ) -> Self
Creates a new binary expression lhs OP rhs
Sourcepub fn variadic(
op: VariadicExpressionOp,
exprs: impl IntoIterator<Item = impl Into<Expression>>,
) -> Self
pub fn variadic( op: VariadicExpressionOp, exprs: impl IntoIterator<Item = impl Into<Expression>>, ) -> Self
Creates a new variadic expression
Sourcepub fn coalesce(exprs: impl IntoIterator<Item = impl Into<Expression>>) -> Self
pub fn coalesce(exprs: impl IntoIterator<Item = impl Into<Expression>>) -> Self
Creates a new COALESCE expression that returns the first non-null value.
COALESCE evaluates expressions in order and returns the first non-null result. If all expressions evaluate to null, the result is null.
Sourcepub fn array(exprs: impl IntoIterator<Item = impl Into<Expression>>) -> Self
pub fn array(exprs: impl IntoIterator<Item = impl Into<Expression>>) -> Self
Creates a new Array constructor expression. See VariadicExpressionOp::Array.
Sourcepub fn opaque(
op: impl OpaqueExpressionOp,
exprs: impl IntoIterator<Item = Expression>,
) -> Self
pub fn opaque( op: impl OpaqueExpressionOp, exprs: impl IntoIterator<Item = Expression>, ) -> Self
Creates a new opaque expression
Sourcepub fn parse_json(
json_expr: impl Into<Expression>,
output_schema: SchemaRef,
) -> Self
pub fn parse_json( json_expr: impl Into<Expression>, output_schema: SchemaRef, ) -> Self
Creates a new ParseJson expression that parses a JSON string column into a struct.
This is the inverse of UnaryExpressionOp::ToJson - it converts a JSON-encoded string
into a struct. Sub-millisecond timestamp precision does not survive the round trip, since
ToJson truncates it.
Sourcepub fn map_to_struct(map_expr: impl Into<Expression>) -> Self
pub fn map_to_struct(map_expr: impl Into<Expression>) -> Self
Extracts keys from a Map<String, String> and parses values into a typed struct. The output
struct schema is determined by the evaluator’s result_type. An empty-string value is the
exception (aligning with Spark): it casts to itself for string, to empty bytes for binary,
and to null for every other type. See MapToStructExpression for the full contract.
Sourcepub fn cast(expr: impl Into<Expression>, target: DataType) -> Self
pub fn cast(expr: impl Into<Expression>, target: DataType) -> Self
Creates a new cast of expr to target, following SQL CAST semantics (unrepresentable
values become NULL). See CastExpression.
Trait Implementations§
Source§impl<R: Into<Expression>> Add<R> for Expression
impl<R: Into<Expression>> Add<R> for Expression
Source§impl ArrowOpaqueExpression for Expression
Available on crate feature arrow-expression and crate feature default-engine-base and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
impl ArrowOpaqueExpression for Expression
arrow-expression and crate feature default-engine-base and (crate features arrow-conversion or declarative-plans or default-engine-base) only.Source§fn arrow_opaque(
op: impl ArrowOpaqueExpressionOp,
exprs: impl IntoIterator<Item = Expression>,
) -> Expression
fn arrow_opaque( op: impl ArrowOpaqueExpressionOp, exprs: impl IntoIterator<Item = Expression>, ) -> Expression
Expression::opaque.Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Expression
impl Display for Expression
Source§impl<R: Into<Expression>> Div<R> for Expression
impl<R: Into<Expression>> Div<R> for Expression
Source§impl From<&Expression> for Expression
Available on crate feature declarative-plans only.
impl From<&Expression> for Expression
declarative-plans only.Source§fn from(expr: &Expression) -> Self
fn from(expr: &Expression) -> Self
Source§impl From<ColumnName> for Expression
impl From<ColumnName> for Expression
Source§fn from(value: ColumnName) -> Self
fn from(value: ColumnName) -> Self
Source§impl From<Predicate> for Expression
impl From<Predicate> for Expression
Source§impl From<Scalar> for Expression
impl From<Scalar> for Expression
Source§impl<R: Into<Expression>> Mul<R> for Expression
impl<R: Into<Expression>> Mul<R> for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl Serialize for Expression
impl Serialize for Expression
impl StructuralPartialEq for Expression
Source§impl<R: Into<Expression>> Sub<R> for Expression
impl<R: Into<Expression>> Sub<R> for Expression
Auto Trait Implementations§
impl !RefUnwindSafe for Expression
impl !UnwindSafe for Expression
impl Freeze for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
Blanket Implementations§
Source§impl<T> AsAny for T
impl<T> AsAny for T
Source§fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)
fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)
dyn Any reference to the object: Read moreSource§fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ
fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ
Arc<dyn Any> reference to the object: Read moreSource§fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>
fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>
Box<dyn Any>: Read moreSource§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
std::any::type_name, since Any does not provide it and
Any::type_id is useless as a debugging aid (its Debug is just a mess of hex digits).Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynPartialEq for T
impl<T> DynPartialEq for T
Source§impl<T> FoldWithOption for T
impl<T> FoldWithOption for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
Source§impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelTypewhere
ArrowType: TryFromKernel<KernelType>,
impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelTypewhere
ArrowType: TryFromKernel<KernelType>,
Source§fn try_into_arrow(self) -> Result<ArrowType, ArrowError>
fn try_into_arrow(self) -> Result<ArrowType, ArrowError>
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.Source§impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowTypewhere
KernelType: TryFromArrow<ArrowType>,
impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowTypewhere
KernelType: TryFromArrow<ArrowType>,
Source§fn try_into_kernel(self) -> Result<KernelType, ArrowError>
fn try_into_kernel(self) -> Result<KernelType, ArrowError>
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.