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 13:24:18 UTC

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

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