adriangb commented on code in PR #25412:
URL: https://github.com/apache/datafusion/pull/25412#discussion_r4267188966
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -737,27 +751,33 @@ 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.
+ //
+ // Resolve the pass-through columns of `existing` and the columns in
+ // `columns_needed` against the input schema before comparing them (see
+ // `resolve_against`). Without this, a bare `c` in one set and a
+ // qualified `t.c` in the other do not match, so the merged projection
+ // holds both, and `Projection::try_new` rejects it as ambiguous.
+ //
+ // This shape occurs when the optimizer removes the empty input of a
+ // `UNION ALL` (for example `... UNION ALL SELECT ... WHERE 1 = 2`):
the
+ // projection that remains lists bare column names over a qualified
+ // input. A same-name alias (`t.c AS c`) counts as a pass-through of
+ // `t.c`.
+ 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())
- } else {
- None
- }
- })
+ .filter_map(|e| resolve_against(input_schema,
passthrough_column(e)?))
.collect();
- let input_schema = existing.input.schema();
for col in columns_needed {
let col_expr = Expr::Column(col.clone());
let resolved = replace_cols_by_name(col_expr, &replace_map)?;
if let Expr::Column(resolved_col) = &resolved
- && !existing_cols.contains(resolved_col)
- && input_schema.has_column(resolved_col)
+ && let Some(input_col) = resolve_against(input_schema,
resolved_col)
+ && !existing_cols.contains(&input_col)
{
Review Comment:
added in 68a2780
--
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]