You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/04/25 19:44:19 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request, #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

alamb opened a new pull request, #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121

   # Which issue does this PR close?
   
   Part of https://github.com/apache/arrow-datafusion/issues/1281
   
   # Rationale for this change
   
   While reviewing https://github.com/apache/arrow-datafusion/pull/6096 I noticed that the LogialPlan was getting quite large for the various Catalog manipulation statements
   
   
   
   # What changes are included in this PR?
   
   Thus I think it is time to finally implement https://github.com/apache/arrow-datafusion/issues/1281 and isolate these a bit more
   
   Before I went and changed everything though I figured I would put up an RFC that moves the `CREATE*` DDLs over. I think it looks much nicer.
   
   I will add the DROP variants (like `DropTable` as a follow on PR
   
   # Are these changes tested?
   
   Covered by existing tests
   
   # Are there any user-facing changes?
   Yes, this is an API change


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


[GitHub] [arrow-datafusion] alamb merged pull request #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121


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


[GitHub] [arrow-datafusion] alamb commented on pull request #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121#issuecomment-1523198170

   I wonder if you have any thoughts about this change @avantgardnerio @andygrove or @liukun4515 


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


[GitHub] [arrow-datafusion] alamb commented on pull request #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121#issuecomment-1526427186

   I broke the build with this one :sad -- fix https://github.com/apache/arrow-datafusion/pull/6143


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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121#discussion_r1177017771


##########
datafusion/core/src/execution/context.rs:
##########
@@ -628,6 +488,159 @@ impl SessionContext {
         self.return_empty_dataframe()
     }
 
+    async fn create_memory_table(&self, cmd: CreateMemoryTable) -> Result<DataFrame> {

Review Comment:
   Moved from above



##########
datafusion/expr/src/lib.rs:
##########
@@ -66,20 +66,7 @@ pub use function::{
     StateTypeFunction,
 };
 pub use literal::{lit, lit_timestamp_nano, Literal, TimestampLiteral};
-pub use logical_plan::{
-    builder::{
-        build_join_schema, union, wrap_projection_for_join_if_necessary, UNNAMED_TABLE,
-    },
-    Aggregate, Analyze, CreateCatalog, CreateCatalogSchema, CreateExternalTable,
-    CreateMemoryTable, CreateView, CrossJoin, DescribeTable, Distinct, DmlStatement,
-    DropTable, DropView, EmptyRelation, Explain, Extension, Filter, Join, JoinConstraint,
-    JoinType, Limit, LogicalPlan, LogicalPlanBuilder, Partitioning, PlanType, Prepare,
-    Projection, Repartition, SetVariable, Sort, Statement, StringifiedPlan, Subquery,
-    SubqueryAlias, TableScan, ToStringifiedPlan, TransactionAccessMode,
-    TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
-    Union, Unnest, UserDefinedLogicalNode, UserDefinedLogicalNodeCore, Values, Window,
-    WriteOp,
-};
+pub use logical_plan::*;

Review Comment:
   this code was just re-exporting all the names in logical_plan anyways so I reduced the duplication



##########
datafusion/core/src/execution/context.rs:
##########
@@ -351,88 +352,19 @@ impl SessionContext {
                 }
                 self.return_empty_dataframe()
             }
-            LogicalPlan::CreateExternalTable(cmd) => {
-                self.create_external_table(&cmd).await
-            }
-
-            LogicalPlan::CreateMemoryTable(CreateMemoryTable {

Review Comment:
   I moved this code into separate methods as this particular dispatch method was getting quite large



##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -1087,13 +1087,14 @@ impl DefaultPhysicalPlanner {
                     let schema = SchemaRef::new(schema.as_ref().to_owned().into());
                     Ok(Arc::new(UnnestExec::new(input, column_exec, schema)))
                 }
-                LogicalPlan::CreateExternalTable(_) => {
-                    // There is no default plan for "CREATE EXTERNAL
-                    // TABLE" -- it must be handled at a higher level (so
-                    // that the appropriate table can be registered with
+                LogicalPlan::Ddl(ddl) => {

Review Comment:
   I think this reduction of repetition makes the intent of the code clearer



##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -1190,28 +1130,6 @@ pub enum JoinConstraint {
     Using,
 }
 
-/// Creates a catalog (aka "Database").

Review Comment:
   moved to `ddl.rs`



##########
datafusion/expr/src/logical_plan/ddl.rs:
##########
@@ -0,0 +1,233 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion_common::Column;
+use datafusion_common::{
+    parsers::CompressionTypeVariant, DFSchemaRef, OwnedTableReference,
+};
+use std::collections::HashMap;
+use std::sync::Arc;
+use std::{
+    fmt::{self, Display},
+    hash::{Hash, Hasher},
+};
+
+use crate::{Expr, LogicalPlan};
+
+/// Various types of DDL  (CREATE / DROP) catalog manipulation
+#[derive(Clone, PartialEq, Eq, Hash)]
+pub enum DdlStatement {

Review Comment:
   This is the new wrapper enum



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


[GitHub] [arrow-datafusion] alamb commented on pull request #6121: Extract `LogicalPlan::Create*` DDL related plan structures into `LogicalPlan::Ddl`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6121:
URL: https://github.com/apache/arrow-datafusion/pull/6121#issuecomment-1526427794

   FWIW here is the follow on PR to move the `DROP` variants : https://github.com/apache/arrow-datafusion/pull/6144


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