alamb commented on code in PR #4958:
URL: https://github.com/apache/arrow-datafusion/pull/4958#discussion_r1073840524


##########
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:
   > 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.
   
   @gruuya I don't think we have contemplated using `SqlToRel` directly in the 
past. If that is a usecase that is important, what I found works well is to 
make an example demonstrating what you are doing. Here are some examples:
   
   * 
https://github.com/apache/arrow-datafusion/blob/master/datafusion-examples/examples/rewrite_expr.rs
   * 
https://github.com/apache/arrow-datafusion/blob/master/datafusion-examples/examples/custom_datasource.rs
   
   
   An example has several advantages:
   1. It ensures your usecase is clearly documented so people who are changing 
DataFusion know it is used and don't break it accidentally 
   3. It then gives you an example to start from if the interface changes (you 
can look at the example to see how the interface may have changed)
   4. It helps others who might have the same need
   



-- 
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]

Reply via email to