This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f95966cc refactor: correct the implementation of `all_schemas()` 
(#5236)
0f95966cc is described below

commit 0f95966cc28d2ff55c225d8522027d61cdcdf4af
Author: jakevin <[email protected]>
AuthorDate: Sun Feb 12 21:57:16 2023 +0800

    refactor: correct the implementation of `all_schemas()` (#5236)
    
    * refactor: correct the implementation of `all_schemas()`
    
    * correct comment
---
 datafusion/expr/src/logical_plan/plan.rs | 84 +++++++++++++++-----------------
 1 file changed, 38 insertions(+), 46 deletions(-)

diff --git a/datafusion/expr/src/logical_plan/plan.rs 
b/datafusion/expr/src/logical_plan/plan.rs
index 8f8c4fd65..d86a44e5d 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -174,62 +174,54 @@ impl LogicalPlan {
         }
     }
 
-    /// Get a vector of references to all schemas in every node of the logical 
plan
+    /// Get all meaningful schemas of a plan and its children plan.
     pub fn all_schemas(&self) -> Vec<&DFSchemaRef> {
         match self {
-            LogicalPlan::TableScan(TableScan {
-                projected_schema, ..
-            }) => vec![projected_schema],
-            LogicalPlan::Window(Window { input, schema, .. })
-            | LogicalPlan::Projection(Projection { input, schema, .. })
-            | LogicalPlan::Aggregate(Aggregate { input, schema, .. })
-            | LogicalPlan::Unnest(Unnest { input, schema, .. }) => {
-                let mut schemas = input.all_schemas();
-                schemas.insert(0, schema);
+            // return self and children schemas
+            LogicalPlan::Window(_)
+            | LogicalPlan::Projection(_)
+            | LogicalPlan::Aggregate(_)
+            | LogicalPlan::Unnest(_)
+            | LogicalPlan::Join(_)
+            | LogicalPlan::CrossJoin(_) => {
+                let mut schemas = vec![self.schema()];
+                self.inputs().iter().for_each(|input| {
+                    schemas.push(input.schema());
+                });
                 schemas
             }
-            LogicalPlan::Join(Join {
-                left,
-                right,
-                schema,
-                ..
-            })
-            | LogicalPlan::CrossJoin(CrossJoin {
-                left,
-                right,
-                schema,
-            }) => {
-                let mut schemas = left.all_schemas();
-                schemas.extend(right.all_schemas());
-                schemas.insert(0, schema);
-                schemas
+            // just return self.schema()
+            LogicalPlan::Explain(_)
+            | LogicalPlan::Analyze(_)
+            | LogicalPlan::EmptyRelation(_)
+            | LogicalPlan::CreateExternalTable(_)
+            | LogicalPlan::CreateCatalogSchema(_)
+            | LogicalPlan::CreateCatalog(_)
+            | LogicalPlan::Dml(_)
+            | LogicalPlan::Values(_)
+            | LogicalPlan::SubqueryAlias(_)
+            | LogicalPlan::Union(_)
+            | LogicalPlan::TableScan(_) => {
+                vec![self.schema()]
             }
-            LogicalPlan::Subquery(Subquery { subquery, .. }) => 
subquery.all_schemas(),
-            LogicalPlan::Extension(extension) => vec![extension.node.schema()],
-            LogicalPlan::Explain(Explain { schema, .. })
-            | LogicalPlan::Analyze(Analyze { schema, .. })
-            | LogicalPlan::EmptyRelation(EmptyRelation { schema, .. })
-            | LogicalPlan::CreateExternalTable(CreateExternalTable { schema, 
.. })
-            | LogicalPlan::CreateCatalogSchema(CreateCatalogSchema { schema, 
.. })
-            | LogicalPlan::CreateCatalog(CreateCatalog { schema, .. })
-            | LogicalPlan::Values(Values { schema, .. })
-            | LogicalPlan::SubqueryAlias(SubqueryAlias { schema, .. })
-            | LogicalPlan::Union(Union { schema, .. }) => {
-                vec![schema]
+            // return children schemas
+            LogicalPlan::Limit(_)
+            | LogicalPlan::Subquery(_)
+            | LogicalPlan::Extension(_)
+            | LogicalPlan::Repartition(_)
+            | LogicalPlan::Sort(_)
+            | LogicalPlan::CreateMemoryTable(_)
+            | LogicalPlan::CreateView(_)
+            | LogicalPlan::Filter(_)
+            | LogicalPlan::Distinct(_)
+            | LogicalPlan::Prepare(_) => {
+                self.inputs().iter().map(|p| p.schema()).collect()
             }
-            LogicalPlan::Limit(Limit { input, .. })
-            | LogicalPlan::Repartition(Repartition { input, .. })
-            | LogicalPlan::Sort(Sort { input, .. })
-            | LogicalPlan::CreateMemoryTable(CreateMemoryTable { input, .. })
-            | LogicalPlan::CreateView(CreateView { input, .. })
-            | LogicalPlan::Filter(Filter { input, .. })
-            | LogicalPlan::Distinct(Distinct { input, .. })
-            | LogicalPlan::Prepare(Prepare { input, .. }) => 
input.all_schemas(),
+            // return empty
             LogicalPlan::DropTable(_)
             | LogicalPlan::DropView(_)
             | LogicalPlan::DescribeTable(_)
             | LogicalPlan::SetVariable(_) => vec![],
-            LogicalPlan::Dml(DmlStatement { table_schema, .. }) => 
vec![table_schema],
         }
     }
 

Reply via email to