Skip to content

Commit 50cbee1

Browse files
masonh22avantgardnerio
authored andcommitted
Use Expr::qualified_name() and Column::new() to extract partition keys from window and aggregate operators (#355) (apache#17757) v51
1 parent a624bd0 commit 50cbee1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

datafusion/optimizer/src/push_down_filter.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,10 @@ impl OptimizerRule for PushDownFilter {
10021002
let extract_partition_keys = |func: &WindowFunction| {
10031003
func.partition_by
10041004
.iter()
1005-
.map(|c| Column::from_qualified_name(c.schema_name().to_string()))
1005+
.map(|c| {
1006+
let (relation, name) = c.qualified_name();
1007+
Column::new(relation, name)
1008+
})
10061009
.collect::<HashSet<_>>()
10071010
};
10081011
let potential_partition_keys = window
@@ -1545,6 +1548,38 @@ mod tests {
15451548
assert_optimized_plan_eq(plan, expected)
15461549
}
15471550

1551+
/// verifies that filters with unusual identifier names are pushed down through window functions
1552+
#[test]
1553+
fn filter_window_special_identifier() -> Result<()> {
1554+
let schema = Schema::new(vec![
1555+
Field::new("$a", DataType::UInt32, false),
1556+
Field::new("$b", DataType::UInt32, false),
1557+
Field::new("$c", DataType::UInt32, false),
1558+
]);
1559+
let table_scan = table_scan(Some("test"), &schema, None)?.build()?;
1560+
1561+
let window = Expr::WindowFunction(WindowFunction::new(
1562+
WindowFunctionDefinition::WindowUDF(
1563+
datafusion_functions_window::rank::rank_udwf(),
1564+
),
1565+
vec![],
1566+
))
1567+
.partition_by(vec![col("$a"), col("$b")])
1568+
.order_by(vec![col("$c").sort(true, true)])
1569+
.build()
1570+
.unwrap();
1571+
1572+
let plan = LogicalPlanBuilder::from(table_scan)
1573+
.window(vec![window])?
1574+
.filter(col("$b").gt(lit(10i64)))?
1575+
.build()?;
1576+
1577+
let expected = "\
1578+
WindowAggr: windowExpr=[[rank() PARTITION BY [test.$a, test.$b] ORDER BY [test.$c ASC NULLS FIRST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]\
1579+
\n TableScan: test, full_filters=[test.$b > Int64(10)]";
1580+
assert_optimized_plan_eq(plan, expected)
1581+
}
1582+
15481583
/// verifies that when partitioning by 'a' and 'b', and filtering by 'a' and 'b', both 'a' and
15491584
/// 'b' are pushed
15501585
#[test]

0 commit comments

Comments
 (0)