Skip to content

Commit ba36d39

Browse files
committed
fix: PushDownFilter for GROUP BY on uppercase col names
1 parent d8ee8d8 commit ba36d39

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

datafusion/optimizer/src/push_down_filter.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,11 @@ impl OptimizerRule for PushDownFilter {
941941
let group_expr_columns = agg
942942
.group_expr
943943
.iter()
944-
.map(|e| Ok(Column::from_qualified_name(e.schema_name().to_string())))
944+
.map(|e| {
945+
Ok(Column::from_qualified_name_ignore_case(
946+
e.schema_name().to_string(),
947+
))
948+
})
945949
.collect::<Result<HashSet<_>>>()?;
946950

947951
let predicates = split_conjunction_owned(filter.predicate);
@@ -4123,4 +4127,34 @@ mod tests {
41234127
"
41244128
)
41254129
}
4130+
4131+
/// Create a test table scan with uppercase column names for case sensitivity testing
4132+
fn test_table_scan_with_uppercase_columns() -> Result<LogicalPlan> {
4133+
let schema = Schema::new(vec![
4134+
Field::new("A", DataType::UInt32, false),
4135+
Field::new("B", DataType::UInt32, false),
4136+
Field::new("C", DataType::UInt32, false),
4137+
]);
4138+
table_scan(Some("test"), &schema, None)?.build()
4139+
}
4140+
4141+
#[test]
4142+
fn filter_agg_case_insensitive() -> Result<()> {
4143+
let table_scan = test_table_scan_with_uppercase_columns()?;
4144+
let plan = LogicalPlanBuilder::from(table_scan)
4145+
.aggregate(
4146+
vec![col(r#""A""#)],
4147+
vec![sum(col(r#""B""#)).alias("total_salary")],
4148+
)?
4149+
.filter(col(r#""A""#).gt(lit(10i64)))?
4150+
.build()?;
4151+
4152+
assert_optimized_plan_equal!(
4153+
plan,
4154+
@r"
4155+
Aggregate: groupBy=[[test.A]], aggr=[[sum(test.B) AS total_salary]]
4156+
TableScan: test, full_filters=[test.A > Int64(10)]
4157+
"
4158+
)
4159+
}
41264160
}

0 commit comments

Comments
 (0)