Uh oh!
There was an error while loading. Please reload this page.
Non-deprecated support for planning SQL without DDL, deprecate some more SessionContext methods - #4721
Non-deprecated support for planning SQL without DDL, deprecate some more SessionContext methods#4721alamb wants to merge 1 commit into
Conversation
beef643 to
e733070Comparee733070 to
c6291ffCompare| } | ||
| let plan = ctx.optimize(&plan)?; | ||
| let plan = ctx.dataframe(plan).await?.into_optimized_plan()?; |
There was a problem hiding this comment.
this is the new pattern to get an optimized plan (rather than calling ctx.optimize directly
| /// | ||
| /// This method is `async` because queries of type `CREATE | ||
| /// EXTERNAL TABLE` might require the schema to be inferred. | ||
| pub async fn sql(&self, sql: &str) -> Result<DataFrame> { |
There was a problem hiding this comment.
the core SessionContext::sql API does not change
| } | ||
| /// Creates a [`DataFrame`] that will execute the specified | ||
| /// LogicalPlan, including DDL such as (such as `CREATE TABLE`). |
There was a problem hiding this comment.
| /// LogicalPlan, including DDL such as (such as `CREATE TABLE`). | |
| /// LogicalPlan, including DDL (such as `CREATE TABLE`). |
| /// `CREATE TABLE` | ||
| /// | ||
| /// Use [`Self::dataframe`] to run plans with DDL | ||
| pub fn dataframe_without_ddl(&self, plan: LogicalPlan) -> Result<DataFrame> { |
There was a problem hiding this comment.
This appears to just be DataFrame new, do we really need this?
| // that the appropriate table can be registered with | ||
| // the context) | ||
| Err(DataFusionError::Internal( | ||
| Err(DataFusionError::Plan( |
There was a problem hiding this comment.
These are not really "internal errors" as they can be triggered by trying to run a sql query that contains DDL
There was a problem hiding this comment.
Imo this is a footgun we should aim to remove, I have a plan
There was a problem hiding this comment.
#4721 (comment) are the key usecases -- as long as they are possible / easy / well documented it will be great
c6291ff to
052caebCompare052caeb to
b9ff071CompareThere was a problem hiding this comment.
I'm really not a fan of introducing more complexity into this interface, part of the current mess is from there being 14 different ways to do everything, this appears to be putting back a quirk I'm actively trying to remove.
I think IOx should use the lower-level APIs, such as SessionState and DFParser, longer-term I don't think it should be using the interior mutable SessionContext at all
| pub fn create_logical_plan(&self, sql: &str) -> Result<LogicalPlan> { | ||
| /// Creates a [`LogicalPlan`] from a SQL query. | ||
| pub fn plan_sql(&self, sql: &str) -> Result<LogicalPlan> { |
There was a problem hiding this comment.
Again this appears to just call DFParser followed by the query planner
There was a problem hiding this comment.
It is also problematic for the same reason that create_logical_plan is problematic - it returns a LogicalPlan without any mechanism to optimise/execute against the same state
There was a problem hiding this comment.
Again this appears to just call DFParser followed by the query planner
Yes that is exactly what it does.
There needs to be some way for users to create a LogicalPlan and get datafusion to optimize and run it properly it (e.g. if the user makes the LogicalPlan directly from their own query language such as influxrpc or VegaFusion)
alamb
commented
Dec 24, 2022
I think some key capabilities for all users of DataFusion (including IOx) are:
As long as those are possible and well documented I do not have strong opinions on the API |
alamb
commented
Dec 24, 2022
Marking as a Draft as I think @tustvold plans an alternate proposal and we can continue to us the deprecated APIs in IOx for the time being |
tustvold
commented
Dec 24, 2022
I will work on this after christmas (27th). I think the key thing is to not be mixing high-level APIs i.e. SessionContext with low-level concepts LogicalPlan. The key thing is to ensure that planning, optimisation and execution take place against the same SessionState. The interior mutability of SessionContext makes this impossible |
tustvold
commented
Dec 27, 2022
POC in https://github.com/influxdata/influxdb_iox/pull/6469 - the TLDR is to use SessionState directly |
alamb
commented
Dec 28, 2022
This PR has been rendered obsolete via #4750 |
Which issue does this PR close?
Closes#4720
Part of #4617
Rationale for this change
More details on ticket #4720
Basically this moves the planning / execution in DataFusion to be based on DataFrame rather than some sort of mx of SessionContext / SessionState / DataFrame. Started by @tustvold in #4679
What changes are included in this PR?
SessionContext::dataframe_without_ddlSessionContext::optimizeandSessionContext::create_physical_planAre these changes tested?
Yes, existing tests
Are there any user-facing changes?