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/10/21 18:19:25 UTC

[GitHub] [arrow-datafusion] Dandandan commented on a diff in pull request #3923: Support inlining view / dataframes logical plan

Dandandan commented on code in PR #3923:
URL: https://github.com/apache/arrow-datafusion/pull/3923#discussion_r1002070063


##########
datafusion/optimizer/src/inline_table_scan.rs:
##########
@@ -0,0 +1,188 @@
+// 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.
+
+//! Optimizer rule to replace TableScan references
+//! such as DataFrames and Views and inlines the LogicalPlan
+//! to support further optimization
+use crate::{OptimizerConfig, OptimizerRule};
+use datafusion_common::Result;
+use datafusion_expr::{
+    col, logical_plan::LogicalPlan, utils::from_plan, LogicalPlanBuilder, TableScan,
+};
+
+/// Optimization rule that inlines TableScan that provide a [LogicalPlan]
+/// ([DataFrame] / [ViewTable])
+#[derive(Default)]
+pub struct InlineTableScan;
+
+impl InlineTableScan {
+    #[allow(missing_docs)]
+    pub fn new() -> Self {
+        Self {}
+    }
+}
+
+/// Inline
+fn inline_table_scan(plan: &LogicalPlan) -> Result<LogicalPlan> {
+    match plan {
+        LogicalPlan::TableScan(TableScan {
+            source,
+            table_name,
+            filters,
+            fetch,
+            projected_schema,
+            ..
+        }) => {
+            if let Some(sub_plan) = source.get_logical_plan() {
+                // Recurse into scan
+                let plan = inline_table_scan(sub_plan)?;
+                let mut plan = LogicalPlanBuilder::from(plan).project_with_alias(
+                    projected_schema
+                        .fields()
+                        .iter()
+                        .map(|field| col(field.name())),
+                    Some(table_name.clone()),
+                )?;
+                for filter in filters {

Review Comment:
   I think probably we can even remove handling filter / limit here as tables and for views/dataframes don't have those. Will remove the handling of possible.



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