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 2021/05/24 12:55:44 UTC

[GitHub] [arrow-datafusion] e-dard opened a new pull request #409: fix: don't duplicate existing filters

e-dard opened a new pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409


   # 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 #408
   
   # 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.
   -->
   
   This PR ensures that filter expressions already present on the table scan part of a logical plan are not re-added if the plan is run through the optimiser again.
   


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

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



[GitHub] [arrow-datafusion] NGA-TRAN commented on a change in pull request #409: fix: don't duplicate existing filters

Posted by GitBox <gi...@apache.org>.
NGA-TRAN commented on a change in pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409#discussion_r637941394



##########
File path: datafusion/src/optimizer/filter_push_down.rs
##########
@@ -1037,6 +1045,23 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn filter_with_table_provider_multiple_invocations() -> Result<()> {
+        let plan =
+            table_scan_with_pushdown_provider(TableProviderFilterPushDown::Inexact)?;
+
+        let optimised_plan = optimize_plan(&plan);
+
+        let expected = "\
+        Filter: #a Eq Int64(1)\
+        \n  TableScan: projection=None, filters=[#a Eq Int64(1)]";
+
+        // Optimizing the same plan multiple times should produce the same plan
+        // each time.
+        assert_optimized_plan_eq(&optimised_plan, expected);

Review comment:
       +1

##########
File path: datafusion/src/optimizer/filter_push_down.rs
##########
@@ -379,6 +379,11 @@ fn optimize(plan: &LogicalPlan, mut state: State) -> Result<LogicalPlan> {
                 }
 
                 if add_to_provider {
+                    // Don't add expression again if it's already present in
+                    // pushed down filters.
+                    if new_filters.iter().any(|filter| filter.eq(filter_expr)) {

Review comment:
       Nice




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

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



[GitHub] [arrow-datafusion] e-dard commented on a change in pull request #409: fix: don't duplicate existing filters

Posted by GitBox <gi...@apache.org>.
e-dard commented on a change in pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409#discussion_r637947723



##########
File path: datafusion/src/optimizer/filter_push_down.rs
##########
@@ -379,6 +379,11 @@ fn optimize(plan: &LogicalPlan, mut state: State) -> Result<LogicalPlan> {
                 }
 
                 if add_to_provider {
+                    // Don't add expression again if it's already present in
+                    // pushed down filters.
+                    if new_filters.iter().any(|filter| filter.eq(filter_expr)) {

Review comment:
       Thanks @Dandandan, I completely forgot about `contains` on `Vec`.




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

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



[GitHub] [arrow-datafusion] Dandandan commented on a change in pull request #409: fix: don't duplicate existing filters

Posted by GitBox <gi...@apache.org>.
Dandandan commented on a change in pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409#discussion_r637935409



##########
File path: datafusion/src/optimizer/filter_push_down.rs
##########
@@ -379,6 +379,11 @@ fn optimize(plan: &LogicalPlan, mut state: State) -> Result<LogicalPlan> {
                 }
 
                 if add_to_provider {
+                    // Don't add expression again if it's already present in
+                    // pushed down filters.
+                    if new_filters.iter().any(|filter| filter.eq(filter_expr)) {

Review comment:
       ```suggestion
                       if new_filters.contains(filter_expr) {
   ```
   something like this should work?




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

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



[GitHub] [arrow-datafusion] alamb commented on a change in pull request #409: fix: don't duplicate existing filters

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409#discussion_r637932340



##########
File path: datafusion/src/optimizer/filter_push_down.rs
##########
@@ -1037,6 +1045,23 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn filter_with_table_provider_multiple_invocations() -> Result<()> {
+        let plan =
+            table_scan_with_pushdown_provider(TableProviderFilterPushDown::Inexact)?;
+
+        let optimised_plan = optimize_plan(&plan);
+
+        let expected = "\
+        Filter: #a Eq Int64(1)\
+        \n  TableScan: projection=None, filters=[#a Eq Int64(1)]";
+
+        // Optimizing the same plan multiple times should produce the same plan
+        // each time.
+        assert_optimized_plan_eq(&optimised_plan, expected);

Review comment:
       👍 




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

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



[GitHub] [arrow-datafusion] alamb merged pull request #409: fix: don't duplicate existing filters

Posted by GitBox <gi...@apache.org>.
alamb merged pull request #409:
URL: https://github.com/apache/arrow-datafusion/pull/409


   


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

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