VTable

Trait VTable 

Source
pub trait VTable:
    'static
    + Sized
    + Send
    + Sync {
    type Instance: 'static + Send + Sync + Debug + PartialEq + Eq + Hash;

Show 14 methods // Required methods fn id(&self) -> ExprId; fn validate(&self, expr: &ExpressionView<'_, Self>) -> VortexResult<()>; fn child_name( &self, instance: &Self::Instance, child_idx: usize, ) -> ChildName; fn fmt_sql( &self, expr: &ExpressionView<'_, Self>, f: &mut Formatter<'_>, ) -> Result; fn return_dtype( &self, expr: &ExpressionView<'_, Self>, scope: &DType, ) -> VortexResult<DType>; fn evaluate( &self, expr: &ExpressionView<'_, Self>, scope: &ArrayRef, ) -> VortexResult<ArrayRef>; // Provided methods fn serialize( &self, instance: &Self::Instance, ) -> VortexResult<Option<Vec<u8>>> { ... } fn deserialize( &self, metadata: &[u8], ) -> VortexResult<Option<Self::Instance>> { ... } fn fmt_data( &self, instance: &Self::Instance, f: &mut Formatter<'_>, ) -> Result { ... } fn execute( &self, data: &Self::Instance, args: ExecutionArgs, ) -> VortexResult<Vector> { ... } fn stat_falsification( &self, expr: &ExpressionView<'_, Self>, catalog: &dyn StatsCatalog, ) -> Option<Expression> { ... } fn stat_expression( &self, expr: &ExpressionView<'_, Self>, stat: Stat, catalog: &dyn StatsCatalog, ) -> Option<Expression> { ... } fn is_null_sensitive(&self, instance: &Self::Instance) -> bool { ... } fn is_fallible(&self, instance: &Self::Instance) -> 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§

Source

type Instance: 'static + Send + Sync + Debug + PartialEq + Eq + Hash

Instance data for this expression.

Required Methods§

Source

fn id(&self) -> ExprId

Returns the ID of the expr vtable.

Source

fn validate(&self, expr: &ExpressionView<'_, Self>) -> VortexResult<()>

Validate the metadata and children for the expression.

Source

fn child_name(&self, instance: &Self::Instance, child_idx: usize) -> ChildName

Returns the name of the nth child of the expr.

Source

fn fmt_sql( &self, expr: &ExpressionView<'_, Self>, 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).

Source

fn return_dtype( &self, expr: &ExpressionView<'_, Self>, scope: &DType, ) -> VortexResult<DType>

Compute the return DType of the expression if evaluated in the given scope.

Source

fn evaluate( &self, expr: &ExpressionView<'_, Self>, scope: &ArrayRef, ) -> VortexResult<ArrayRef>

Evaluate the expression in the given scope.

Provided Methods§

Source

fn serialize(&self, instance: &Self::Instance) -> VortexResult<Option<Vec<u8>>>

Serialize the metadata for the expression.

Should return Ok(None) if the expression is not serializable, and Ok(vec![]) if it is serializable but has no metadata.

Source

fn deserialize(&self, metadata: &[u8]) -> VortexResult<Option<Self::Instance>>

Deserialize an instance of this expression.

Returns Ok(None) if the expression is not serializable.

Source

fn fmt_data(&self, instance: &Self::Instance, f: &mut Formatter<'_>) -> Result

Format only the instance data for this expression.

Defaults to a debug representation of the instance data.

Source

fn execute( &self, data: &Self::Instance, args: ExecutionArgs, ) -> VortexResult<Vector>

Execute the expression on the given vector with the given dtype.

Source

fn stat_falsification( &self, expr: &ExpressionView<'_, Self>, catalog: &dyn StatsCatalog, ) -> Option<Expression>

Source

fn stat_expression( &self, expr: &ExpressionView<'_, Self>, stat: Stat, catalog: &dyn StatsCatalog, ) -> Option<Expression>

Source

fn is_null_sensitive(&self, instance: &Self::Instance) -> 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. An unary expression e to be 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. To check if an expression or any of its descendants are null-sensitive.

Source

fn is_fallible(&self, instance: &Self::Instance) -> 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.

Implementors§