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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 3b8b94eae minor: port limit tests to sqllogictests (#5355)
3b8b94eae is described below

commit 3b8b94eaec3569af6b954134289e4b1990f41018
Author: jakevin <[email protected]>
AuthorDate: Thu Feb 23 21:28:41 2023 +0800

    minor: port limit tests to sqllogictests (#5355)
---
 datafusion/core/tests/sql/limit.rs                 | 162 -----------
 datafusion/core/tests/sqllogictests/README.md      |   2 +-
 .../core/tests/sqllogictests/test_files/limit.slt  | 302 +++++++++++++++++++++
 3 files changed, 303 insertions(+), 163 deletions(-)

diff --git a/datafusion/core/tests/sql/limit.rs 
b/datafusion/core/tests/sql/limit.rs
index 261e7f819..a4247492b 100644
--- a/datafusion/core/tests/sql/limit.rs
+++ b/datafusion/core/tests/sql/limit.rs
@@ -17,87 +17,6 @@
 
 use super::*;
 
-#[tokio::test]
-async fn csv_query_limit() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 LIMIT 2";
-    let actual = execute_to_batches(&ctx, sql).await;
-    #[rustfmt::skip]
-    let expected = vec![
-        "+----+",
-        "| c1 |",
-        "+----+",
-        "| c  |",
-        "| d  |",
-        "+----+"
-    ];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_limit_bigger_than_nbr_of_rows() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c2 FROM aggregate_test_100 LIMIT 200";
-    let actual = execute_to_batches(&ctx, sql).await;
-    // println!("{}", pretty_format_batches(&a).unwrap());
-    let expected = vec![
-        "+----+", "| c2 |", "+----+", "| 2  |", "| 5  |", "| 1  |", "| 1  |", 
"| 5  |",
-        "| 4  |", "| 3  |", "| 3  |", "| 1  |", "| 4  |", "| 1  |", "| 4  |", 
"| 3  |",
-        "| 2  |", "| 1  |", "| 1  |", "| 2  |", "| 1  |", "| 3  |", "| 2  |", 
"| 4  |",
-        "| 1  |", "| 5  |", "| 4  |", "| 2  |", "| 1  |", "| 4  |", "| 5  |", 
"| 2  |",
-        "| 3  |", "| 4  |", "| 2  |", "| 1  |", "| 5  |", "| 3  |", "| 1  |", 
"| 2  |",
-        "| 3  |", "| 3  |", "| 3  |", "| 2  |", "| 4  |", "| 1  |", "| 3  |", 
"| 2  |",
-        "| 5  |", "| 2  |", "| 1  |", "| 4  |", "| 1  |", "| 4  |", "| 2  |", 
"| 5  |",
-        "| 4  |", "| 2  |", "| 3  |", "| 4  |", "| 4  |", "| 4  |", "| 5  |", 
"| 4  |",
-        "| 2  |", "| 1  |", "| 2  |", "| 4  |", "| 2  |", "| 3  |", "| 5  |", 
"| 1  |",
-        "| 1  |", "| 4  |", "| 2  |", "| 1  |", "| 2  |", "| 1  |", "| 1  |", 
"| 5  |",
-        "| 4  |", "| 5  |", "| 2  |", "| 3  |", "| 2  |", "| 4  |", "| 1  |", 
"| 3  |",
-        "| 4  |", "| 3  |", "| 2  |", "| 5  |", "| 3  |", "| 3  |", "| 2  |", 
"| 5  |",
-        "| 5  |", "| 4  |", "| 1  |", "| 3  |", "| 3  |", "| 4  |", "| 4  |", 
"+----+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_limit_with_same_nbr_of_rows() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c2 FROM aggregate_test_100 LIMIT 100";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----+", "| c2 |", "+----+", "| 2  |", "| 5  |", "| 1  |", "| 1  |", 
"| 5  |",
-        "| 4  |", "| 3  |", "| 3  |", "| 1  |", "| 4  |", "| 1  |", "| 4  |", 
"| 3  |",
-        "| 2  |", "| 1  |", "| 1  |", "| 2  |", "| 1  |", "| 3  |", "| 2  |", 
"| 4  |",
-        "| 1  |", "| 5  |", "| 4  |", "| 2  |", "| 1  |", "| 4  |", "| 5  |", 
"| 2  |",
-        "| 3  |", "| 4  |", "| 2  |", "| 1  |", "| 5  |", "| 3  |", "| 1  |", 
"| 2  |",
-        "| 3  |", "| 3  |", "| 3  |", "| 2  |", "| 4  |", "| 1  |", "| 3  |", 
"| 2  |",
-        "| 5  |", "| 2  |", "| 1  |", "| 4  |", "| 1  |", "| 4  |", "| 2  |", 
"| 5  |",
-        "| 4  |", "| 2  |", "| 3  |", "| 4  |", "| 4  |", "| 4  |", "| 5  |", 
"| 4  |",
-        "| 2  |", "| 1  |", "| 2  |", "| 4  |", "| 2  |", "| 3  |", "| 5  |", 
"| 1  |",
-        "| 1  |", "| 4  |", "| 2  |", "| 1  |", "| 2  |", "| 1  |", "| 1  |", 
"| 5  |",
-        "| 4  |", "| 5  |", "| 2  |", "| 3  |", "| 2  |", "| 4  |", "| 1  |", 
"| 3  |",
-        "| 4  |", "| 3  |", "| 2  |", "| 5  |", "| 3  |", "| 3  |", "| 2  |", 
"| 5  |",
-        "| 5  |", "| 4  |", "| 1  |", "| 3  |", "| 3  |", "| 4  |", "| 4  |", 
"+----+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_limit_zero() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 LIMIT 0";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec!["++", "++"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
 #[tokio::test]
 async fn limit() -> Result<()> {
     let tmp_dir = TempDir::new()?;
@@ -184,84 +103,3 @@ async fn limit_multi_partitions() -> Result<()> {
 
     Ok(())
 }
-
-#[tokio::test]
-async fn csv_offset_without_limit_99() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 OFFSET 99";
-    let actual = execute_to_batches(&ctx, sql).await;
-
-    #[rustfmt::skip]
-        let expected = vec![
-        "+----+",
-        "| c1 |",
-        "+----+",
-        "| e  |",
-        "+----+"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_offset_without_limit_100() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 OFFSET 100";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec!["++", "++"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_offset_without_limit_101() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 OFFSET 101";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec!["++", "++"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_offset() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 OFFSET 2 LIMIT 2";
-    let actual = execute_to_batches(&ctx, sql).await;
-
-    #[rustfmt::skip]
-        let expected = vec![
-        "+----+",
-        "| c1 |",
-        "+----+",
-        "| b  |",
-        "| a  |",
-        "+----+"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_offset_the_same_as_nbr_of_rows() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 LIMIT 1 OFFSET 100";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec!["++", "++"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn csv_query_offset_bigger_than_nbr_of_rows() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_aggregate_csv(&ctx).await?;
-    let sql = "SELECT c1 FROM aggregate_test_100 LIMIT 1 OFFSET 101";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec!["++", "++"];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
diff --git a/datafusion/core/tests/sqllogictests/README.md 
b/datafusion/core/tests/sqllogictests/README.md
index 2f697921a..f3a06ec5a 100644
--- a/datafusion/core/tests/sqllogictests/README.md
+++ b/datafusion/core/tests/sqllogictests/README.md
@@ -76,7 +76,7 @@ docker run \
 
 #### Updating tests: Completion Mode
 
-In test script completion mode, `sqllogictests` reads a prototype script and 
runs the statements and queries against the database engine. The output is is a 
full script that is a copy of the prototype script with result inserted.
+In test script completion mode, `sqllogictests` reads a prototype script and 
runs the statements and queries against the database engine. The output is a 
full script that is a copy of the prototype script with result inserted.
 
 You can update the tests / generate expected output by passing the 
`--complete` argument.
 
diff --git a/datafusion/core/tests/sqllogictests/test_files/limit.slt 
b/datafusion/core/tests/sqllogictests/test_files/limit.slt
new file mode 100644
index 000000000..253ca8f33
--- /dev/null
+++ b/datafusion/core/tests/sqllogictests/test_files/limit.slt
@@ -0,0 +1,302 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+##########
+## Limit Tests
+##########
+
+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'
+
+# async fn csv_query_limit
+query T
+SELECT c1 FROM aggregate_test_100 LIMIT 2
+----
+c
+d
+
+# async fn csv_query_limit_bigger_than_nbr_of_rows
+query I
+SELECT c2 FROM aggregate_test_100 LIMIT 200
+----
+2
+5
+1
+1
+5
+4
+3
+3
+1
+4
+1
+4
+3
+2
+1
+1
+2
+1
+3
+2
+4
+1
+5
+4
+2
+1
+4
+5
+2
+3
+4
+2
+1
+5
+3
+1
+2
+3
+3
+3
+2
+4
+1
+3
+2
+5
+2
+1
+4
+1
+4
+2
+5
+4
+2
+3
+4
+4
+4
+5
+4
+2
+1
+2
+4
+2
+3
+5
+1
+1
+4
+2
+1
+2
+1
+1
+5
+4
+5
+2
+3
+2
+4
+1
+3
+4
+3
+2
+5
+3
+3
+2
+5
+5
+4
+1
+3
+3
+4
+4
+
+# async fn csv_query_limit_with_same_nbr_of_rows
+query I
+SELECT c2 FROM aggregate_test_100 LIMIT 100
+----
+2
+5
+1
+1
+5
+4
+3
+3
+1
+4
+1
+4
+3
+2
+1
+1
+2
+1
+3
+2
+4
+1
+5
+4
+2
+1
+4
+5
+2
+3
+4
+2
+1
+5
+3
+1
+2
+3
+3
+3
+2
+4
+1
+3
+2
+5
+2
+1
+4
+1
+4
+2
+5
+4
+2
+3
+4
+4
+4
+5
+4
+2
+1
+2
+4
+2
+3
+5
+1
+1
+4
+2
+1
+2
+1
+1
+5
+4
+5
+2
+3
+2
+4
+1
+3
+4
+3
+2
+5
+3
+3
+2
+5
+5
+4
+1
+3
+3
+4
+4
+
+# async fn csv_query_limit_zero
+query T
+SELECT c1 FROM aggregate_test_100 LIMIT 0
+----
+
+# async fn csv_offset_without_limit_99
+query T
+SELECT c1 FROM aggregate_test_100 OFFSET 99
+----
+e
+
+# async fn csv_offset_without_limit_100
+query T
+SELECT c1 FROM aggregate_test_100 OFFSET 100
+----
+
+# async fn csv_offset_without_limit_101
+query T
+SELECT c1 FROM aggregate_test_100 OFFSET 101
+----
+
+# async fn csv_query_offset
+query T
+SELECT c1 FROM aggregate_test_100 OFFSET 2 LIMIT 2
+----
+b
+a
+
+# async fn csv_query_offset_the_same_as_nbr_of_rows
+query T
+SELECT c1 FROM aggregate_test_100 LIMIT 1 OFFSET 100
+----
+
+# async fn csv_query_offset_bigger_than_nbr_of_rows
+query T
+SELECT c1 FROM aggregate_test_100 LIMIT 1 OFFSET 101
+----
+
+########
+# Clean up after the test
+########
+
+statement ok
+drop table aggregate_test_100;

Reply via email to