diff --git a/datafusion/core/tests/sql/union.rs b/datafusion/core/tests/sql/union.rs index 5d16c1dc9397f..d56a0a39ffad4 100644 --- a/datafusion/core/tests/sql/union.rs +++ b/datafusion/core/tests/sql/union.rs @@ -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]", diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index e6ff15244474d..3a03c9d3db98a 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -1101,7 +1101,7 @@ pub fn union(left_plan: LogicalPlan, right_plan: LogicalPlan) -> Result Result<()> { + let values = vec![vec![lit(1)]]; + + let left = LogicalPlanBuilder::values(values.clone())? + .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(()) + } } diff --git a/datafusion/optimizer/src/propagate_empty_relation.rs b/datafusion/optimizer/src/propagate_empty_relation.rs index 4e4280ee80d80..01e16058ec32b 100644 --- a/datafusion/optimizer/src/propagate_empty_relation.rs +++ b/datafusion/optimizer/src/propagate_empty_relation.rs @@ -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) } @@ -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) } diff --git a/datafusion/sql/tests/integration_test.rs b/datafusion/sql/tests/integration_test.rs index 44c0559ef35a3..71f5bf05e99e6 100644 --- a/datafusion/sql/tests/integration_test.rs +++ b/datafusion/sql/tests/integration_test.rs @@ -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=[[]]\