Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: port limit tests to sqllogictests #5355

Merged
merged 1 commit into from
Feb 23, 2023
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
162 changes: 0 additions & 162 deletions datafusion/core/tests/sql/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion datafusion/core/tests/sqllogictests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading