pub trait VTable:
'static
+ Sized
+ Send
+ Sync {
type Options: 'static + Send + Sync + Clone + Debug + Display + PartialEq + Eq + Hash;
Show 16 methods
// Required methods
fn id(&self) -> ExprId;
fn arity(&self, options: &Self::Options) -> Arity;
fn child_name(&self, options: &Self::Options, child_idx: usize) -> ChildName;
fn fmt_sql(
&self,
options: &Self::Options,
expr: &Expression,
f: &mut Formatter<'_>,
) -> Result;
fn return_dtype(
&self,
options: &Self::Options,
arg_dtypes: &[DType],
) -> VortexResult<DType>;
// Provided methods
fn serialize(
&self,
options: &Self::Options,
) -> VortexResult<Option<Vec<u8>>> { ... }
fn deserialize(&self, _metadata: &[u8]) -> VortexResult<Self::Options> { ... }
fn evaluate(
&self,
options: &Self::Options,
expr: &Expression,
scope: &ArrayRef,
) -> VortexResult<ArrayRef> { ... }
fn execute(
&self,
options: &Self::Options,
args: ExecutionArgs,
) -> VortexResult<Datum> { ... }
fn reduce(
&self,
options: &Self::Options,
node: &dyn ReduceNode,
ctx: &dyn ReduceCtx,
) -> VortexResult<Option<ReduceNodeRef>> { ... }
fn simplify(
&self,
options: &Self::Options,
expr: &Expression,
ctx: &dyn SimplifyCtx,
) -> VortexResult<Option<Expression>> { ... }
fn simplify_untyped(
&self,
options: &Self::Options,
expr: &Expression,
) -> VortexResult<Option<Expression>> { ... }
fn stat_falsification(
&self,
options: &Self::Options,
expr: &Expression,
catalog: &dyn StatsCatalog,
) -> Option<Expression> { ... }
fn stat_expression(
&self,
options: &Self::Options,
expr: &Expression,
stat: Stat,
catalog: &dyn StatsCatalog,
) -> Option<Expression> { ... }
fn is_null_sensitive(&self, options: &Self::Options) -> bool { ... }
fn is_fallible(&self, options: &Self::Options) -> bool { ... }
}Expand description
This trait defines the interface for expression vtables, including methods for serialization, deserialization, validation, child naming, return type computation, and evaluation.
This trait is non-object safe and allows the implementer to make use of associated types for improved type safety, while allowing Vortex to enforce runtime checks on the inputs and outputs of each function.
The VTable trait should be implemented for a struct that holds global data across
all instances of the expression. In almost all cases, this struct will be an empty unit
struct, since most expressions do not require any global state.
Required Associated Types§
Required Methods§
Sourcefn child_name(&self, options: &Self::Options, child_idx: usize) -> ChildName
fn child_name(&self, options: &Self::Options, child_idx: usize) -> ChildName
Returns the name of the nth child of the expr.
Sourcefn fmt_sql(
&self,
options: &Self::Options,
expr: &Expression,
f: &mut Formatter<'_>,
) -> Result
fn fmt_sql( &self, options: &Self::Options, expr: &Expression, f: &mut Formatter<'_>, ) -> Result
Format this expression in nice human-readable SQL-style format
The implementation should recursively format child expressions by calling
expr.child(i).fmt_sql(f).
Sourcefn return_dtype(
&self,
options: &Self::Options,
arg_dtypes: &[DType],
) -> VortexResult<DType>
fn return_dtype( &self, options: &Self::Options, arg_dtypes: &[DType], ) -> VortexResult<DType>
Compute the return DType of the expression if evaluated over the given input types.
Provided Methods§
Sourcefn serialize(&self, options: &Self::Options) -> VortexResult<Option<Vec<u8>>>
fn serialize(&self, options: &Self::Options) -> VortexResult<Option<Vec<u8>>>
Serialize the options for this expression.
Should return Ok(None) if the expression is not serializable, and Ok(vec![]) if it is
serializable but has no metadata.
Sourcefn deserialize(&self, _metadata: &[u8]) -> VortexResult<Self::Options>
fn deserialize(&self, _metadata: &[u8]) -> VortexResult<Self::Options>
Deserialize the options of this expression.
Sourcefn evaluate(
&self,
options: &Self::Options,
expr: &Expression,
scope: &ArrayRef,
) -> VortexResult<ArrayRef>
fn evaluate( &self, options: &Self::Options, expr: &Expression, scope: &ArrayRef, ) -> VortexResult<ArrayRef>
Evaluate the expression in the given scope.
This function will be deprecated in a future release in favor of VTable::execute.
Sourcefn execute(
&self,
options: &Self::Options,
args: ExecutionArgs,
) -> VortexResult<Datum>
fn execute( &self, options: &Self::Options, args: ExecutionArgs, ) -> VortexResult<Datum>
Execute the expression on the given vector with the given dtype.
This function will become required in a future release.
Sourcefn reduce(
&self,
options: &Self::Options,
node: &dyn ReduceNode,
ctx: &dyn ReduceCtx,
) -> VortexResult<Option<ReduceNodeRef>>
fn reduce( &self, options: &Self::Options, node: &dyn ReduceNode, ctx: &dyn ReduceCtx, ) -> VortexResult<Option<ReduceNodeRef>>
Implement an abstract reduction rule over a tree of scalar functions.
The ReduceNode can be used to traverse children, inspect their types, and
construct the result expression.
Return Ok(None) if no reduction is possible.
Sourcefn simplify(
&self,
options: &Self::Options,
expr: &Expression,
ctx: &dyn SimplifyCtx,
) -> VortexResult<Option<Expression>>
fn simplify( &self, options: &Self::Options, expr: &Expression, ctx: &dyn SimplifyCtx, ) -> VortexResult<Option<Expression>>
Simplify the expression if possible.
Sourcefn simplify_untyped(
&self,
options: &Self::Options,
expr: &Expression,
) -> VortexResult<Option<Expression>>
fn simplify_untyped( &self, options: &Self::Options, expr: &Expression, ) -> VortexResult<Option<Expression>>
Simplify the expression if possible, without type information.
Sourcefn stat_falsification(
&self,
options: &Self::Options,
expr: &Expression,
catalog: &dyn StatsCatalog,
) -> Option<Expression>
fn stat_falsification( &self, options: &Self::Options, expr: &Expression, catalog: &dyn StatsCatalog, ) -> Option<Expression>
Sourcefn stat_expression(
&self,
options: &Self::Options,
expr: &Expression,
stat: Stat,
catalog: &dyn StatsCatalog,
) -> Option<Expression>
fn stat_expression( &self, options: &Self::Options, expr: &Expression, stat: Stat, catalog: &dyn StatsCatalog, ) -> Option<Expression>
Sourcefn is_null_sensitive(&self, options: &Self::Options) -> bool
fn is_null_sensitive(&self, options: &Self::Options) -> bool
Returns whether this expression itself is null-sensitive. Conservatively default to true.
An expression is null-sensitive if it directly operates on null values,
such as is_null. Most expressions are not null-sensitive.
The property we are interested in is if the expression (e) distributes over mask.
Define a mask(a, m) expression that applies the boolean array m to the validity of the
array a.
A unary expression e is not null-sensitive iff forall arrays a and masks m,
e(mask(a, m)) == mask(e(a), m).
This can be extended to an n-ary expression.
This method only checks the expression itself, not its children.
Sourcefn is_fallible(&self, options: &Self::Options) -> bool
fn is_fallible(&self, options: &Self::Options) -> bool
Returns whether this expression itself is fallible. Conservatively default to true.
An expression is runtime fallible is there is an input set that causes the expression to panic or return an error, for example checked_add is fallible if there is overflow.
Note: this is only applicable to expressions that pass type-checking
VTable::return_dtype.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.