tustvold commented on code in PR #4607:
URL: https://github.com/apache/arrow-datafusion/pull/4607#discussion_r1061412161
##########
datafusion/core/src/execution/context.rs:
##########
@@ -1641,6 +1619,97 @@ 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;
+
+ let mut statements = DFParser::parse_sql(sql)?;
+ 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 mut relations = hashbrown::HashSet::with_capacity(10);
+
+ match &statement {
+ DFStatement::Statement(s) => {
+ struct RelationVisitor<'a>(&'a mut
hashbrown::HashSet<ObjectName>);
+
+ impl<'a> Visitor for RelationVisitor<'a> {
+ type Break = ();
+
+ fn pre_visit_relation(
+ &mut self,
+ relation: &ObjectName,
+ ) -> ControlFlow<()> {
+ self.0.get_or_insert_with(relation, |_|
relation.clone());
+ ControlFlow::Continue(())
+ }
+
+ fn pre_visit_statement(
Review Comment:
This is a bit gross, but I hope to split apart the query planning from the
other types of query, that will clean this up.
--
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]