Trait SubstraitProducer

pub trait SubstraitProducer:
    Sized
    + Send
    + Sync {
Show 34 methods // Required methods fn register_function(&mut self, signature: String) -> u32; fn get_extensions(self) -> Extensions; // Provided methods fn handle_plan( &mut self, plan: &LogicalPlan, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_projection( &mut self, plan: &Projection, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_filter( &mut self, plan: &Filter, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_window( &mut self, plan: &Window, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_aggregate( &mut self, plan: &Aggregate, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_sort(&mut self, plan: &Sort) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_join(&mut self, plan: &Join) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_repartition( &mut self, plan: &Repartition, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_union( &mut self, plan: &Union, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_table_scan( &mut self, plan: &TableScan, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_empty_relation( &mut self, plan: &EmptyRelation, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_subquery_alias( &mut self, plan: &SubqueryAlias, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_limit( &mut self, plan: &Limit, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_values( &mut self, plan: &Values, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_distinct( &mut self, plan: &Distinct, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_extension( &mut self, _plan: &Extension, ) -> Result<Box<Rel>, DataFusionError> { ... } fn handle_expr( &mut self, expr: &Expr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_alias( &mut self, alias: &Alias, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_column( &mut self, column: &Column, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_literal( &mut self, value: &ScalarValue, ) -> Result<Expression, DataFusionError> { ... } fn handle_binary_expr( &mut self, expr: &BinaryExpr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_like( &mut self, like: &Like, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_unary_expr( &mut self, expr: &Expr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_between( &mut self, between: &Between, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_case( &mut self, case: &Case, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_cast( &mut self, cast: &Cast, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_try_cast( &mut self, cast: &TryCast, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_scalar_function( &mut self, scalar_fn: &ScalarFunction, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_aggregate_function( &mut self, agg_fn: &AggregateFunction, schema: &Arc<DFSchema>, ) -> Result<Measure, DataFusionError> { ... } fn handle_window_function( &mut self, window_fn: &WindowFunction, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_in_list( &mut self, in_list: &InList, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... } fn handle_in_subquery( &mut self, in_subquery: &InSubquery, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError> { ... }
}
Expand description

This trait is used to produce Substrait plans, converting them from DataFusion Logical Plans. It can be implemented by users to allow for custom handling of relations, expressions, etc.

Combined with the crate::logical_plan::consumer::SubstraitConsumer this allows for fully customizable Substrait serde.

§Example Usage


struct CustomSubstraitProducer {
    extensions: Extensions,
    state: Arc<SessionState>,
}

impl SubstraitProducer for CustomSubstraitProducer {

    fn register_function(&mut self, signature: String) -> u32 {
       self.extensions.register_function(signature)
    }

    fn get_extensions(self) -> Extensions {
        self.extensions
    }

    // You can set additional metadata on the Rels you produce
    fn handle_projection(&mut self, plan: &Projection) -> Result<Box<Rel>> {
        let mut rel = from_projection(self, plan)?;
        match rel.rel_type {
            Some(RelType::Project(mut project)) => {
                let mut project = project.clone();
                // set common metadata or advanced extension
                project.common = None;
                project.advanced_extension = None;
                Ok(Box::new(Rel {
                    rel_type: Some(RelType::Project(project)),
                }))
            }
            rel_type => Ok(Box::new(Rel { rel_type })),
       }
    }

    // You can tweak how you convert expressions for your target system
    fn handle_between(&mut self, between: &Between, schema: &DFSchemaRef) -> Result<Expression> {
       // add your own encoding for Between
       todo!()
   }

    // You can fully control how you convert UserDefinedLogicalNodes into Substrait
    fn handle_extension(&mut self, _plan: &Extension) -> Result<Box<Rel>> {
        // implement your own serializer into Substrait
       todo!()
   }
}

Required Methods§

fn register_function(&mut self, signature: String) -> u32

Within a Substrait plan, functions are referenced using function anchors that are stored at the top level of the [Plan] within ExtensionFunction messages.

When given a function signature, this method should return the existing anchor for it if there is one. Otherwise, it should generate a new anchor.

fn get_extensions(self) -> Extensions

Consume the producer to generate the [Extensions] for the Substrait plan based on the functions that have been registered

Provided Methods§

fn handle_plan( &mut self, plan: &LogicalPlan, ) -> Result<Box<Rel>, DataFusionError>

fn handle_projection( &mut self, plan: &Projection, ) -> Result<Box<Rel>, DataFusionError>

fn handle_filter(&mut self, plan: &Filter) -> Result<Box<Rel>, DataFusionError>

fn handle_window(&mut self, plan: &Window) -> Result<Box<Rel>, DataFusionError>

fn handle_aggregate( &mut self, plan: &Aggregate, ) -> Result<Box<Rel>, DataFusionError>

fn handle_sort(&mut self, plan: &Sort) -> Result<Box<Rel>, DataFusionError>

fn handle_join(&mut self, plan: &Join) -> Result<Box<Rel>, DataFusionError>

fn handle_repartition( &mut self, plan: &Repartition, ) -> Result<Box<Rel>, DataFusionError>

fn handle_union(&mut self, plan: &Union) -> Result<Box<Rel>, DataFusionError>

fn handle_table_scan( &mut self, plan: &TableScan, ) -> Result<Box<Rel>, DataFusionError>

fn handle_empty_relation( &mut self, plan: &EmptyRelation, ) -> Result<Box<Rel>, DataFusionError>

fn handle_subquery_alias( &mut self, plan: &SubqueryAlias, ) -> Result<Box<Rel>, DataFusionError>

fn handle_limit(&mut self, plan: &Limit) -> Result<Box<Rel>, DataFusionError>

fn handle_values(&mut self, plan: &Values) -> Result<Box<Rel>, DataFusionError>

fn handle_distinct( &mut self, plan: &Distinct, ) -> Result<Box<Rel>, DataFusionError>

fn handle_extension( &mut self, _plan: &Extension, ) -> Result<Box<Rel>, DataFusionError>

fn handle_expr( &mut self, expr: &Expr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_alias( &mut self, alias: &Alias, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_column( &mut self, column: &Column, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_literal( &mut self, value: &ScalarValue, ) -> Result<Expression, DataFusionError>

fn handle_binary_expr( &mut self, expr: &BinaryExpr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_like( &mut self, like: &Like, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_unary_expr( &mut self, expr: &Expr, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

For handling Not, IsNotNull, IsNull, IsTrue, IsFalse, IsUnknown, IsNotTrue, IsNotFalse, IsNotUnknown, Negative

fn handle_between( &mut self, between: &Between, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_case( &mut self, case: &Case, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_cast( &mut self, cast: &Cast, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_try_cast( &mut self, cast: &TryCast, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_scalar_function( &mut self, scalar_fn: &ScalarFunction, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_aggregate_function( &mut self, agg_fn: &AggregateFunction, schema: &Arc<DFSchema>, ) -> Result<Measure, DataFusionError>

fn handle_window_function( &mut self, window_fn: &WindowFunction, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_in_list( &mut self, in_list: &InList, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

fn handle_in_subquery( &mut self, in_subquery: &InSubquery, schema: &Arc<DFSchema>, ) -> Result<Expression, DataFusionError>

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§