You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/10 21:37:15 UTC

[GitHub] [arrow-datafusion] matthewmturner commented on a change in pull request #1959: Add Create Schema functionality in SQL

matthewmturner commented on a change in pull request #1959:
URL: https://github.com/apache/arrow-datafusion/pull/1959#discussion_r824179001



##########
File path: datafusion/src/execution/context.rs
##########
@@ -283,6 +282,61 @@ impl ExecutionContext {
                     Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan)))
                 }
             }
+            LogicalPlan::CreateCatalogSchema(CreateCatalogSchema {
+                schema_name,
+                if_not_exists,
+                ..
+            }) => {
+                // sqlparser doesnt accept database / catalog as parameter to CREATE SCHEMA
+                // so for now, we default to "datafusion" catalog
+                let default_catalog = "datafusion";
+                let catalog = self.catalog(default_catalog).ok_or_else(|| {
+                    DataFusionError::Execution(String::from(
+                        "Missing 'datafusion' catalog",
+                    ))
+                })?;
+
+                let schema = catalog.schema(&schema_name);
+
+                match (if_not_exists, schema) {
+                    //
+                    (true, Some(_)) => {
+                        println!("Schema '{:?}' already exists", &schema_name);
+                        let plan = LogicalPlanBuilder::empty(false).build()?;
+                        Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan)))
+                    }
+                    (true, None) | (false, None) => {
+                        println!("Creating schema {:?}", schema_name);
+                        let schema = Arc::new(MemorySchemaProvider::new());
+                        let plan = LogicalPlanBuilder::empty(false).build()?;
+                        schema.register_table(
+                            "test".into(),
+                            Arc::new(DataFrameImpl::new(self.state.clone(), &plan)),
+                        )?;
+                        let schem_reg_res = catalog.register_schema(&schema_name, schema);

Review comment:
       It's not clear to me why registering schema here isnt working. I reregister the catalog below just in case but still has no effect.  I wasnt expecting to have to reregister.  Still digging deep into the implementations to get better idea whats going on.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org