Skip to content

Commit 23c2cd2

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 059999f commit 23c2cd2

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

datafusion/optimizer/src/push_down_filter.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,8 @@ impl OptimizerRule for PushDownFilter {
10101010
.partition_by
10111011
.iter()
10121012
.map(|c| {
1013-
Column::from_qualified_name(
1014-
c.schema_name().to_string(),
1015-
)
1013+
let (relation, name) = c.qualified_name();
1014+
Column::new(relation, name)
10161015
})
10171016
.collect::<HashSet<_>>()
10181017
} else {
@@ -1550,6 +1549,38 @@ mod tests {
15501549
assert_optimized_plan_eq(plan, expected)
15511550
}
15521551

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

0 commit comments

Comments
 (0)