Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn test_union_upcast_types() -> Result<()> {

let expected_logical_plan = vec![
"Limit: skip=0, fetch=5 [c1:Utf8, c9:Int64]",
" Sort: c9 DESC NULLS FIRST [c1:Utf8, c9:Int64]",
" Sort: aggregate_test_100.c9 DESC NULLS FIRST [c1:Utf8, c9:Int64]",
" Union [c1:Utf8, c9:Int64]",
" Projection: aggregate_test_100.c1, CAST(aggregate_test_100.c9 AS Int64) AS c9 [c1:Utf8, c9:Int64]",
" TableScan: aggregate_test_100 [c1:Utf8, c2:UInt32, c3:Int8, c4:Int16, c5:Int32, c6:Int64, c7:UInt8, c8:UInt16, c9:UInt32, c10:UInt64, c11:Float32, c12:Float64, c13:Utf8]",
Expand Down
22 changes: 21 additions & 1 deletion datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ pub fn union(left_plan: LogicalPlan, right_plan: LogicalPlan) -> Result<LogicalP
})?;

Ok(DFField::new(
None,
left_field.qualifier().map(|x| x.as_ref()),
left_field.name(),
data_type,
nullable,
Expand Down Expand Up @@ -1782,4 +1782,24 @@ mod tests {

table_scan(Some(table_name), &schema, None)
}

#[test]
fn test_union_after_join() -> Result<()> {
let values = vec![vec![lit(1)]];

let left = LogicalPlanBuilder::values(values.clone())?
Copy link
Member

Choose a reason for hiding this comment

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

👍

.alias("left")?
.build()?;
let right = LogicalPlanBuilder::values(values)?
.alias("right")?
.build()?;

let join = LogicalPlanBuilder::from(left).cross_join(right)?.build()?;

let _ = LogicalPlanBuilder::from(join.clone())
.union(join)?
.build()?;

Ok(())
}
}
6 changes: 2 additions & 4 deletions datafusion/optimizer/src/propagate_empty_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ mod tests {

let plan = LogicalPlanBuilder::from(left).union(right)?.build()?;

let expected = "Projection: a, b, c\
\n TableScan: test";
let expected = "TableScan: test";
assert_together_optimized_plan_eq(&plan, expected)
}

Expand Down Expand Up @@ -362,8 +361,7 @@ mod tests {

let plan = LogicalPlanBuilder::from(left).union(right)?.build()?;

let expected = "Projection: a, b, c\
\n TableScan: test";
let expected = "TableScan: test";
assert_together_optimized_plan_eq(&plan, expected)
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion/sql/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ fn union_with_multiply_cols() {
#[test]
fn sorted_union_with_different_types_and_group_by() {
let sql = "SELECT a FROM (select 1 a) x GROUP BY 1 UNION ALL (SELECT a FROM (select 1.1 a) x GROUP BY 1) ORDER BY 1";
let expected = "Sort: a ASC NULLS LAST\
let expected = "Sort: x.a ASC NULLS LAST\
\n Union\
\n Projection: CAST(x.a AS Float64) AS a\
\n Aggregate: groupBy=[[x.a]], aggr=[[]]\
Expand Down