Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression in the use of name in ProjectionPushdown #8219

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()?);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was done in #7981 -- it doesn't seem necessary and I think was just a mistake (and did not have adequate test coverage)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for resolving this; this was a leftover from my initial attempt to address the qualified alias problem (without altering the Expr::Alias enum) that I forgot to rollback.

Copy link
Contributor Author

@alamb alamb Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. The real problem is that we had no test coverage for it :(

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