Skip to content

Apache DataFusion SQL Query Engine

Port test in select.rs to sqllogic (#6158)

Armin Primadi2f39479b6c46
diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rs
index 6218640b9c..52d338d9e9 100644
--- a/datafusion/core/tests/sql/select.rs
+++ b/datafusion/core/tests/sql/select.rs
@@ -16,265 +16,9 @@
// under the License.
use super::*;
-use datafusion::{datasource::empty::EmptyTable, from_slice::FromSlice};
use datafusion_common::ScalarValue;
use tempfile::TempDir;
-#[tokio::test]
-async fn select_all() -> Result<()> {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await?;
-
- let sql = "SELECT c1 FROM aggregate_simple order by c1";
- let results = execute_to_batches(&ctx, sql).await;
-
- let sql_all = "SELECT ALL c1 FROM aggregate_simple order by c1";
- let results_all = execute_to_batches(&ctx, sql_all).await;
-
- let expected = vec![
- "+---------+",
- "| c1 |",
- "+---------+",
- "| 0.00001 |",
- "| 0.00002 |",
- "| 0.00002 |",
- "| 0.00003 |",
- "| 0.00003 |",
- "| 0.00003 |",
- "| 0.00004 |",
- "| 0.00004 |",
- "| 0.00004 |",
- "| 0.00004 |",
- "| 0.00005 |",
- "| 0.00005 |",
- "| 0.00005 |",
- "| 0.00005 |",
- "| 0.00005 |",
- "+---------+",
- ];
-
- assert_batches_eq!(expected, &results);
- assert_batches_eq!(expected, &results_all);
-
- Ok(())
-}
-
-#[tokio::test]
-async fn select_distinct() -> Result<()> {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await?;
-
- let sql = "SELECT DISTINCT * FROM aggregate_simple";
- let mut actual = execute(&ctx, sql).await;
- actual.sort();
-
- let mut dedup = actual.clone();
- dedup.dedup();
-
- assert_eq!(actual, dedup);
-
- Ok(())
-}
-
-#[tokio::test]
-async fn select_distinct_simple_1() {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await.unwrap();
-
- let sql = "SELECT DISTINCT c1 FROM aggregate_simple order by c1";
- let actual = execute_to_batches(&ctx, sql).await;
-
- let expected = vec![
- "+---------+",
- "| c1 |",
- "+---------+",
- "| 0.00001 |",
- "| 0.00002 |",
- "| 0.00003 |",
- "| 0.00004 |",
- "| 0.00005 |",
- "+---------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn select_distinct_simple_2() {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await.unwrap();
-
- let sql = "SELECT DISTINCT c1, c2 FROM aggregate_simple order by c1";
- let actual = execute_to_batches(&ctx, sql).await;
-
- let expected = vec![
- "+---------+---------+",
- "| c1 | c2 |",
- "+---------+---------+",
- "| 0.00001 | 1.0e-12 |",
- "| 0.00002 | 2.0e-12 |",
- "| 0.00003 | 3.0e-12 |",
- "| 0.00004 | 4.0e-12 |",
- "| 0.00005 | 5.0e-12 |",
- "+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn select_distinct_simple_3() {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await.unwrap();
-
- let sql = "SELECT distinct c3 FROM aggregate_simple order by c3";
- let actual = execute_to_batches(&ctx, sql).await;
-
- let expected = vec![
- "+-------+",
- "| c3 |",
- "+-------+",
- "| false |",
- "| true |",
- "+-------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn select_distinct_simple_4() {
- let ctx = SessionContext::new();
- register_aggregate_simple_csv(&ctx).await.unwrap();
-
- let sql = "SELECT distinct c1+c2 as a FROM aggregate_simple";
- let actual = execute_to_batches(&ctx, sql).await;
-
- let expected = vec![
- "+-------------------------+",
- "| a |",
- "+-------------------------+",
- "| 0.000030000002242136256 |",
- "| 0.000040000002989515004 |",
- "| 0.000010000000747378751 |",
- "| 0.00005000000373689376 |",
- "| 0.000020000001494757502 |",
- "+-------------------------+",
- ];
- assert_batches_sorted_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn select_distinct_from() {
- let ctx = SessionContext::new();
-
- let sql = "select
- 1 IS DISTINCT FROM CAST(NULL as INT) as a,
- 1 IS DISTINCT FROM 1 as b,
- 1 IS NOT DISTINCT FROM CAST(NULL as INT) as c,
- 1 IS NOT DISTINCT FROM 1 as d,
- NULL IS DISTINCT FROM NULL as e,
- NULL IS NOT DISTINCT FROM NULL as f,
- NULL is DISTINCT FROM 1 as g,
- NULL is NOT DISTINCT FROM 1 as h
- ";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+------+-------+-------+------+-------+------+------+-------+",
- "| a | b | c | d | e | f | g | h |",
- "+------+-------+-------+------+-------+------+------+-------+",
- "| true | false | false | true | false | true | true | false |",
- "+------+-------+-------+------+-------+------+------+-------+",
- ];
- assert_batches_eq!(expected, &actual);
-
- let sql = "select
- NULL IS DISTINCT FROM NULL as a,
- NULL IS NOT DISTINCT FROM NULL as b,
- NULL is DISTINCT FROM 1 as c,
- NULL is NOT DISTINCT FROM 1 as d,
- 1 IS DISTINCT FROM CAST(NULL as INT) as e,
- 1 IS DISTINCT FROM 1 as f,
- 1 IS NOT DISTINCT FROM CAST(NULL as INT) as g,
- 1 IS NOT DISTINCT FROM 1 as h
- ";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+------+------+-------+------+-------+-------+------+",
- "| a | b | c | d | e | f | g | h |",
- "+-------+------+------+-------+------+-------+-------+------+",
- "| false | true | true | false | true | false | false | true |",
- "+-------+------+------+-------+------+-------+-------+------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn select_distinct_from_utf8() {
- let ctx = SessionContext::new();
-
- let sql = "select
- 'x' IS DISTINCT FROM NULL as a,
- 'x' IS DISTINCT FROM 'x' as b,
- 'x' IS NOT DISTINCT FROM NULL as c,
- 'x' IS NOT DISTINCT FROM 'x' as d
- ";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+------+-------+-------+------+",
- "| a | b | c | d |",
- "+------+-------+-------+------+",
- "| true | false | false | true |",
- "+------+-------+-------+------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn use_between_expression_in_select_query() -> Result<()> {
- let ctx = SessionContext::new();
-
- let sql = "SELECT 1 NOT BETWEEN 3 AND 5";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+--------------------------------------------+",
- "| Int64(1) NOT BETWEEN Int64(3) AND Int64(5) |",
- "+--------------------------------------------+",
- "| true |",
- "+--------------------------------------------+",
- ];
- assert_batches_eq!(expected, &actual);
-
- let input = Int64Array::from_slice([1, 2, 3, 4]);
- let batch = RecordBatch::try_from_iter(vec![("c1", Arc::new(input) as _)]).unwrap();
- ctx.register_batch("test", batch)?;
-
- let sql = "SELECT abs(c1) BETWEEN 0 AND LoG(c1 * 100 ) FROM test";
- let actual = execute_to_batches(&ctx, sql).await;
- // Expect field name to be correctly converted for expr, low and high.
- let expected = vec![
- "+-------------------------------------------------------------+",
- "| abs(test.c1) BETWEEN Int64(0) AND log(test.c1 * Int64(100)) |",
- "+-------------------------------------------------------------+",
- "| true |",
- "| true |",
- "| false |",
- "| false |",
- "+-------------------------------------------------------------+",
- ];
- assert_batches_eq!(expected, &actual);
-
- let sql = "EXPLAIN SELECT c1 BETWEEN 2 AND 3 FROM test";
- let actual = execute_to_batches(&ctx, sql).await;
- let formatted = arrow::util::pretty::pretty_format_batches(&actual)
- .unwrap()
- .to_string();
-
- // Only test that the projection exprs are correct, rather than entire output
- let needle = "ProjectionExec: expr=[c1@0 >= 2 AND c1@0 <= 3 as test.c1 BETWEEN Int64(2) AND Int64(3)]";
- assert_contains!(&formatted, needle);
- let needle = "Projection: test.c1 >= Int64(2) AND test.c1 <= Int64(3)";
- assert_contains!(&formatted, needle);
- Ok(())
-}
-
#[tokio::test]
async fn query_get_indexed_field() -> Result<()> {
let ctx = SessionContext::new();
@@ -738,354 +482,6 @@ async fn sort_on_window_null_string() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn filter_with_time32second() -> Result<()> {
- let ctx = SessionContext::new();
- let schema = Arc::new(Schema::new(vec![
- Field::new("time", DataType::Time32(TimeUnit::Second), false),
- Field::new("value", DataType::Int64, false),
- ]));
- let data = RecordBatch::try_new(
- schema.clone(),
- vec![
- Arc::new(Time32SecondArray::from(vec![
- Some(5_000),
- Some(5_000),
- Some(5_500),
- Some(5_500),
- Some(5_900),
- Some(5_900),
- ])),
- Arc::new(Int64Array::from(vec![
- Some(2505),
- Some(2436),
- Some(2384),
- Some(1815),
- Some(2330),
- Some(2065),
- ])),
- ],
- )?;
-
- ctx.register_batch("temporal", data)?;
- let sql = "SELECT value FROM temporal WHERE time = '01:23:20'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+",
- "| value |",
- "+-------+",
- "| 2436 |",
- "| 2505 |",
- "+-------+",
- ];
- assert_batches_sorted_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn filter_with_time32millisecond() -> Result<()> {
- let ctx = SessionContext::new();
- let schema = Arc::new(Schema::new(vec![
- Field::new("time", DataType::Time32(TimeUnit::Millisecond), false),
- Field::new("value", DataType::Int64, false),
- ]));
- let data = RecordBatch::try_new(
- schema.clone(),
- vec![
- Arc::new(Time32MillisecondArray::from(vec![
- Some(5_000_000),
- Some(5_000_000),
- Some(5_500_000),
- Some(5_500_000),
- Some(5_900_000),
- Some(5_900_000),
- ])),
- Arc::new(Int64Array::from(vec![
- Some(2505),
- Some(2436),
- Some(2384),
- Some(1815),
- Some(2330),
- Some(2065),
- ])),
- ],
- )?;
-
- ctx.register_batch("temporal", data)?;
- let sql = "SELECT value FROM temporal WHERE time = '01:23:20'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+",
- "| value |",
- "+-------+",
- "| 2436 |",
- "| 2505 |",
- "+-------+",
- ];
- assert_batches_sorted_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn filter_with_time64microsecond() -> Result<()> {
- let ctx = SessionContext::new();
- let schema = Arc::new(Schema::new(vec![
- Field::new("time", DataType::Time64(TimeUnit::Microsecond), false),
- Field::new("value", DataType::Int64, false),
- ]));
- let data = RecordBatch::try_new(
- schema.clone(),
- vec![
- Arc::new(Time64MicrosecondArray::from(vec![
- Some(5_000_000_000),
- Some(5_000_000_000),
- Some(5_500_000_000),
- Some(5_500_000_000),
- Some(5_900_000_000),
- Some(5_900_000_000),
- ])),
- Arc::new(Int64Array::from(vec![
- Some(2505),
- Some(2436),
- Some(2384),
- Some(1815),
- Some(2330),
- Some(2065),
- ])),
- ],
- )?;
-
- ctx.register_batch("temporal", data)?;
- let sql = "SELECT value FROM temporal WHERE time = '01:23:20'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+",
- "| value |",
- "+-------+",
- "| 2436 |",
- "| 2505 |",
- "+-------+",
- ];
- assert_batches_sorted_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn filter_with_time64nanosecond() -> Result<()> {
- let ctx = SessionContext::new();
- let schema = Arc::new(Schema::new(vec![
- Field::new("time", DataType::Time64(TimeUnit::Nanosecond), false),
- Field::new("value", DataType::Int64, false),
- ]));
- let data = RecordBatch::try_new(
- schema.clone(),
- vec![
- Arc::new(Time64NanosecondArray::from(vec![
- Some(5_000_000_000_000),
- Some(5_000_000_000_000),
- Some(5_500_000_000_000),
- Some(5_500_000_000_000),
- Some(5_900_000_000_000),
- Some(5_900_000_000_000),
- ])),
- Arc::new(Int64Array::from(vec![
- Some(2505),
- Some(2436),
- Some(2384),
- Some(1815),
- Some(2330),
- Some(2065),
- ])),
- ],
- )?;
-
- ctx.register_batch("temporal", data)?;
- let sql = "SELECT value FROM temporal WHERE time = '01:23:20'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+",
- "| value |",
- "+-------+",
- "| 2436 |",
- "| 2505 |",
- "+-------+",
- ];
- assert_batches_sorted_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn query_cte_with_alias() -> Result<()> {
- let ctx = SessionContext::new();
- let schema = Schema::new(vec![
- Field::new("id", DataType::Int16, false),
- Field::new("a", DataType::Int16, false),
- ]);
- let empty_table = Arc::new(EmptyTable::new(Arc::new(schema)));
- ctx.register_table("t1", empty_table)?;
- let sql = "WITH \
- v1 AS (SELECT * FROM t1), \
- v2 AS (SELECT v1.id AS id, v1a.id AS id_a, v1b.id AS id_b \
- FROM v1, v1 v1a, v1 v1b \
- WHERE v1a.id = v1.id - 1 \
- AND v1b.id = v1.id + 1) \
- SELECT * FROM v2";
- let actual = execute_to_batches(&ctx, sql).await;
- // the purpose of this test is just to make sure the query produces a valid plan
- let expected = vec!["++", "++"];
- assert_batches_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn query_cte() -> Result<()> {
- // Test for SELECT <expression> without FROM.
- // Should evaluate expressions in project position.
- let ctx = SessionContext::new();
-
- // simple with
- let sql = "WITH t AS (SELECT 1) SELECT * FROM t";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+----------+",
- "| Int64(1) |",
- "+----------+",
- "| 1 |",
- "+----------+",
- ];
- assert_batches_eq!(expected, &actual);
-
- // with + union
- let sql =
- "WITH t AS (SELECT 1 AS a), u AS (SELECT 2 AS a) SELECT * FROM t UNION ALL SELECT * FROM u";
- let actual = execute_to_batches(&ctx, sql).await;
- #[rustfmt::skip]
- let expected = vec![
- "+---+",
- "| a |",
- "+---+",
- "| 1 |",
- "| 2 |",
- "+---+"
- ];
- assert_batches_eq!(expected, &actual);
-
- // with + join
- let sql = "WITH t AS (SELECT 1 AS id1), u AS (SELECT 1 AS id2, 5 as x) SELECT x FROM t JOIN u ON (id1 = id2)";
- let actual = execute_to_batches(&ctx, sql).await;
- #[rustfmt::skip]
- let expected = vec![
- "+---+",
- "| x |",
- "+---+",
- "| 5 |",
- "+---+"
- ];
- assert_batches_eq!(expected, &actual);
-
- // backward reference
- let sql = "WITH t AS (SELECT 1 AS id1), u AS (SELECT * FROM t) SELECT * from u";
- let actual = execute_to_batches(&ctx, sql).await;
- #[rustfmt::skip]
- let expected = vec![
- "+-----+",
- "| id1 |",
- "+-----+",
- "| 1 |",
- "+-----+"
- ];
- assert_batches_eq!(expected, &actual);
-
- Ok(())
-}
-
-#[tokio::test]
-async fn csv_select_nested() -> Result<()> {
- let ctx = SessionContext::new();
- register_aggregate_csv(&ctx).await?;
- let sql = "SELECT o1, o2, c3
- FROM (
- SELECT c1 AS o1, c2 + 1 AS o2, c3
- FROM (
- SELECT c1, c2, c3, c4
- FROM aggregate_test_100
- WHERE c1 = 'a' AND c2 >= 4
- ORDER BY c2 ASC, c3 ASC
- ) AS a
- ) AS b";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+----+----+------+",
- "| o1 | o2 | c3 |",
- "+----+----+------+",
- "| a | 5 | -101 |",
- "| a | 5 | -54 |",
- "| a | 5 | -38 |",
- "| a | 5 | 65 |",
- "| a | 6 | -101 |",
- "| a | 6 | -31 |",
- "| a | 6 | 36 |",
- "+----+----+------+",
- ];
- assert_batches_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn csv_select_nested_without_aliases() -> Result<()> {
- let ctx = SessionContext::new();
- register_aggregate_csv(&ctx).await?;
- let sql = "SELECT o1, o2, c3
- FROM (
- SELECT c1 AS o1, c2 + 1 AS o2, c3
- FROM (
- SELECT c1, c2, c3, c4
- FROM aggregate_test_100
- WHERE c1 = 'a' AND c2 >= 4
- ORDER BY c2 ASC, c3 ASC
- )
- )";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+----+----+------+",
- "| o1 | o2 | c3 |",
- "+----+----+------+",
- "| a | 5 | -101 |",
- "| a | 5 | -54 |",
- "| a | 5 | -38 |",
- "| a | 5 | 65 |",
- "| a | 6 | -101 |",
- "| a | 6 | -31 |",
- "| a | 6 | 36 |",
- "+----+----+------+",
- ];
- assert_batches_eq!(expected, &actual);
- Ok(())
-}
-
-#[tokio::test]
-async fn csv_join_unaliased_subqueries() -> Result<()> {
- let ctx = SessionContext::new();
- register_aggregate_csv(&ctx).await?;
- let sql = "SELECT o1, o2, c3, p1, p2, p3 FROM \
- (SELECT c1 AS o1, c2 + 1 AS o2, c3 FROM aggregate_test_100), \
- (SELECT c1 AS p1, c2 - 1 AS p2, c3 AS p3 FROM aggregate_test_100) LIMIT 5";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+----+----+----+----+----+-----+",
- "| o1 | o2 | c3 | p1 | p2 | p3 |",
- "+----+----+----+----+----+-----+",
- "| c | 3 | 1 | c | 1 | 1 |",
- "| c | 3 | 1 | d | 4 | -40 |",
- "| c | 3 | 1 | b | 0 | 29 |",
- "| c | 3 | 1 | a | 0 | -85 |",
- "| c | 3 | 1 | b | 4 | -82 |",
- "+----+----+----+----+----+-----+",
- ];
- assert_batches_eq!(expected, &actual);
- Ok(())
-}
-
// Test prepare statement from sql to final result
// This test is equivalent with the test parallel_query_with_filter below but using prepare statement
#[tokio::test]
@@ -1176,56 +572,6 @@ async fn parallel_query_with_filter() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn query_with_filter_string_type_coercion() {
- let large_string_array = LargeStringArray::from(vec!["1", "2", "3", "4", "5"]);
- let schema =
- Schema::new(vec![Field::new("large_string", DataType::LargeUtf8, false)]);
- let batch =
- RecordBatch::try_new(Arc::new(schema), vec![Arc::new(large_string_array)])
- .unwrap();
-
- let ctx = SessionContext::new();
- ctx.register_batch("t", batch).unwrap();
- let sql = "select * from t where large_string = '1'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+--------------+",
- "| large_string |",
- "+--------------+",
- "| 1 |",
- "+--------------+",
- ];
- assert_batches_eq!(expected, &actual);
-
- let sql = "select * from t where large_string != '1'";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+--------------+",
- "| large_string |",
- "+--------------+",
- "| 2 |",
- "| 3 |",
- "| 4 |",
- "| 5 |",
- "+--------------+",
- ];
- assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn query_empty_table() {
- let ctx = SessionContext::new();
- let empty_table = Arc::new(EmptyTable::new(Arc::new(Schema::empty())));
- ctx.register_table("test_tbl", empty_table).unwrap();
- let sql = "SELECT * FROM test_tbl";
- let result = plan_and_collect(&ctx, sql)
- .await
- .expect("Query empty table");
- let expected = vec!["++", "++"];
- assert_batches_sorted_eq!(expected, &result);
-}
-
#[tokio::test]
async fn boolean_literal() -> Result<()> {
let results =
@@ -1274,37 +620,3 @@ async fn unprojected_filter() {
];
assert_batches_sorted_eq!(expected, &results);
}
-
-#[tokio::test]
-async fn case_sensitive_in_default_dialect() {
- let int32_array = Int32Array::from(vec![1, 2, 3, 4, 5]);
- let schema = Schema::new(vec![Field::new("INT32", DataType::Int32, false)]);
- let batch =
- RecordBatch::try_new(Arc::new(schema), vec![Arc::new(int32_array)]).unwrap();
-
- let ctx = SessionContext::new();
- ctx.register_batch("t", batch).unwrap();
-
- {
- let sql = "select \"int32\" from t";
- ctx.sql(sql).await.unwrap_err();
- }
-
- {
- let sql = "select \"INT32\" from t";
- let actual = execute_to_batches(&ctx, sql).await;
-
- let expected = vec![
- "+-------+",
- "| INT32 |",
- "+-------+",
- "| 1 |",
- "| 2 |",
- "| 3 |",
- "| 4 |",
- "| 5 |",
- "+-------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
-}
diff --git a/datafusion/core/tests/sqllogictests/src/main.rs b/datafusion/core/tests/sqllogictests/src/main.rs
index 46ea60da06..841511decf 100644
--- a/datafusion/core/tests/sqllogictests/src/main.rs
+++ b/datafusion/core/tests/sqllogictests/src/main.rs
@@ -168,7 +168,7 @@ async fn context_for_test_file(relative_path: &Path) -> SessionContext {
let ctx = SessionContext::with_config(config);
match relative_path.file_name().unwrap().to_str().unwrap() {
- "aggregate.slt" | "select.slt" => {
+ "aggregate.slt" => {
info!("Registering aggregate tables");
setup::register_aggregate_tables(&ctx).await;
}
diff --git a/datafusion/core/tests/sqllogictests/test_files/select.slt b/datafusion/core/tests/sqllogictests/test_files/select.slt
index 7d5a7717a7..ff523d713d 100644
--- a/datafusion/core/tests/sqllogictests/test_files/select.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/select.slt
@@ -16,6 +16,37 @@
# specific language governing permissions and limitations
# under the License.
+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'
+
+statement ok
+CREATE EXTERNAL TABLE aggregate_simple (
+ c1 FLOAT NOT NULL,
+ c2 DOUBLE NOT NULL,
+ c3 BOOLEAN NOT NULL
+)
+STORED AS CSV
+WITH HEADER ROW
+LOCATION 'tests/data/aggregate_simple.csv'
+
+
##########
## SELECT Tests
##########
@@ -265,3 +296,394 @@ query B
select column1 is not distinct from column2 from t;
----
false
+
+
+# select all
+# these two queries should return the same result
+query R
+SELECT c1 FROM aggregate_simple order by c1
+----
+0.00001
+0.00002
+0.00002
+0.00003
+0.00003
+0.00003
+0.00004
+0.00004
+0.00004
+0.00004
+0.00005
+0.00005
+0.00005
+0.00005
+0.00005
+
+query R
+SELECT ALL c1 FROM aggregate_simple order by c1
+----
+0.00001
+0.00002
+0.00002
+0.00003
+0.00003
+0.00003
+0.00004
+0.00004
+0.00004
+0.00004
+0.00005
+0.00005
+0.00005
+0.00005
+0.00005
+
+# select distinct
+query RRB rowsort
+SELECT DISTINCT * FROM aggregate_simple
+----
+0.00001 0.000000000001 true
+0.00002 0.000000000002 false
+0.00003 0.000000000003 true
+0.00004 0.000000000004 false
+0.00005 0.000000000005 true
+
+# select distinct with projection and order by
+query R
+SELECT DISTINCT c1 FROM aggregate_simple order by c1
+----
+0.00001
+0.00002
+0.00003
+0.00004
+0.00005
+
+# select distinct with multi-columns projection and single-column order by
+query RR
+SELECT DISTINCT c1, c2 FROM aggregate_simple order by c1
+----
+0.00001 0.000000000001
+0.00002 0.000000000002
+0.00003 0.000000000003
+0.00004 0.000000000004
+0.00005 0.000000000005
+
+# select distinct boolean column
+query B
+SELECT DISTINCT c3 FROM aggregate_simple order by c3
+----
+false
+true
+
+# select distinct with addition expression
+query R rowsort
+SELECT DISTINCT c1 + c2 AS a FROM aggregate_simple
+----
+0.000010000001
+0.000020000001
+0.000030000002
+0.000040000003
+0.000050000004
+
+# select distinct from
+query BBBBBBBB
+select
+1 IS DISTINCT FROM CAST(NULL as INT) as a,
+1 IS DISTINCT FROM 1 as b,
+1 IS NOT DISTINCT FROM CAST(NULL as INT) as c,
+1 IS NOT DISTINCT FROM 1 as d,
+NULL IS DISTINCT FROM NULL as e,
+NULL IS NOT DISTINCT FROM NULL as f,
+NULL is DISTINCT FROM 1 as g,
+NULL is NOT DISTINCT FROM 1 as h
+----
+true false false true false true true false
+
+query BBBBBBBB
+select
+NULL IS DISTINCT FROM NULL as a,
+NULL IS NOT DISTINCT FROM NULL as b,
+NULL is DISTINCT FROM 1 as c,
+NULL is NOT DISTINCT FROM 1 as d,
+1 IS DISTINCT FROM CAST(NULL as INT) as e,
+1 IS DISTINCT FROM 1 as f,
+1 IS NOT DISTINCT FROM CAST(NULL as INT) as g,
+1 IS NOT DISTINCT FROM 1 as h
+----
+false true true false true false false true
+
+# select distinct from utf8
+query BBBB
+select
+'x' IS DISTINCT FROM NULL as a,
+'x' IS DISTINCT FROM 'x' as b,
+'x' IS NOT DISTINCT FROM NULL as c,
+'x' IS NOT DISTINCT FROM 'x' as d
+----
+true false false true
+
+# select between simple expression
+query B
+SELECT 1 NOT BETWEEN 3 AND 5
+----
+true
+
+
+statement ok
+create table select_between_data(c1 bigint) as values (1), (2), (3), (4);
+
+# select between complex expression
+
+query B
+SELECT abs(c1) BETWEEN 0 AND LoG(c1 * 100 ) FROM select_between_data ORDER BY c1
+----
+true
+true
+false
+false
+
+# explain select between
+query TT
+EXPLAIN SELECT c1 BETWEEN 2 AND 3 FROM select_between_data
+----
+logical_plan
+Projection: select_between_data.c1 >= Int64(2) AND select_between_data.c1 <= Int64(3) AS select_between_data.c1 BETWEEN Int64(2) AND Int64(3)
+ TableScan: select_between_data projection=[c1]
+physical_plan
+ProjectionExec: expr=[c1@0 >= 2 AND c1@0 <= 3 as select_between_data.c1 BETWEEN Int64(2) AND Int64(3)]
+ RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+ MemoryExec: partitions=1, partition_sizes=[1]
+
+
+# TODO: query_get_indexed_field
+
+# TODO: query_nested_get_indexed_field
+
+# TODO: query_nested_get_indexed_field_on_struct
+
+# TODO: query_on_string_dictionary
+
+# TODO: sort_on_window_null_string
+
+
+# # Create time tables with different precisions but the same logical values
+
+statement ok
+create table time_data(ts bigint, value bigint) as values
+ (5000000000000, 2505),
+ (5000000000000, 2436),
+ (5500000000000, 2384),
+ (5500000000000, 1815),
+ (5900000000000, 2330),
+ (5900000000000, 2065);
+
+statement ok
+create table time64_nanos as
+select arrow_cast(ts, 'Time64(Nanosecond)') as time, value
+from time_data;
+
+statement ok
+create table time64_micros as
+select arrow_cast(ts / 1000, 'Time64(Microsecond)') as time, value
+from time_data;
+
+statement ok
+create table time32_millis as
+select arrow_cast(arrow_cast(ts / 1000 / 1000, 'Int32'), 'Time32(Millisecond)') as time, value
+from time_data;
+
+statement ok
+create table time32_s as
+select arrow_cast(arrow_cast(ts / 1000 / 1000 / 1000, 'Int32'), 'Time32(Second)') as time, value
+from time_data;
+
+# select with time filter and seconds precision
+query I rowsort
+SELECT value FROM time32_s WHERE time = '01:23:20'
+----
+2436
+2505
+
+# select with time filter and milliseconds precision
+query I rowsort
+SELECT value FROM time32_millis WHERE time = '01:23:20'
+----
+2436
+2505
+
+# select with time filter and microseconds precision
+query I rowsort
+SELECT value FROM time64_micros WHERE time = '01:23:20'
+----
+2436
+2505
+
+# select with time filter and nanoseconds precision
+query I rowsort
+SELECT value FROM time64_nanos WHERE time = '01:23:20'
+----
+2436
+2505
+
+
+# query cte with alias
+# the purpose of this test is just to make sure the query produces a valid plan
+statement ok
+create table t1(id smallint, a smallint);
+
+query III
+WITH
+ v1 AS (SELECT * FROM t1),
+ v2 AS (SELECT v1.id AS id, v1a.id AS id_a, v1b.id AS id_b
+FROM v1, v1 v1a, v1 v1b
+WHERE v1a.id = v1.id - 1
+ AND v1b.id = v1.id + 1)
+SELECT * FROM v2
+----
+
+# query cte
+query I
+WITH t AS (SELECT 1) SELECT * FROM t
+----
+1
+
+# query cte + union
+query I rowsort
+WITH t AS (SELECT 1 AS a), u AS (SELECT 2 AS a)
+SELECT * FROM t
+UNION ALL
+SELECT * FROM u
+----
+1
+2
+
+# query cte + join
+query I
+WITH t AS (SELECT 1 AS id1), u AS (SELECT 1 AS id2, 5 as x)
+SELECT x
+FROM t
+JOIN u ON (id1 = id2)
+----
+5
+
+# query cte with backward reference
+query I
+WITH t AS (SELECT 1 AS id1), u AS (SELECT * FROM t) SELECT * from u
+----
+1
+
+# nested select
+query TII
+SELECT o1, o2, c3
+FROM (
+ SELECT c1 AS o1, c2 + 1 AS o2, c3
+ FROM (
+ SELECT c1, c2, c3, c4
+ FROM aggregate_test_100
+ WHERE c1 = 'a' AND c2 >= 4
+ ORDER BY c2 ASC, c3 ASC
+ ) AS a
+) AS b
+----
+a 5 -101
+a 5 -54
+a 5 -38
+a 5 65
+a 6 -101
+a 6 -31
+a 6 36
+
+# nested select without aliases
+query TII
+SELECT o1, o2, c3
+FROM (
+ SELECT c1 AS o1, c2 + 1 AS o2, c3
+ FROM (
+ SELECT c1, c2, c3, c4
+ FROM aggregate_test_100
+ WHERE c1 = 'a' AND c2 >= 4
+ ORDER BY c2 ASC, c3 ASC
+ )
+)
+----
+a 5 -101
+a 5 -54
+a 5 -38
+a 5 65
+a 6 -101
+a 6 -31
+a 6 36
+
+# select with join unaliased subqueries
+query TIITII
+SELECT o1, o2, c3, p1, p2, p3
+FROM
+ (SELECT c1 AS o1, c2 + 1 AS o2, c3 FROM aggregate_test_100),
+ (SELECT c1 AS p1, c2 - 1 AS p2, c3 AS p3 FROM aggregate_test_100)
+LIMIT 5
+----
+c 3 1 c 1 1
+c 3 1 d 4 -40
+c 3 1 b 0 29
+c 3 1 a 0 -85
+c 3 1 b 4 -82
+
+# TODO: test_prepare_statement
+
+# TODO: parallel_query_with_filter
+
+
+# query with filter string type coercion
+
+statement ok
+create table utf8_data(str string) as values ('1'), ('2'), ('3'), ('4'), ('5');
+
+statement ok
+create table largeutf8_data as
+select arrow_cast(str, 'LargeUtf8') as large_str
+from utf8_data;
+
+query T
+select * from largeutf8_data where large_str = '1'
+----
+1
+
+query T
+select * from largeutf8_data where large_str != '1'
+----
+2
+3
+4
+5
+
+
+# query empty table
+statement ok
+CREATE TABLE empty_table;
+
+query
+SELECT * FROM empty_table
+----
+
+
+# TODO: boolean_literal
+
+# TODO: unprojected_filter
+
+
+# case sensitive in default dialect
+
+statement ok
+CREATE TABLE case_sensitive_table("INT32" int) AS VALUES (1), (2), (3), (4), (5);
+
+statement error DataFusion error: Schema error: No field named int32. Valid fields are case_sensitive_table."INT32".
+select "int32" from case_sensitive_table
+
+query I
+select "INT32" from case_sensitive_table;
+----
+1
+2
+3
+4
+5