Skip to content

Commit

Permalink
add fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted-Jiang committed Jun 15, 2022
1 parent eed0a92 commit b40a85b
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion datafusion/optimizer/src/filter_push_down.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ mod tests {
use async_trait::async_trait;
use datafusion_common::DFSchema;
use datafusion_expr::{
and, col, lit,
and, col, in_list, lit,
logical_plan::{builder::union_with_alias, JoinType},
sum, Expr, LogicalPlanBuilder, Operator, TableSource, TableType,
};
Expand Down Expand Up @@ -2013,4 +2013,38 @@ mod tests {
assert_optimized_plan_eq(&plan, expected);
Ok(())
}

#[test]
fn test_in_filter_with_alias() -> Result<()> {
// in table scan the true col name is 'test.a',
// but we rename it as 'b', and use col 'b' in filter
// we need rewrite filter col before push down.
let table_scan = test_table_scan()?;
let filter_value = vec![lit(1u32), lit(2u32), lit(3u32), lit(4u32)];
let plan = LogicalPlanBuilder::from(table_scan)
.project(vec![col("a").alias("b"), col("c")])?
.filter(in_list(col("b"), filter_value, false))?
.build()?;

// filter on col b
assert_eq!(
format!("{:?}", plan),
"\
Filter: #b IN ([UInt32(1), UInt32(2), UInt32(3), UInt32(4)])\
\n Projection: #test.a AS b, #test.c\
\n TableScan: test projection=None\
"
);

// rewrite filter col b to test.a
let expected = "\
Projection: #test.a AS b, #test.c\
\n Filter: #test.a IN ([UInt32(1), UInt32(2), UInt32(3), UInt32(4)])\
\n TableScan: test projection=None\
";

assert_optimized_plan_eq(&plan, expected);

Ok(())
}
}

0 comments on commit b40a85b

Please sign in to comment.