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


##########
datafusion/core/src/execution/context.rs:
##########
@@ -1636,22 +1636,34 @@ impl SessionState {
         self
     }
 
-    /// 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> {
-        use crate::catalog::information_schema::INFORMATION_SCHEMA_TABLES;
-        use datafusion_sql::parser::Statement as DFStatement;
-        use sqlparser::ast::*;
-        use std::collections::hash_map::Entry;
-
+    /// Convert a sql string into an ast Statement
+    pub fn sql_to_statement(
+        &self,
+        sql: &str,
+    ) -> Result<datafusion_sql::parser::Statement> {
         let mut statements = DFParser::parse_sql(sql)?;
-        if statements.len() != 1 {
+        if statements.len() > 1 {
             return Err(DataFusionError::NotImplemented(
                 "The context currently only supports a single SQL 
statement".to_string(),
             ));
         }
-        let statement = statements.pop_front().unwrap();
+        let statement = statements.pop_front().ok_or_else(|| {
+            DataFusionError::NotImplemented(
+                "The context requires a statement!".to_string(),
+            )
+        })?;
+        Ok(statement)
+    }
+
+    /// Convert an ast Statement into a LogicalPlan
+    pub async fn statement_to_plan(
+        &self,
+        statement: datafusion_sql::parser::Statement,
+    ) -> Result<LogicalPlan> {
+        use crate::catalog::information_schema::INFORMATION_SCHEMA_TABLES;
+        use datafusion_sql::parser::Statement as DFStatement;
+        use sqlparser::ast::*;
+        use std::collections::hash_map::Entry;

Review Comment:
   These `use` statements seem out of place 🤔 
   



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