Apache DataFusion SQL Query Engine
sqllogicaltest: move union.rs (#5075)
jakevindd092126328a
diff --git a/datafusion/core/tests/sql/union.rs b/datafusion/core/tests/sql/union.rsindex abc1b00d76..804833bb9d 100644--- a/datafusion/core/tests/sql/union.rs+++ b/datafusion/core/tests/sql/union.rs@@ -17,130 +17,6 @@use super::*;-#[tokio::test]-async fn union_all() -> Result<()> {- let ctx = SessionContext::new();- let sql = "SELECT 1 as x UNION ALL SELECT 2 as x";- let actual = execute_to_batches(&ctx, sql).await;- #[rustfmt::skip]- let expected = vec![- "+---+",- "| x |",- "+---+",- "| 1 |",- "| 2 |",- "+---+"- ];- assert_batches_eq!(expected, &actual);- Ok(())-}--#[tokio::test]-async fn csv_union_all() -> Result<()> {- let ctx = SessionContext::new();- register_aggregate_csv(&ctx).await?;- let sql =- "SELECT c1 FROM aggregate_test_100 UNION ALL SELECT c1 FROM aggregate_test_100";- let actual = execute(&ctx, sql).await;- assert_eq!(actual.len(), 200);- Ok(())-}--#[tokio::test]-async fn union_distinct() -> Result<()> {- let ctx = SessionContext::new();- let sql = "SELECT 1 as x UNION SELECT 1 as x";- let actual = execute_to_batches(&ctx, sql).await;- #[rustfmt::skip]- let expected = vec![- "+---+",- "| x |",- "+---+",- "| 1 |",- "+---+"- ];- assert_batches_eq!(expected, &actual);- Ok(())-}--#[tokio::test]-async fn union_all_with_aggregate() -> Result<()> {- let ctx = SessionContext::new();- let sql =- "SELECT SUM(d) FROM (SELECT 1 as c, 2 as d UNION ALL SELECT 1 as c, 3 AS d) as a";- let actual = execute_to_batches(&ctx, sql).await;- let expected = vec![- "+----------+",- "| SUM(a.d) |",- "+----------+",- "| 5 |",- "+----------+",- ];- assert_batches_eq!(expected, &actual);- Ok(())-}--#[tokio::test]-async fn union_all_with_count() -> Result<()> {- let ctx = SessionContext::new();- execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;- let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)";- let actual = execute_to_batches(&ctx, sql).await;- let expected = vec![- "+-----------------+",- "| COUNT(UInt8(1)) |",- "+-----------------+",- "| 2 |",- "+-----------------+",- ];- assert_batches_eq!(expected, &actual);- Ok(())-}--#[tokio::test]-async fn union_schemas() -> Result<()> {- let ctx =- SessionContext::with_config(SessionConfig::new().with_information_schema(true));-- let result = ctx- .sql("SELECT 1 A UNION ALL SELECT 2 order by 1")- .await- .unwrap()- .collect()- .await- .unwrap();-- #[rustfmt::skip]- let expected = vec![- "+---+",- "| a |",- "+---+",- "| 1 |",- "| 2 |",- "+---+"- ];- assert_batches_eq!(expected, &result);-- let result = ctx- .sql("SELECT 1 UNION SELECT 2 order by 1")- .await- .unwrap()- .collect()- .await- .unwrap();-- let expected = vec![- "+----------+",- "| Int64(1) |",- "+----------+",- "| 1 |",- "| 2 |",- "+----------+",- ];- assert_batches_eq!(expected, &result);- Ok(())-}-#[tokio::test]async fn union_with_except_input() -> Result<()> {let ctx = create_union_context()?;diff --git a/datafusion/core/tests/sqllogictests/test_files/union.slt b/datafusion/core/tests/sqllogictests/test_files/union.sltindex 8e4034052a..7f387e8c51 100644--- a/datafusion/core/tests/sqllogictests/test_files/union.slt+++ b/datafusion/core/tests/sqllogictests/test_files/union.slt@@ -57,8 +57,6 @@ ORDER BY nameAliceJohn--# union with type coercionquery T(@@ -76,3 +74,123 @@ ORDER BY name----3 Alice3 John++# union all+query I+SELECT 1 as x+UNION ALL+SELECT 2 as x+----+1+2++# csv_union_all+statement ok+CREATE EXTERNAL TABLE aggregate_test_100 (+ c1 VARCHAR NOT NULL,+ c2 TINYINT NOT NULL,+ c3 SMALLINT NOT NULL,+ c4 SMALLINT,+ c5 INT,+ c6 BIGINT NOT NULL,+ c7 SMALLINT NOT NULL,+ c8 INT NOT NULL,+ c9 BIGINT UNSIGNED NOT NULL,+ c10 VARCHAR NOT NULL,+ c11 FLOAT NOT NULL,+ c12 DOUBLE NOT NULL,+ c13 VARCHAR NOT NULL+)+STORED AS CSV+WITH HEADER ROW+LOCATION '../../testing/data/csv/aggregate_test_100.csv'++query I+select COUNT(*) from (+ SELECT c1 FROM aggregate_test_100+ UNION ALL+ SELECT c1 FROM aggregate_test_100+)+----+200++# union_distinct+query I+SELECT 1 as x+UNION+SELECT 1 as x+----+1++# union_all_with_aggregate+query I+SELECT SUM(d) FROM (+ SELECT 1 as c, 2 as d+ UNION ALL+ SELECT 1 as c, 3 AS d+) as a+----+5++# union_all_with_count+statement ok+CREATE table t as SELECT 1 as a++query I+SELECT COUNT(*) FROM (+ SELECT a from t+ UNION ALL+ SELECT a from t+)+----+2++# union_schemas+query I+SELECT 1 A UNION ALL SELECT 2 order by 1+----+1+2++# union_schemas+query I+SELECT 1 UNION SELECT 2 order by 1+----+1+2++# union_with_except_input+query T+SELECT * FROM (+ (+ SELECT name FROM t1+ EXCEPT+ SELECT name FROM t2+ )+ UNION ALL+ (+ SELECT name FROM t2+ EXCEPT+ SELECT name FROM t1+ )+) ORDER BY name+----+Alice+John++# union_with_type_coercion+query IT+(+ SELECT id, name FROM t1+ EXCEPT+ SELECT id, name FROM t2+)+UNION ALL+(+ SELECT id, name FROM t2+ EXCEPT+ SELECT id, name FROM t1+)+----+3 Alice+3 John