Copilot commented on code in PR #25412:
URL: https://github.com/apache/datafusion/pull/25412#discussion_r4038058795
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -702,27 +720,36 @@ fn build_extraction_projection_impl(
// than target_schema (the projection's output) because columns
produced
// by alias expressions (e.g., CSE's __common_expr_N) exist in the
output but
// not the input, and cannot be added as pass-through Column
references.
+ //
+ // Both sides of that check are read in the input's own spelling. A
column can
+ // arrive here unqualified while the input names it `t.c`, and the
other way round:
+ // a projection of bare names over a qualified input is what
eliminating one side
+ // of a union leaves behind. Resolving both sides lets a pass-through
the
+ // projection already carries match the one about to be added, and
pushes the one
+ // that is genuinely new under the name the input gives it. Left
unresolved, the
+ // merged projection would hold `t.c` and a bare `c` together, which
+ // `Projection::try_new` rejects as ambiguous.
+ let input_schema = existing.input.schema();
let existing_cols: IndexSet<Column> = existing
.expr
.iter()
.filter_map(|e| {
if let Expr::Column(c) = e {
- Some(c.clone())
+ resolve_against(input_schema, c)
Review Comment:
This set ignores trivial pass-through aliases such as `p.c AS c`, even
though `passthrough_column` explicitly treats them as pass-throughs. When
`columns_needed` contains `c`, the replacement map resolves it to `p.c`;
omitting the retained alias here then appends `p.c` beside the existing
unqualified `c`, recreating the same ambiguous schema. Normalize every
`passthrough_column(e)` here, and add a regression case with a same-name alias.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]