This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 54fb92e0d Recursively apply remove filter rule if filter is a true
scalar value (#3175)
54fb92e0d is described below
commit 54fb92e0d815d994a8605b044e5a3453f204a16b
Author: byteink <[email protected]>
AuthorDate: Wed Aug 17 04:55:58 2022 +0800
Recursively apply remove filter rule if filter is a true scalar value
(#3175)
* Recursively apply rule if filter is a true scalar value
* Apply suggestions from code review
#3175
Co-authored-by: Andrew Lamb <[email protected]>
* Fix clippy warning
Co-authored-by: Andrew Lamb <[email protected]>
---
datafusion/optimizer/src/eliminate_filter.rs | 33 ++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/datafusion/optimizer/src/eliminate_filter.rs
b/datafusion/optimizer/src/eliminate_filter.rs
index 5e75e8134..ef09cd5b5 100644
--- a/datafusion/optimizer/src/eliminate_filter.rs
+++ b/datafusion/optimizer/src/eliminate_filter.rs
@@ -54,7 +54,7 @@ impl OptimizerRule for EliminateFilter {
schema: input.schema().clone(),
}))
} else {
- Ok((**input).clone())
+ self.optimize(input, optimizer_config)
}
}
_ => {
@@ -79,7 +79,7 @@ impl OptimizerRule for EliminateFilter {
mod tests {
use super::*;
use crate::test::*;
- use datafusion_expr::{col, logical_plan::builder::LogicalPlanBuilder, sum};
+ use datafusion_expr::{col, lit, logical_plan::builder::LogicalPlanBuilder,
sum};
fn assert_optimized_plan_eq(plan: &LogicalPlan, expected: &str) {
let rule = EliminateFilter::new();
@@ -183,4 +183,33 @@ mod tests {
\n TableScan: test";
assert_optimized_plan_eq(&plan, expected);
}
+
+ #[test]
+ fn fliter_from_subquery() {
+ // SELECT a FROM (SELECT a FROM test WHERE FALSE) WHERE TRUE
+
+ let false_filter = lit(false);
+ let table_scan = test_table_scan().unwrap();
+ let plan1 = LogicalPlanBuilder::from(table_scan.clone())
+ .project(vec![col("a")])
+ .unwrap()
+ .filter(false_filter)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ let true_filter = lit(true);
+ let plan = LogicalPlanBuilder::from(plan1.clone())
+ .project(vec![col("a")])
+ .unwrap()
+ .filter(true_filter)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ // Filter is removed
+ let expected = "Projection: #test.a\
+ \n EmptyRelation";
+ assert_optimized_plan_eq(&plan, expected);
+ }
}