gruuya commented on code in PR #4958:
URL: https://github.com/apache/arrow-datafusion/pull/4958#discussion_r1073510915
##########
datafusion/core/src/execution/context.rs:
##########
@@ -1729,6 +1741,15 @@ impl SessionState {
query.statement_to_plan(statement)
}
+ /// Creates a [`LogicalPlan`] from the provided SQL string
+ ///
+ /// See [`SessionContext::sql`] for a higher-level interface that also
handles DDL
+ pub async fn create_logical_plan(&self, sql: &str) -> Result<LogicalPlan> {
+ let statement = self.sql_to_statement(sql)?;
+ let plan = self.statement_to_plan(statement).await?;
+ Ok(plan)
+ }
Review Comment:
It may be too late by now, but I have a slightly different proposal for this
issue (thanks for addressing it btw!).
Namely, while this solution handles the stated case well it doesn't address
the general problem of `SqlToRel` now being hard/impossible to instantiate
properly (with the new trait bound for `ContextProvider`, which is only
implemented for a private struct, and the entire `information_schema` module
also being private further complicating a custom implementation of
`ContextProvider`). This in turn forbids usage of other useful public
`SqlToRel` methods, such as `sql_to_expr`.
My proposal would be to simply rename `statement_to_plan` to
`statement_to_planner`, and then return `SqlToRel::new(&provider)` at line
1740. Subsequently, to address the original issue just revise this part:
```suggestion
pub async fn create_logical_plan(&self, sql: &str) ->
Result<LogicalPlan> {
let statement = self.sql_to_statement(sql)?;
let planner = self.statement_to_planner(statement).await?;
let plan = planner.statement_to_plan(statement);
Ok(plan)
}
```
while anyone else can then get easy access to the planner.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]