Skip to main content

Expression

Enum Expression 

Source
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, ...) END
§

StructPatch(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

Source

pub fn references(&self) -> HashSet<&ColumnName>

Returns a set of columns referenced by this expression.

Source

pub fn column(field_names: impl CollectInto<ColumnName>) -> Expression

Create a new column name expression from input satisfying FromIterator for ColumnName.

Source

pub fn literal(value: impl Into<Scalar>) -> Self

Create a new expression for a literal value

Source

pub const fn null_literal(data_type: DataType) -> Self

Creates a NULL literal expression

Source

pub fn from_pred(value: Predicate) -> Self

Wraps a predicate as a boolean-valued expression

Source

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).

Source

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.

Source

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.

Source

pub fn is_null(self) -> Predicate

Create a new predicate self IS NULL

Source

pub fn is_not_null(self) -> Predicate

Create a new predicate self IS NOT NULL

Source

pub fn eq(self, other: impl Into<Self>) -> Predicate

Create a new predicate self == other

Source

pub fn ne(self, other: impl Into<Self>) -> Predicate

Create a new predicate self != other

Source

pub fn le(self, other: impl Into<Self>) -> Predicate

Create a new predicate self <= other

Source

pub fn lt(self, other: impl Into<Self>) -> Predicate

Create a new predicate self < other

Source

pub fn ge(self, other: impl Into<Self>) -> Predicate

Create a new predicate self >= other

Source

pub fn gt(self, other: impl Into<Self>) -> Predicate

Create a new predicate self > other

Source

pub fn distinct(self, other: impl Into<Self>) -> Predicate

Create a new predicate DISTINCT(self, other)

Source

pub fn unary(op: UnaryExpressionOp, expr: impl Into<Expression>) -> Self

Creates a new unary expression

Source

pub fn binary( op: BinaryExpressionOp, lhs: impl Into<Expression>, rhs: impl Into<Expression>, ) -> Self

Creates a new binary expression lhs OP rhs

Source

pub fn variadic( op: VariadicExpressionOp, exprs: impl IntoIterator<Item = impl Into<Expression>>, ) -> Self

Creates a new variadic expression

Source

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.

Source

pub fn array(exprs: impl IntoIterator<Item = impl Into<Expression>>) -> Self

Creates a new Array constructor expression. See VariadicExpressionOp::Array.

Source

pub fn opaque( op: impl OpaqueExpressionOp, exprs: impl IntoIterator<Item = Expression>, ) -> Self

Creates a new opaque expression

Source

pub fn unknown(name: impl Into<String>) -> Self

Creates a new unknown expression

Source

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.

Source

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.

Source

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

Source§

type Output = Expression

The resulting type after applying the + operator.
Source§

fn add(self, rhs: R) -> Self::Output

Performs the + operation. Read more
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.
Source§

fn arrow_opaque( op: impl ArrowOpaqueExpressionOp, exprs: impl IntoIterator<Item = Expression>, ) -> Expression

Creates a new opaque expression. See also Expression::opaque.
Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expression

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Expression

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Expression

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Into<Expression>> Div<R> for Expression

Source§

type Output = Expression

The resulting type after applying the / operator.
Source§

fn div(self, rhs: R) -> Self

Performs the / operation. Read more
Source§

impl From<&Expression> for Expression

Available on crate feature declarative-plans only.
Source§

fn from(expr: &Expression) -> Self

Converts to this type from the input type.
Source§

impl From<ColumnName> for Expression

Source§

fn from(value: ColumnName) -> Self

Converts to this type from the input type.
Source§

impl From<Predicate> for Expression

Source§

fn from(value: Predicate) -> Self

Converts to this type from the input type.
Source§

impl From<Scalar> for Expression

Source§

fn from(value: Scalar) -> Self

Converts to this type from the input type.
Source§

impl<R: Into<Expression>> Mul<R> for Expression

Source§

type Output = Expression

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: R) -> Self

Performs the * operation. Read more
Source§

impl PartialEq for Expression

Source§

fn eq(&self, other: &Expression) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Expression

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Expression

Source§

impl<R: Into<Expression>> Sub<R> for Expression

Source§

type Output = Expression

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: R) -> Self

Performs the - operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any + Send + Sync,

Source§

fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)

Obtains a dyn Any reference to the object: Read more
Source§

fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Obtains an Arc<dyn Any> reference to the object: Read more
Source§

fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts the object to Box<dyn Any>: Read more
Source§

fn type_name(&self) -> &'static str

Convenient wrapper for 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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynPartialEq for T
where T: PartialEq + AsAny,

Source§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

Source§

impl<T> FoldWithOption for T

Source§

fn fold_with<U>(self, opt: Option<U>, f: impl FnOnce(Self, U) -> Self) -> Self

Available on crate feature internal-api only.
Applies an optional fold operation f to self if opt is Some; otherwise returns self unchanged. Read more
Source§

fn try_fold_with<U, E>( self, opt: Option<U>, f: impl FnOnce(Self, U) -> Result<Self, E>, ) -> Result<Self, E>

Available on crate feature internal-api only.
Fallible fold_with: applies Result-returning f to self if opt is Some, otherwise returns self unchanged (wrapped in Ok).
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelType
where ArrowType: TryFromKernel<KernelType>,

Source§

fn try_into_arrow(self) -> Result<ArrowType, ArrowError>

Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
Source§

impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowType
where KernelType: TryFromArrow<ArrowType>,

Source§

fn try_into_kernel(self) -> Result<KernelType, ArrowError>

Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more