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/08/25 14:01:15 UTC

[GitHub] [arrow-datafusion] HaoYang670 opened a new pull request, #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

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

   Signed-off-by: remzi <13...@gmail.com>
   
   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3249.
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956900462


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -104,14 +107,24 @@ impl TableProvider for ViewTable {
                         )
                     })
                     .collect();
-                let plan = LogicalPlanBuilder::from(self.logical_plan.clone())
-                    .project(fields)?
-                    .build()?;
-                state_cloned.create_physical_plan(&plan).await
+                plan_builder.project(fields)?
             }
         } else {
-            state_cloned.create_physical_plan(&self.logical_plan).await
-        }
+            plan_builder
+        };
+
+        let plan = plan_builder
+            // add filters, otherwise use `true` as the predicate
+            .filter(
+                filters
+                    .iter()
+                    .fold(Expr::Literal(ScalarValue::Boolean(Some(true))), |acc, f| {
+                        acc.and(f.clone())
+                    }),
+            )?
+            .limit(None, limit)?

Review Comment:
   Updated.



-- 
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] HaoYang670 closed pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 closed pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`
URL: https://github.com/apache/arrow-datafusion/pull/3258


-- 
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] HaoYang670 commented on pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#issuecomment-1236104204

   Thank you @alamb. I will study your advice carefully.


-- 
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] kmitchener commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
kmitchener commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956741498


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -104,14 +107,24 @@ impl TableProvider for ViewTable {
                         )
                     })
                     .collect();
-                let plan = LogicalPlanBuilder::from(self.logical_plan.clone())
-                    .project(fields)?
-                    .build()?;
-                state_cloned.create_physical_plan(&plan).await
+                plan_builder.project(fields)?
             }
         } else {
-            state_cloned.create_physical_plan(&self.logical_plan).await
-        }
+            plan_builder
+        };
+
+        let plan = plan_builder
+            // add filters, otherwise use `true` as the predicate
+            .filter(
+                filters
+                    .iter()
+                    .fold(Expr::Literal(ScalarValue::Boolean(Some(true))), |acc, f| {
+                        acc.and(f.clone())
+                    }),
+            )?
+            .limit(None, limit)?

Review Comment:
   This should be wrapped in an if to determine if a limit was passed in to scan(). If no limit, don't call plan_builder.limit(). The way this is written, it's adding a Limit to the logical plan always.
   
   something like
   ```rust
           if limit.is_some() {
               plan_builder.limit(None, limit)?;
           }
   ```



-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r955788156


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")
+            .await?
+            .collect()
+            .await?;
+
+        let expected_plan = vec![
+            "+---------------+------------------------------------------------------+",
+            "| plan_type     | plan                                                 |",
+            "+---------------+------------------------------------------------------+",
+            "| logical_plan  | CreateView: \"efg\"                                    |",
+            "|               |   Limit: skip=1, fetch=2                             |",
+            "|               |     Projection: #xyz.column1                         |",
+            "|               |       Filter: #xyz.column2 % Int64(2) = Int64(0)     |",
+            "|               |         TableScan: xyz projection=[column1, column2] |",

Review Comment:
   Hi @Dandandan @andygrove . Should the `Limit` and `Filter` be pushed down to the `TableScan`?



-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956029009


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   I got this:
   ```
   [
       "+---------------+-----------------------------------------------------------------------------------+",
       "| plan_type     | plan                                                                              |",
       "+---------------+-----------------------------------------------------------------------------------+",
       "| logical_plan  | Limit: skip=1, fetch=2                                                            |",
       "|               |   Projection: #xyz.column1                                                        |",
       "|               |     Filter: #xyz.column2 % Int64(2) = Int64(0)                                    |",
       "|               |       TableScan: xyz projection=[column1, column2]                                |",
       "| physical_plan | GlobalLimitExec: skip=1, fetch=2                                                  |",
       "|               |   CoalescePartitionsExec                                                          |",
       "|               |     ProjectionExec: expr=[column1@0 as column1]                                   |",
       "|               |       CoalesceBatchesExec: target_batch_size=4096                                 |",
       "|               |         FilterExec: column2@1 % 2 = 0                                             |",
       "|               |           RepartitionExec: partitioning=RoundRobinBatch(10)                       |",
       "|               |             GlobalLimitExec: skip=None, fetch=None                                |",
       "|               |               CoalescePartitionsExec                                              |",
       "|               |                 ProjectionExec: expr=[column1@0 as column1, column2@1 as column2] |",
       "|               |                   RepartitionExec: partitioning=RoundRobinBatch(10)               |",
       "|               |                     MemoryExec: partitions=1, partition_sizes=[1]                 |",
       "|               |                                                                                   |",
       "+---------------+-----------------------------------------------------------------------------------+",
   ]
   ```
   Seems like only `projection` is pushed down, but not `filter` or `limit`. Not sure what goes wrong πŸ˜…



-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956024420


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   Thank you, Andy! I will update the test.



-- 
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 #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#issuecomment-1236104554

   @HaoYang670  I am happy to help out with this project too -- I think it important for DataFusion and we can likely generate a very nice solution 


-- 
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] codecov-commenter commented on pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#issuecomment-1227983591

   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/3258?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#3258](https://codecov.io/gh/apache/arrow-datafusion/pull/3258?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7a21783) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/92110ddba004ca585649d1ba97dcb67f20fc0779?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (92110dd) will **increase** coverage by `0.00%`.
   > The diff coverage is `84.61%`.
   
   ```diff
   @@           Coverage Diff           @@
   ##           master    #3258   +/-   ##
   =======================================
     Coverage   85.89%   85.89%           
   =======================================
     Files         294      294           
     Lines       53373    53411   +38     
   =======================================
   + Hits        45845    45879   +34     
   - Misses       7528     7532    +4     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/3258?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Ξ” | |
   |---|---|---|
   | [datafusion/core/src/datasource/view.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3258/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9kYXRhc291cmNlL3ZpZXcucnM=) | `86.38% <84.61%> (-0.17%)` | :arrow_down: |
   | [datafusion/expr/src/logical\_plan/plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3258/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vcGxhbi5ycw==) | `78.55% <0.00%> (-0.18%)` | :arrow_down: |
   | [...fusion/optimizer/src/pre\_cast\_lit\_in\_comparison.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3258/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3ByZV9jYXN0X2xpdF9pbl9jb21wYXJpc29uLnJz) | `85.60% <0.00%> (+2.27%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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] HaoYang670 commented on pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#issuecomment-1294327649

   Close this PR as the issue has been fixed.


-- 
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] Dandandan commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
Dandandan commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r955649455


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,43 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")

Review Comment:
   Could you test the plan as well (with `EXPLAIN`)?



-- 
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] andygrove commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956014393


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   I think what we want here is to just select from the view. 
   
   ```suggestion
               .sql("EXPLAIN SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")
   ```



-- 
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] andygrove commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956014831


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   When we select from a view, it will cause the `TableView::scan` method to be called.



-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956531947


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   > Ah, the test is using a MemTable 
   
   Thank you for the explanation Andy. Is there a way to test using other data source except the `MemTable`?



##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   > Ah, the test is using a MemTable 
   
   Thank you for the explanation, Andy. Is there a way to test using other data source except the `MemTable`?



-- 
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] andygrove commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956015575


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")
+            .await?
+            .collect()
+            .await?;
+
+        let expected_plan = vec![
+            "+---------------+------------------------------------------------------+",
+            "| plan_type     | plan                                                 |",
+            "+---------------+------------------------------------------------------+",
+            "| logical_plan  | CreateView: \"efg\"                                    |",
+            "|               |   Limit: skip=1, fetch=2                             |",
+            "|               |     Projection: #xyz.column1                         |",
+            "|               |       Filter: #xyz.column2 % Int64(2) = Int64(0)     |",
+            "|               |         TableScan: xyz projection=[column1, column2] |",

Review Comment:
   Yes, when we select from a view, I am expecting these to be pushed down. This will not happen when creating the view though.



-- 
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 #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#issuecomment-1294993279

   πŸŽ‰ 


-- 
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] HaoYang670 commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956535260


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   > We can see that the filter and limit are added into the logical plan though so I think this is good enough for this PR.
   
   I guess what we do in this PR is to add the `limit` and `filter` information into the `TableScan`. However, I can't find a way to test whether it works properly. Could you help me?



-- 
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] andygrove commented on a diff in pull request #3258: Apply `filters` and `limits` when building logical plan in `ViewTable::scan`

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3258:
URL: https://github.com/apache/arrow-datafusion/pull/3258#discussion_r956153860


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -342,6 +355,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn query_view_with_filter_and_limit() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6), (7,8,9)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let result_plan = session_ctx
+            .sql("EXPLAIN CREATE VIEW efg as SELECT column1 FROM xyz WHERE column2 % 2 = 0 OFFSET 1 LIMIT 2")

Review Comment:
   Ah, the test is using a `MemTable`, which does not support filter pushdown. We can see that the filter and limit are added into the logical plan though so I think this is good enough for this PR.



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