Skip to content

Allow extension nodes to correctly plan physical expressions with relations #642

@alamb

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
In IOx we have several extension nodes with Exprs which we want to compile to PhysicalExpr as part of a plan

This was previously annoying as the signature of the extension planner is:

    fn plan_extension(
        &self,
        node: &dyn UserDefinedLogicalNode,
        inputs: &[Arc<dyn ExecutionPlan>],
        ctx_state: &ExecutionContextState,
    ) -> Result<Option<Arc<dyn ExecutionPlan>>> {

Which offers no way to plan physical expressions, so I had to do something like the following workaround

            // create physical expressions in extension planner)
            let input_schema = inputs[0].schema();
            let physical_planner = DefaultPhysicalPlanner::default();
            let split_expr = physical_planner.create_physical_expr(
                stream_split.split_expr(),
                &input_schema,
                ctx_state,
            )?;

However, with the introduction of qualified names, now I have to provide a DFSchema (which should have come from the input LogicalPlan which I do not have access to at this point).

            // create physical expressions in extension planner)
            let input_schema = inputs[0].schema();
            let input_df_schema = DFSchema::try_from_qualified_schema("foo", &input_schema).unwrap();
            let physical_planner = DefaultPhysicalPlanner::default();
            let split_expr = physical_planner.create_physical_expr(
                stream_split.split_expr(),
                &input_df_schema,
                &input_schema,
                ctx_state,
            )?;

(note the "foo" needs to be the correct table name"

Describe the solution you'd like

  1. Add create_physical_expr to the PhysicalPlanner trait
  2. Pass an instance of the planner to the plan extension (rather than a ctx_state)
  3. Pass the input logical schema to each "plan extension" call as well

Basically as the internals of DataFusion evolve we also need to evolve the interfaces along with it.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions