alamb commented on code in PR #15201:
URL: https://github.com/apache/datafusion/pull/15201#discussion_r1995496219


##########
datafusion/sqllogictest/test_files/ddl.slt:
##########
@@ -855,3 +855,29 @@ DROP TABLE t1;
 
 statement ok
 DROP TABLE t2;
+
+statement count 0
+create table t(a int) as values (1), (2), (3);
+
+statement count 0
+create view v as select a, count(a) from t group by a;
+
+query II rowsort
+select * from v;
+----
+1 1
+2 1
+3 1
+
+query II rowsort
+select "count(t.a)", a from v;
+----
+1 1
+1 2
+1 3
+
+query error DataFusion error: Execution error: Table 'v' doesn't exist\.

Review Comment:
   I think it should be `drop view v` rather than `drop table`



##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -465,9 +465,21 @@ impl LogicalPlanBuilder {
         projection: Option<Vec<usize>>,
         filters: Vec<Expr>,
     ) -> Result<Self> {
-        TableScan::try_new(table_name, table_source, projection, filters, None)
-            .map(LogicalPlan::TableScan)
-            .map(Self::new)
+        let table_scan =
+            TableScan::try_new(table_name, table_source, projection, filters, 
None)?;
+
+        // Inline TableScan
+        if table_scan.filters.is_empty() {
+            if let Some(p) = table_scan.source.get_logical_plan() {
+                let sub_plan = p.into_owned();
+                // Ensures that the reference to the inlined table remains the
+                // same, meaning we don't have to change any of the parent 
nodes
+                // that reference this table.
+                return Self::new(sub_plan).alias(table_scan.table_name);
+            }
+        }
+
+        Ok(Self::new(LogicalPlan::TableScan(table_scan)))

Review Comment:
   seems like the same logic should apply to scan_with_filters_fetch below



##########
datafusion/core/tests/dataframe/mod.rs:
##########
@@ -1563,8 +1563,12 @@ async fn with_column_join_same_columns() -> Result<()> {
         \n  Limit: skip=0, fetch=1\
         \n    Sort: t1.c1 ASC NULLS FIRST\
         \n      Inner Join: t1.c1 = t2.c1\
-        \n        TableScan: t1\
-        \n        TableScan: t2",
+        \n        SubqueryAlias: t1\

Review Comment:
   I am still worried about this change -- I don't undersrtand why the subquery 
allias has not been removed or if that is a problem 🤔 



-- 
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-unsubscr...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to