Skip to content

Split create_logical_plan() into parsing and planning #4957

@avantgardnerio

Description

@avantgardnerio

Describe the bug

It's not really a bug, more of an API regression. When #4607 got merged, consumers of the DataFusion public API lost the ability to (easily) inspect or alter the AST of a SQL statement before it got planned. This is because the function that runs it became non-trivial in that it copies tables into a new context, so now the consumer would either have to duplicate the table copying logic, or go without.

To Reproduce

This used to work:

        let statements = DFParser::parse_sql(sql)?;
        let statements: Vec<_> = statements.into_iter().collect();

       // Do something with AST here

        let state = df_ctx.state();
        let planner = SqlToRel::new(&state);
        let plan = planner.statement_to_plan(stmt).map_err(|e| err!("", e))?;
        let df = Arc::new(DataFrame::new(df_ctx.state(), plan));

But now it yields: ContextProvider not implented for SessionState

Expected behavior

A way to parse, manipulate AST, then plan separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions