You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/01/27 20:42:15 UTC

[arrow-datafusion] branch master updated: sqllogicaltest: move union.rs (#5075)

This is an automated email from the ASF dual-hosted git repository.

alamb 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 dd0921263 sqllogicaltest: move union.rs (#5075)
dd0921263 is described below

commit dd092126328a468f1c7100c50fe2477c6e0e897a
Author: jakevin <ja...@gmail.com>
AuthorDate: Sat Jan 28 04:42:08 2023 +0800

    sqllogicaltest: move union.rs (#5075)
    
    * sqllogicaltest: move union.rs
    
    * add order by to confirm the order of result
    correct type.
    
    * correct type.
---
 datafusion/core/tests/sql/union.rs                 | 124 ---------------------
 .../core/tests/sqllogictests/test_files/union.slt  | 122 +++++++++++++++++++-
 2 files changed, 120 insertions(+), 126 deletions(-)

diff --git a/datafusion/core/tests/sql/union.rs b/datafusion/core/tests/sql/union.rs
index abc1b00d7..804833bb9 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.slt
index 8e4034052..7f387e8c5 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 name
 Alice
 John
 
-
-
 # union with type coercion
 query T
 (   
@@ -76,3 +74,123 @@ ORDER BY name
 ----
 3 Alice
 3 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