Skip to content

Commit

Permalink
fix use of name in Column (#8219)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Nov 15, 2023
1 parent 937bb44 commit 04c77ca
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion datafusion/optimizer/src/push_down_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl OptimizerRule for PushDownProjection {
// Gather all columns needed for expressions in this Aggregate
let mut new_aggr_expr = vec![];
for e in agg.aggr_expr.iter() {
let column = Column::from(e.display_name()?);
let column = Column::from_name(e.display_name()?);
if required_columns.contains(&column) {
new_aggr_expr.push(e.clone());
}
Expand Down Expand Up @@ -605,6 +605,31 @@ mod tests {
assert_optimized_plan_eq(&plan, expected)
}

#[test]
fn aggregate_with_periods() -> Result<()> {
let schema = Schema::new(vec![Field::new("tag.one", DataType::Utf8, false)]);

// Build a plan that looks as follows (note "tag.one" is a column named
// "tag.one", not a column named "one" in a table named "tag"):
//
// Projection: tag.one
// Aggregate: groupBy=[], aggr=[MAX("tag.one") AS "tag.one"]
// TableScan
let plan = table_scan(Some("m4"), &schema, None)?
.aggregate(
Vec::<Expr>::new(),
vec![max(col(Column::new_unqualified("tag.one"))).alias("tag.one")],
)?
.project([col(Column::new_unqualified("tag.one"))])?
.build()?;

let expected = "\
Aggregate: groupBy=[[]], aggr=[[MAX(m4.tag.one) AS tag.one]]\
\n TableScan: m4 projection=[tag.one]";

assert_optimized_plan_eq(&plan, expected)
}

#[test]
fn redundant_project() -> Result<()> {
let table_scan = test_table_scan()?;
Expand Down

0 comments on commit 04c77ca

Please sign in to comment.