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/26 08:21:51 UTC

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

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