Enum mz_expr::scalar::MirScalarExpr
source · [−]pub enum MirScalarExpr {
Column(usize),
Literal(Result<Row, EvalError>, ColumnType),
CallUnmaterializable(UnmaterializableFunc),
CallUnary {
func: UnaryFunc,
expr: Box<MirScalarExpr>,
},
CallBinary {
func: BinaryFunc,
expr1: Box<MirScalarExpr>,
expr2: Box<MirScalarExpr>,
},
CallVariadic {
func: VariadicFunc,
exprs: Vec<MirScalarExpr>,
},
If {
cond: Box<MirScalarExpr>,
then: Box<MirScalarExpr>,
els: Box<MirScalarExpr>,
},
}
Variants
Column(usize)
A column of the input row
Literal(Result<Row, EvalError>, ColumnType)
A literal value. (Stored as a row, because we can’t own a Datum)
CallUnmaterializable(UnmaterializableFunc)
A call to an unmaterializable function.
These functions cannot be evaluated by MirScalarExpr::eval
. They must
be transformed away by a higher layer.
CallUnary
A function call that takes one expression as an argument.
CallBinary
A function call that takes two expressions as arguments.
CallVariadic
A function call that takes an arbitrary number of arguments.
If
Conditionally evaluated expressions.
It is important that then
and els
only be evaluated if
cond
is true or not, respectively. This is the only way
users can guard execution (other logical operator do not
short-circuit) and we need to preserve that.
Implementations
sourceimpl MirScalarExpr
impl MirScalarExpr
pub fn columns(is: &[usize]) -> Vec<MirScalarExpr>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn column(column: usize) -> Self
pub fn literal(res: Result<Datum<'_>, EvalError>, typ: ScalarType) -> Self
pub fn literal_ok(datum: Datum<'_>, typ: ScalarType) -> Self
pub fn literal_null(typ: ScalarType) -> Self
pub fn call_unary(self, func: UnaryFunc) -> Self
pub fn call_binary(self, other: Self, func: BinaryFunc) -> Self
pub fn if_then_else(self, t: Self, f: Self) -> Self
sourcepub fn permute(&mut self, permutation: &[usize])
pub fn permute(&mut self, permutation: &[usize])
Rewrites column indices with their value in permutation
.
This method is applicable even when permutation
is not a
strict permutation, and it only needs to have entries for
each column referenced in self
.
sourcepub fn permute_map(&mut self, permutation: &HashMap<usize, usize>)
pub fn permute_map(&mut self, permutation: &HashMap<usize, usize>)
Rewrites column indices with their value in permutation
.
This method is applicable even when permutation
is not a
strict permutation, and it only needs to have entries for
each column referenced in self
.
pub fn support(&self) -> HashSet<usize>
pub fn take(&mut self) -> Self
pub fn as_literal(&self) -> Option<Result<Datum<'_>, &EvalError>>
pub fn as_literal_str(&self) -> Option<&str>
pub fn as_literal_err(&self) -> Option<&EvalError>
pub fn is_literal(&self) -> bool
pub fn is_literal_true(&self) -> bool
pub fn is_literal_false(&self) -> bool
pub fn is_literal_null(&self) -> bool
pub fn is_literal_ok(&self) -> bool
pub fn is_literal_err(&self) -> bool
sourcepub fn as_column(&self) -> Option<usize>
pub fn as_column(&self) -> Option<usize>
If self is a column, return the column index, otherwise None
.
sourcepub fn reduce(&mut self, relation_type: &RelationType)
pub fn reduce(&mut self, relation_type: &RelationType)
Reduces a complex expression where possible.
Also canonicalizes the expression.
use mz_expr::{BinaryFunc, MirScalarExpr};
use mz_repr::{ColumnType, Datum, RelationType, ScalarType};
let expr_0 = MirScalarExpr::Column(0);
let expr_t = MirScalarExpr::literal_ok(Datum::True, ScalarType::Bool);
let expr_f = MirScalarExpr::literal_ok(Datum::False, ScalarType::Bool);
let mut test =
expr_t
.clone()
.call_binary(expr_f.clone(), BinaryFunc::And)
.if_then_else(expr_0, expr_t.clone());
let input_type = RelationType::new(vec![ScalarType::Int32.nullable(false)]);
test.reduce(&input_type);
assert_eq!(test, expr_t);
sourcefn decompose_is_null(&mut self) -> Option<MirScalarExpr>
fn decompose_is_null(&mut self) -> Option<MirScalarExpr>
Decompose an IsNull expression into a disjunction of simpler expressions.
Assumes that self
is the expression inside of an IsNull.
Returns Some(expressions)
if the outer IsNull is to be
replaced by some other expression.
sourcefn undistribute_and_or(&mut self)
fn undistribute_and_or(&mut self)
AND/OR undistribution to apply at each ScalarExpr
.
Transforms (a && b) || (a && c) into a && (b || c)
Transforms (a || b) && (a || c) into a || (b && c)
sourcefn harvest_operands(&mut self, operands: &mut Vec<MirScalarExpr>, and: bool)
fn harvest_operands(&mut self, operands: &mut Vec<MirScalarExpr>, and: bool)
Collects undistributable terms from X expressions.
If and
, X is AND. If not and
, X is OR.
sourcefn suppress_operands(&mut self, operands: &[MirScalarExpr], and: bool)
fn suppress_operands(&mut self, operands: &[MirScalarExpr], and: bool)
Removes undistributed terms from AND expressions.
If and
, X is AND. If not and
, X is OR.
sourcepub fn non_null_requirements(&self, columns: &mut HashSet<usize>)
pub fn non_null_requirements(&self, columns: &mut HashSet<usize>)
Adds any columns that must be non-Null for self
to be non-Null.
pub fn typ(&self, relation_type: &RelationType) -> ColumnType
pub fn eval<'a>(
&'a self,
datums: &[Datum<'a>],
temp_storage: &'a RowArena
) -> Result<Datum<'a>, EvalError>
sourcepub fn contains_temporal(&self) -> bool
pub fn contains_temporal(&self) -> bool
True iff the expression contains
UnmaterializableFunc::MzLogicalTimestamp
.
sourcepub fn contains_unmaterializable(&self) -> bool
pub fn contains_unmaterializable(&self) -> bool
True iff the expression contains an UnmaterializableFunc
.
Trait Implementations
sourceimpl Arbitrary for MirScalarExpr
impl Arbitrary for MirScalarExpr
type Parameters = ()
type Parameters = ()
The type of parameters that arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
. Read more
type Strategy = BoxedStrategy<MirScalarExpr>
type Strategy = BoxedStrategy<MirScalarExpr>
sourcefn arbitrary_with(_: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
sourceimpl Clone for MirScalarExpr
impl Clone for MirScalarExpr
sourcefn clone(&self) -> MirScalarExpr
fn clone(&self) -> MirScalarExpr
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MirScalarExpr
impl Debug for MirScalarExpr
sourceimpl<'de> Deserialize<'de> for MirScalarExpr
impl<'de> Deserialize<'de> for MirScalarExpr
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for MirScalarExpr
impl Display for MirScalarExpr
sourceimpl Hash for MirScalarExpr
impl Hash for MirScalarExpr
sourceimpl MzReflect for MirScalarExpr
impl MzReflect for MirScalarExpr
sourcefn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)
fn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)
Adds names and types of the fields of the struct or enum to rti
. Read more
sourceimpl Ord for MirScalarExpr
impl Ord for MirScalarExpr
sourceimpl PartialEq<MirScalarExpr> for MirScalarExpr
impl PartialEq<MirScalarExpr> for MirScalarExpr
sourcefn eq(&self, other: &MirScalarExpr) -> bool
fn eq(&self, other: &MirScalarExpr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &MirScalarExpr) -> bool
fn ne(&self, other: &MirScalarExpr) -> bool
This method tests for !=
.
sourceimpl PartialOrd<MirScalarExpr> for MirScalarExpr
impl PartialOrd<MirScalarExpr> for MirScalarExpr
sourcefn partial_cmp(&self, other: &MirScalarExpr) -> Option<Ordering>
fn partial_cmp(&self, other: &MirScalarExpr) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl RustType<ProtoMirScalarExpr> for MirScalarExpr
impl RustType<ProtoMirScalarExpr> for MirScalarExpr
sourcefn into_proto(&self) -> ProtoMirScalarExpr
fn into_proto(&self) -> ProtoMirScalarExpr
Convert a Self
into a Proto
value.
sourcefn from_proto(proto: ProtoMirScalarExpr) -> Result<Self, TryFromProtoError>
fn from_proto(proto: ProtoMirScalarExpr) -> Result<Self, TryFromProtoError>
Consume and convert a Proto
back into a Self
value. Read more
sourceimpl Serialize for MirScalarExpr
impl Serialize for MirScalarExpr
sourceimpl VisitChildren for MirScalarExpr
impl VisitChildren for MirScalarExpr
sourcefn visit_children<'a, F>(&'a self, f: F) where
F: FnMut(&'a Self),
fn visit_children<'a, F>(&'a self, f: F) where
F: FnMut(&'a Self),
Apply an infallible immutable function f
to each direct child.
sourcefn visit_mut_children<'a, F>(&'a mut self, f: F) where
F: FnMut(&'a mut Self),
fn visit_mut_children<'a, F>(&'a mut self, f: F) where
F: FnMut(&'a mut Self),
Apply an infallible mutable function f
to each direct child.
impl Eq for MirScalarExpr
impl StructuralEq for MirScalarExpr
impl StructuralPartialEq for MirScalarExpr
Auto Trait Implementations
impl RefUnwindSafe for MirScalarExpr
impl Send for MirScalarExpr
impl Sync for MirScalarExpr
impl Unpin for MirScalarExpr
impl UnwindSafe for MirScalarExpr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<T> DisplayExt for T where
T: Display,
impl<T> DisplayExt for T where
T: Display,
sourcefn to_string_alt(&self) -> String
fn to_string_alt(&self) -> String
Formats an object with the “alternative” format ({:#}
) and returns it.
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
sourceimpl<T> ProgressEventTimestamp for T where
T: Data + Debug + Any,
impl<T> ProgressEventTimestamp for T where
T: Data + Debug + Any,
sourceimpl<P, R> ProtoType<R> for P where
R: RustType<P>,
impl<P, R> ProtoType<R> for P where
R: RustType<P>,
sourcefn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
See RustType::from_proto
.
sourcefn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
See RustType::into_proto
.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> Visit for T where
T: VisitChildren,
impl<T> Visit for T where
T: VisitChildren,
sourcefn visit_post<F>(&self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&T),
fn visit_post<F>(&self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&T),
Post-order immutable infallible visitor for self
.
sourcefn visit_post_nolimit<F>(&self, f: &mut F) where
F: FnMut(&T),
fn visit_post_nolimit<F>(&self, f: &mut F) where
F: FnMut(&T),
Use visit_post
instead.
Post-order immutable infallible visitor for self
.
Does not enforce a recursion limit. Read more
sourcefn visit_mut_post<F>(&mut self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&mut T),
fn visit_mut_post<F>(&mut self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&mut T),
Post-order mutable infallible visitor for self
.
sourcefn visit_mut_post_nolimit<F>(&mut self, f: &mut F) where
F: FnMut(&mut T),
fn visit_mut_post_nolimit<F>(&mut self, f: &mut F) where
F: FnMut(&mut T),
Use visit_mut_post
instead.
Post-order mutable infallible visitor for self
.
Does not enforce a recursion limit. Read more
sourcefn try_visit_post<F, E>(&self, f: &mut F) -> Result<(), E> where
F: FnMut(&T) -> Result<(), E>,
E: From<RecursionLimitError>,
fn try_visit_post<F, E>(&self, f: &mut F) -> Result<(), E> where
F: FnMut(&T) -> Result<(), E>,
E: From<RecursionLimitError>,
Post-order immutable fallible visitor for self
.
sourcefn try_visit_mut_post<F, E>(&mut self, f: &mut F) -> Result<(), E> where
F: FnMut(&mut T) -> Result<(), E>,
E: From<RecursionLimitError>,
fn try_visit_mut_post<F, E>(&mut self, f: &mut F) -> Result<(), E> where
F: FnMut(&mut T) -> Result<(), E>,
E: From<RecursionLimitError>,
Post-order mutable fallible visitor for self
.
sourcefn visit_pre<F>(&self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&T),
fn visit_pre<F>(&self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&T),
Pre-order immutable infallible visitor for self
.
sourcefn visit_pre_nolimit<F>(&self, f: &mut F) where
F: FnMut(&T),
fn visit_pre_nolimit<F>(&self, f: &mut F) where
F: FnMut(&T),
Use visit_pre
instead.
Pre-order immutable infallible visitor for self
.
Does not enforce a recursion limit. Read more
sourcefn visit_mut_pre<F>(&mut self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&mut T),
fn visit_mut_pre<F>(&mut self, f: &mut F) -> Result<(), RecursionLimitError> where
F: FnMut(&mut T),
Pre-order mutable infallible visitor for self
.
sourcefn visit_mut_pre_nolimit<F>(&mut self, f: &mut F) where
F: FnMut(&mut T),
fn visit_mut_pre_nolimit<F>(&mut self, f: &mut F) where
F: FnMut(&mut T),
Use visit_mut_pre
instead.
Pre-order mutable infallible visitor for self
.
Does not enforce a recursion limit. Read more
sourcefn try_visit_pre<F, E>(&self, f: &mut F) -> Result<(), E> where
F: FnMut(&T) -> Result<(), E>,
E: From<RecursionLimitError>,
fn try_visit_pre<F, E>(&self, f: &mut F) -> Result<(), E> where
F: FnMut(&T) -> Result<(), E>,
E: From<RecursionLimitError>,
Pre-order immutable fallible visitor for self
.
sourcefn try_visit_mut_pre<F, E>(&mut self, f: &mut F) -> Result<(), E> where
F: FnMut(&mut T) -> Result<(), E>,
E: From<RecursionLimitError>,
fn try_visit_mut_pre<F, E>(&mut self, f: &mut F) -> Result<(), E> where
F: FnMut(&mut T) -> Result<(), E>,
E: From<RecursionLimitError>,
Pre-order mutable fallible visitor for self
.
sourcefn visit_pre_post<F1, F2>(
&self,
pre: &mut F1,
post: &mut F2
) -> Result<(), RecursionLimitError> where
F1: FnMut(&T) -> Option<Vec<&T, Global>>,
F2: FnMut(&T),
fn visit_pre_post<F1, F2>(
&self,
pre: &mut F1,
post: &mut F2
) -> Result<(), RecursionLimitError> where
F1: FnMut(&T) -> Option<Vec<&T, Global>>,
F2: FnMut(&T),
A generalization of Visit::visit_pre
and Visit::visit_post
. Read more
sourcefn visit_pre_post_nolimit<F1, F2>(&self, pre: &mut F1, post: &mut F2) where
F1: FnMut(&T) -> Option<Vec<&T, Global>>,
F2: FnMut(&T),
fn visit_pre_post_nolimit<F1, F2>(&self, pre: &mut F1, post: &mut F2) where
F1: FnMut(&T) -> Option<Vec<&T, Global>>,
F2: FnMut(&T),
Use visit_pre_post
instead.
A generalization of Visit::visit_pre
and Visit::visit_post
.
Does not enforce a recursion limit. Read more
sourcefn visit_mut_pre_post<F1, F2>(
&mut self,
pre: &mut F1,
post: &mut F2
) -> Result<(), RecursionLimitError> where
F1: FnMut(&mut T) -> Option<Vec<&mut T, Global>>,
F2: FnMut(&mut T),
fn visit_mut_pre_post<F1, F2>(
&mut self,
pre: &mut F1,
post: &mut F2
) -> Result<(), RecursionLimitError> where
F1: FnMut(&mut T) -> Option<Vec<&mut T, Global>>,
F2: FnMut(&mut T),
A generalization of Visit::visit_mut_pre
and Visit::visit_mut_post
. Read more
sourcefn visit_mut_pre_post_nolimit<F1, F2>(&mut self, pre: &mut F1, post: &mut F2) where
F1: FnMut(&mut T) -> Option<Vec<&mut T, Global>>,
F2: FnMut(&mut T),
fn visit_mut_pre_post_nolimit<F1, F2>(&mut self, pre: &mut F1, post: &mut F2) where
F1: FnMut(&mut T) -> Option<Vec<&mut T, Global>>,
F2: FnMut(&mut T),
Use visit_mut_pre_post
instead.
A generalization of Visit::visit_mut_pre
and Visit::visit_mut_post
.
Does not enforce a recursion limit. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more