Skip to content

Add duplicate name error reproducer - #20106

Merged
gabotechs merged 2 commits into
mainfrom
gabotechs/duplicate-name-reproducer
Feb 3, 2026
Merged

Add duplicate name error reproducer#20106
gabotechs merged 2 commits into
mainfrom
gabotechs/duplicate-name-reproducer

Conversation

@gabotechs

@gabotechsgabotechs commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Reproduces a duplicate name issue introduced in #19019.

Reverting the following code:

From:

 _ => {// maintain the original name when castinglet name = dst_schema.field(idx).name();Ok(expr.cast_to(new_type, src_schema)?.alias(name))}

to

 _ => expr.cast_to(new_type, src_schema),

Seems to fix the issue.

TODO: actually fix the issue before merging

What changes are included in this PR?

For now, just a reproducer test

Are these changes tested?

yes, by a new test

Are there any user-facing changes?

no

@github-actionsgithub-actionsBot added the substrait Changes to the substrait crate label Feb 2, 2026
@gabotechsgabotechs added bug Something isn't working regression Something that used to work no longer does labels Feb 2, 2026

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice find @gabotechs

Comment threaddatafusion/substrait/tests/cases/logical_plans.rs
@gabotechs
gabotechs added this pull request to the merge queueFeb 3, 2026
Merged via the queue into main with commit 1825f97Feb 3, 2026
54 checks passed
@gabotechs

Copy link
Copy Markdown
ContributorAuthor

cc @dd-annarose, merged the reproducer, in case you have time to look into this.

@dd-annarose

Copy link
Copy Markdown
Contributor

@gabotechs ah just saw the issue was taken already. Did not get a notification for this ping

@nuno-faria

nuno-faria commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

That's quite the bug!

Projection: foo AS col1, bar AS col2
Union
Projection: foo, bar
Values: (Int64(100), Int64(200))
Projection: x, foo
Values: (Int32(300), Int64(400))

Because x has a different type, it will be casted to Int64. In the cast, an alias is added to the original name. However, in this case dst_schema will not contain the original column names, but rather the names of the first relation, since this is an union. So the second projection is temporarily foo (casted and alised) and foo, hence the duplicate error.

I will try to push a fix soon.

@gabotechs

Copy link
Copy Markdown
ContributorAuthor

@gabotechs ah just saw the issue was taken already. Did not get a notification for this ping

@dd-annarose It seems like people have been really fast on tackling this. Maybe you can help with a review on #20146?

Thanks @nuno-faria for jumping into this!

@gabotechs
gabotechs deleted the gabotechs/duplicate-name-reproducer branch February 4, 2026 09:51
dd-david-levin pushed a commit to dd-david-levin/datafusion that referenced this pull request Mar 25, 2026
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closesapache#123` indicates that this PR will close issue apache#123.
-->
- Closes #.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Reproduces a duplicate name issue introduced in
apache#19019.
Reverting the following code:
https://github.com/apache/datafusion/blob/2e02cc131d1d71cce819000912f0411345ca2d6e/datafusion/expr/src/expr_rewriter/mod.rs#L263-L263
From:
```rust
_ => {
// maintain the original name when casting
let name = dst_schema.field(idx).name();
Ok(expr.cast_to(new_type, src_schema)?.alias(name))
}
```
to
```rust
_ => expr.cast_to(new_type, src_schema),
```
Seems to fix the issue.
TODO: actually fix the issue before merging
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
For now, just a reproducer test
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
yes, by a new test
no
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
(cherry picked from commit 1825f97)
gh-worker-dd-mergequeue-cf854dBot added a commit to DataDog/datafusion that referenced this pull request Mar 26, 2026
…ache-pr-20106-20260325
Cherry-pick apache#20106
Co-authored-by: gabotechs <45515538+gabotechs@users.noreply.github.com>
Co-authored-by: david.levin <david.levin@datadoghq.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingregressionSomething that used to work no longer doessubstraitChanges to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@gabotechs@dd-annarose@nuno-faria@alamb