This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new f37dd7cd2 fix: union schema fix (#2688)
f37dd7cd2 is described below
commit f37dd7cd231a5423e19c519f66d6b6cffb60d230
Author: George Andronchik <[email protected]>
AuthorDate: Sat Jun 11 23:31:30 2022 +0800
fix: union schema fix (#2688)
---
datafusion/expr/src/logical_plan/builder.rs | 2 +-
datafusion/sql/src/planner.rs | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/datafusion/expr/src/logical_plan/builder.rs
b/datafusion/expr/src/logical_plan/builder.rs
index 509b47909..8d58241ea 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -866,7 +866,7 @@ pub fn project_with_column_index_alias(
.map(|(i, e)| match e {
ignore_alias @ Expr::Alias { .. } => ignore_alias,
ignore_col @ Expr::Column { .. } => ignore_col,
- x => x.alias(format!("column{}", i).as_str()),
+ x => x.alias(schema.field(i).name()),
})
.collect::<Vec<_>>();
Ok(LogicalPlan::Projection(Projection {
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index dff05babb..343157875 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -3987,9 +3987,9 @@ mod tests {
fn union_values_with_no_alias() {
let sql = "SELECT 1, 2 UNION ALL SELECT 3, 4";
let expected = "Union\
- \n Projection: Int64(1) AS column0, Int64(2) AS column1\
+ \n Projection: Int64(1) AS Int64(1), Int64(2) AS Int64(2)\
\n EmptyRelation\
- \n Projection: Int64(3) AS column0, Int64(4) AS column1\
+ \n Projection: Int64(3) AS Int64(1), Int64(4) AS Int64(2)\
\n EmptyRelation";
quick_test(sql, expected);
}