You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "nuno-faria (via GitHub)" <gi...@apache.org> on 2026/02/04 08:54:27 UTC
[PR] fix: Ensure columns are casted to the correct names with Unions [datafusion]
nuno-faria opened a new pull request, #20146:
URL: https://github.com/apache/datafusion/pull/20146
## Which issue does this PR close?
- Closes #20123.
## Rationale for this change
When aliasing a cast, use the original name to prevent duplicate column names errors.
## What changes are included in this PR?
- Updated `coerce_exprs_for_schema` to use the correct name.
- Updated tests.
## Are these changes tested?
Yes.
## Are there any user-facing changes?
No.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Ensure columns are casted to the correct names with Unions [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #20146:
URL: https://github.com/apache/datafusion/pull/20146#discussion_r2766048077
##########
datafusion/expr/src/expr_rewriter/mod.rs:
##########
@@ -261,9 +261,14 @@ fn coerce_exprs_for_schema(
#[expect(deprecated)]
Expr::Wildcard { .. } => Ok(expr),
_ => {
- // maintain the original name when casting
- let name = dst_schema.field(idx).name();
- Ok(expr.cast_to(new_type, src_schema)?.alias(name))
+ match expr {
+ // maintain the original name when casting a column
+ Expr::Column(ref column) => {
Review Comment:
can we add some context about why we maintain the original name only for columns?
##########
datafusion/optimizer/tests/optimizer_integration.rs:
##########
@@ -543,7 +543,7 @@ fn recursive_cte_projection_pushdown() -> Result<()> {
RecursiveQuery: is_distinct=false
Projection: test.col_int32 AS id
TableScan: test projection=[col_int32]
- Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32) AS id
+ Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32)
Review Comment:
it isn't needed because the outer query doesn't use `id`?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Ensure columns are casted to the correct names with Unions [datafusion]
Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on code in PR #20146:
URL: https://github.com/apache/datafusion/pull/20146#discussion_r2767723055
##########
datafusion/expr/src/expr_rewriter/mod.rs:
##########
@@ -261,9 +261,14 @@ fn coerce_exprs_for_schema(
#[expect(deprecated)]
Expr::Wildcard { .. } => Ok(expr),
_ => {
- // maintain the original name when casting
- let name = dst_schema.field(idx).name();
- Ok(expr.cast_to(new_type, src_schema)?.alias(name))
+ match expr {
+ // maintain the original name when casting a column
+ Expr::Column(ref column) => {
Review Comment:
Added.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Ensure columns are casted to the correct names with Unions [datafusion]
Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on code in PR #20146:
URL: https://github.com/apache/datafusion/pull/20146#discussion_r2762893549
##########
datafusion/optimizer/tests/optimizer_integration.rs:
##########
@@ -543,7 +543,7 @@ fn recursive_cte_projection_pushdown() -> Result<()> {
RecursiveQuery: is_distinct=false
Projection: test.col_int32 AS id
TableScan: test projection=[col_int32]
- Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32) AS id
+ Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32)
Review Comment:
These changes are ok, the alias had been introduced by #19019 but it was not needed.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Ensure columns are casted to the correct names with Unions [datafusion]
Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on PR #20146:
URL: https://github.com/apache/datafusion/pull/20146#issuecomment-3851890696
> it isn't needed because the outer query doesn't use id?
The outer query uses `id` but the cast on the recursive branch was not needed since I think the name is set by the non-recursive term (or by the CTE definition).
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org