pub trait SubstraitProducer:
Send
+ Sync
+ Sized {
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>> { ... }
fn handle_projection(&mut self, plan: &Projection) -> Result<Box<Rel>> { ... }
fn handle_filter(&mut self, plan: &Filter) -> Result<Box<Rel>> { ... }
fn handle_window(&mut self, plan: &Window) -> Result<Box<Rel>> { ... }
fn handle_aggregate(&mut self, plan: &Aggregate) -> Result<Box<Rel>> { ... }
fn handle_sort(&mut self, plan: &Sort) -> Result<Box<Rel>> { ... }
fn handle_join(&mut self, plan: &Join) -> Result<Box<Rel>> { ... }
fn handle_repartition(&mut self, plan: &Repartition) -> Result<Box<Rel>> { ... }
fn handle_union(&mut self, plan: &Union) -> Result<Box<Rel>> { ... }
fn handle_table_scan(&mut self, plan: &TableScan) -> Result<Box<Rel>> { ... }
fn handle_empty_relation(
&mut self,
plan: &EmptyRelation,
) -> Result<Box<Rel>> { ... }
fn handle_subquery_alias(
&mut self,
plan: &SubqueryAlias,
) -> Result<Box<Rel>> { ... }
fn handle_limit(&mut self, plan: &Limit) -> Result<Box<Rel>> { ... }
fn handle_values(&mut self, plan: &Values) -> Result<Box<Rel>> { ... }
fn handle_distinct(&mut self, plan: &Distinct) -> Result<Box<Rel>> { ... }
fn handle_extension(&mut self, _plan: &Extension) -> Result<Box<Rel>> { ... }
fn handle_expr(
&mut self,
expr: &Expr,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_alias(
&mut self,
alias: &Alias,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_column(
&mut self,
column: &Column,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_literal(&mut self, value: &ScalarValue) -> Result<Expression> { ... }
fn handle_binary_expr(
&mut self,
expr: &BinaryExpr,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_like(
&mut self,
like: &Like,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_unary_expr(
&mut self,
expr: &Expr,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_between(
&mut self,
between: &Between,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_case(
&mut self,
case: &Case,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_cast(
&mut self,
cast: &Cast,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_try_cast(
&mut self,
cast: &TryCast,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_scalar_function(
&mut self,
scalar_fn: &ScalarFunction,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_aggregate_function(
&mut self,
agg_fn: &AggregateFunction,
schema: &DFSchemaRef,
) -> Result<Measure> { ... }
fn handle_window_function(
&mut self,
window_fn: &WindowFunction,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_in_list(
&mut self,
in_list: &InList,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
fn handle_in_subquery(
&mut self,
in_subquery: &InSubquery,
schema: &DFSchemaRef,
) -> Result<Expression> { ... }
}
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§
Sourcefn register_function(&mut self, signature: String) -> u32
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.
Sourcefn get_extensions(self) -> Extensions
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>>
fn handle_projection(&mut self, plan: &Projection) -> Result<Box<Rel>>
fn handle_filter(&mut self, plan: &Filter) -> Result<Box<Rel>>
fn handle_window(&mut self, plan: &Window) -> Result<Box<Rel>>
fn handle_aggregate(&mut self, plan: &Aggregate) -> Result<Box<Rel>>
fn handle_sort(&mut self, plan: &Sort) -> Result<Box<Rel>>
fn handle_join(&mut self, plan: &Join) -> Result<Box<Rel>>
fn handle_repartition(&mut self, plan: &Repartition) -> Result<Box<Rel>>
fn handle_union(&mut self, plan: &Union) -> Result<Box<Rel>>
fn handle_table_scan(&mut self, plan: &TableScan) -> Result<Box<Rel>>
fn handle_empty_relation(&mut self, plan: &EmptyRelation) -> Result<Box<Rel>>
fn handle_subquery_alias(&mut self, plan: &SubqueryAlias) -> Result<Box<Rel>>
fn handle_limit(&mut self, plan: &Limit) -> Result<Box<Rel>>
fn handle_values(&mut self, plan: &Values) -> Result<Box<Rel>>
fn handle_distinct(&mut self, plan: &Distinct) -> Result<Box<Rel>>
fn handle_extension(&mut self, _plan: &Extension) -> Result<Box<Rel>>
fn handle_expr( &mut self, expr: &Expr, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_alias( &mut self, alias: &Alias, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_column( &mut self, column: &Column, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_literal(&mut self, value: &ScalarValue) -> Result<Expression>
fn handle_binary_expr( &mut self, expr: &BinaryExpr, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_like( &mut self, like: &Like, schema: &DFSchemaRef, ) -> Result<Expression>
Sourcefn handle_unary_expr(
&mut self,
expr: &Expr,
schema: &DFSchemaRef,
) -> Result<Expression>
fn handle_unary_expr( &mut self, expr: &Expr, schema: &DFSchemaRef, ) -> Result<Expression>
For handling Not, IsNotNull, IsNull, IsTrue, IsFalse, IsUnknown, IsNotTrue, IsNotFalse, IsNotUnknown, Negative
fn handle_between( &mut self, between: &Between, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_case( &mut self, case: &Case, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_cast( &mut self, cast: &Cast, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_try_cast( &mut self, cast: &TryCast, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_scalar_function( &mut self, scalar_fn: &ScalarFunction, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_aggregate_function( &mut self, agg_fn: &AggregateFunction, schema: &DFSchemaRef, ) -> Result<Measure>
fn handle_window_function( &mut self, window_fn: &WindowFunction, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_in_list( &mut self, in_list: &InList, schema: &DFSchemaRef, ) -> Result<Expression>
fn handle_in_subquery( &mut self, in_subquery: &InSubquery, schema: &DFSchemaRef, ) -> Result<Expression>
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.