Skip to content

Commit 37aba41

Browse files
authored
Merge 233e42e into 70e702c
2 parents 70e702c + 233e42e commit 37aba41

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

datafusion/optimizer/src/filter_push_down.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,18 @@ fn optimize(plan: &LogicalPlan, mut state: State) -> Result<LogicalPlan> {
363363
.fields()
364364
.iter()
365365
.enumerate()
366-
.map(|(i, field)| {
366+
.flat_map(|(i, field)| {
367367
// strip alias, as they should not be part of filters
368368
let expr = match &expr[i] {
369369
Expr::Alias(expr, _) => expr.as_ref().clone(),
370370
expr => expr.clone(),
371371
};
372372

373-
(field.qualified_name(), expr)
373+
// Convert both qualified and unqualified fields
374+
[
375+
(field.name().clone(), expr.clone()),
376+
(field.qualified_name(), expr),
377+
]
374378
})
375379
.collect::<HashMap<_, _>>();
376380

@@ -992,6 +996,30 @@ mod tests {
992996
Ok(())
993997
}
994998

999+
#[test]
1000+
fn union_all_on_projection() -> Result<()> {
1001+
let table_scan = test_table_scan()?;
1002+
let table = LogicalPlanBuilder::from(table_scan)
1003+
.project_with_alias(vec![col("a").alias("b")], Some("test2".to_string()))?;
1004+
1005+
let plan = table
1006+
.union(table.build()?)?
1007+
.filter(col("b").eq(lit(1i64)))?
1008+
.build()?;
1009+
1010+
// filter appears below Union
1011+
let expected = "\
1012+
Union\
1013+
\n Projection: #test.a AS b, alias=test2\
1014+
\n Filter: #test.a = Int64(1)\
1015+
\n TableScan: test\
1016+
\n Projection: #test.a AS b, alias=test2\
1017+
\n Filter: #test.a = Int64(1)\
1018+
\n TableScan: test";
1019+
assert_optimized_plan_eq(&plan, expected);
1020+
Ok(())
1021+
}
1022+
9951023
/// verifies that filters with the same columns are correctly placed
9961024
#[test]
9971025
fn filter_2_breaks_limits() -> Result<()> {

0 commit comments

Comments
 (0)