Skip to content

Commit fe67edc

Browse files
committed
Add the test from apache#17757
1 parent 3d9138b commit fe67edc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

datafusion/optimizer/src/push_down_filter.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,38 @@ mod tests {
14281428
assert_optimized_plan_eq(plan, expected)
14291429
}
14301430

1431+
/// verifies that filters with unusual identifier names are pushed down through window functions
1432+
#[test]
1433+
fn filter_window_special_identifier() -> Result<()> {
1434+
let schema = Schema::new(vec![
1435+
Field::new("$a", DataType::UInt32, false),
1436+
Field::new("$b", DataType::UInt32, false),
1437+
Field::new("$c", DataType::UInt32, false),
1438+
]);
1439+
let table_scan = table_scan(Some("test"), &schema, None)?.build()?;
1440+
1441+
let window = Expr::WindowFunction(WindowFunction::new(
1442+
WindowFunctionDefinition::WindowUDF(
1443+
datafusion_functions_window::rank::rank_udwf(),
1444+
),
1445+
vec![],
1446+
))
1447+
.partition_by(vec![col("$a"), col("$b")])
1448+
.order_by(vec![col("$c").sort(true, true)])
1449+
.build()
1450+
.unwrap();
1451+
1452+
let plan = LogicalPlanBuilder::from(table_scan)
1453+
.window(vec![window])?
1454+
.filter(col("$b").gt(lit(10i64)))?
1455+
.build()?;
1456+
1457+
let expected = "\
1458+
WindowAggr: windowExpr=[[rank() PARTITION BY [test.$a, test.$b] ORDER BY [test.$c ASC NULLS FIRST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]\
1459+
\n TableScan: test, full_filters=[test.$b > Int64(10)]";
1460+
assert_optimized_plan_eq(plan, expected)
1461+
}
1462+
14311463
/// verifies that when partitioning by 'a' and 'b', and filtering by 'a' and 'b', both 'a' and
14321464
/// 'b' are pushed
14331465
#[test]

0 commit comments

Comments
 (0)