Skip to content

Commit

Permalink
Move subset of select tests to sqllogic (#4583)
Browse files Browse the repository at this point in the history
* Move subset of select tests to sqllogic

* add the slt file
  • Loading branch information
ajayaa authored Dec 12, 2022
1 parent c153c13 commit 4d3065e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 76 deletions.
75 changes: 0 additions & 75 deletions datafusion/core/tests/sql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,9 @@ use datafusion::{
use datafusion_common::ScalarValue;
use tempfile::TempDir;

#[tokio::test]
async fn all_where_empty() -> Result<()> {
let ctx = SessionContext::new();
register_aggregate_csv(&ctx).await?;
let sql = "SELECT *
FROM aggregate_test_100
WHERE 1=2";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["++", "++"];
assert_batches_eq!(expected, &actual);
Ok(())
}

#[tokio::test]
async fn select_values_list() -> Result<()> {
let ctx = SessionContext::new();
{
let sql = "VALUES (1)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------+",
"| column1 |",
"+---------+",
"| 1 |",
"+---------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "VALUES (-1)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------+",
"| column1 |",
"+---------+",
"| -1 |",
"+---------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "VALUES (2+1,2-1,2>1)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------+---------+---------+",
"| column1 | column2 | column3 |",
"+---------+---------+---------+",
"| 3 | 1 | true |",
"+---------+---------+---------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "VALUES";
let plan = ctx.create_logical_plan(sql);
Expand All @@ -85,37 +36,11 @@ async fn select_values_list() -> Result<()> {
let plan = ctx.create_logical_plan(sql);
assert!(plan.is_err());
}
{
let sql = "VALUES (1),(2)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------+",
"| column1 |",
"+---------+",
"| 1 |",
"| 2 |",
"+---------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "VALUES (1),()";
let plan = ctx.create_logical_plan(sql);
assert!(plan.is_err());
}
{
let sql = "VALUES (1,'a'),(2,'b')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------+---------+",
"| column1 | column2 |",
"+---------+---------+",
"| 1 | a |",
"| 2 | b |",
"+---------+---------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "VALUES (1),(1,2)";
let plan = ctx.create_logical_plan(sql);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sqllogictests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn check_test_file(filters: &[&str], path: &Path) -> bool {
/// Create a SessionContext, configured for the specific test
async fn context_for_test_file(file_name: &str) -> SessionContext {
match file_name {
"aggregate.slt" => {
"aggregate.slt" | "select.slt" => {
info!("Registering aggregate tables");
let ctx = SessionContext::new();
setup::register_aggregate_tables(&ctx).await;
Expand Down
58 changes: 58 additions & 0 deletions datafusion/core/tests/sqllogictests/test_files/select.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

# 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.

##########
## SELECT Tests
##########

# all where empty
query II
SELECT * FROM aggregate_test_100 WHERE 1=2
----

# Simple values function
query I
VALUES (1)
----
1

# VALUES with a negative values
query I
VALUES (-1)
----
-1

# foo bar
query IIC
VALUES (2+1,2-1,2>1)
----
3 1 true

# multiple rows values
query I
VALUES (1),(2)
----
1
2

# multiple rows and columns from VALUES
query IC
VALUES (1,'a'),(2,'b')
----
1 a
2 b

0 comments on commit 4d3065e

Please sign in to comment.