Skip to content

Commit

Permalink
test: Port tests in references.rs to sqllogictest (#8877)
Browse files Browse the repository at this point in the history
* Migrate references unit tests to sqllogictest

* Remove unused import
  • Loading branch information
simicd authored Jan 17, 2024
1 parent 3f219bc commit ffaa679
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 196 deletions.
56 changes: 0 additions & 56 deletions datafusion/core/tests/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,66 +73,10 @@ pub mod explain_analyze;
pub mod expr;
pub mod joins;
pub mod partitioned_csv;
pub mod references;
pub mod repartition;
pub mod select;
mod sql_api;

fn create_join_context(
column_left: &str,
column_right: &str,
repartition_joins: bool,
) -> Result<SessionContext> {
let ctx = SessionContext::new_with_config(
SessionConfig::new()
.with_repartition_joins(repartition_joins)
.with_target_partitions(2)
.with_batch_size(4096),
);

let t1_schema = Arc::new(Schema::new(vec![
Field::new(column_left, DataType::UInt32, true),
Field::new("t1_name", DataType::Utf8, true),
Field::new("t1_int", DataType::UInt32, true),
]));
let t1_data = RecordBatch::try_new(
t1_schema,
vec![
Arc::new(UInt32Array::from(vec![11, 22, 33, 44])),
Arc::new(StringArray::from(vec![
Some("a"),
Some("b"),
Some("c"),
Some("d"),
])),
Arc::new(UInt32Array::from(vec![1, 2, 3, 4])),
],
)?;
ctx.register_batch("t1", t1_data)?;

let t2_schema = Arc::new(Schema::new(vec![
Field::new(column_right, DataType::UInt32, true),
Field::new("t2_name", DataType::Utf8, true),
Field::new("t2_int", DataType::UInt32, true),
]));
let t2_data = RecordBatch::try_new(
t2_schema,
vec![
Arc::new(UInt32Array::from(vec![11, 22, 44, 55])),
Arc::new(StringArray::from(vec![
Some("z"),
Some("y"),
Some("x"),
Some("w"),
])),
Arc::new(UInt32Array::from(vec![3, 1, 3, 3])),
],
)?;
ctx.register_batch("t2", t2_data)?;

Ok(ctx)
}

fn create_left_semi_anti_join_context_with_null_ids(
column_left: &str,
column_right: &str,
Expand Down
140 changes: 0 additions & 140 deletions datafusion/core/tests/sql/references.rs

This file was deleted.

134 changes: 134 additions & 0 deletions datafusion/sqllogictest/test_files/references.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# 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.

##########
## References Tests
##########


# Qualified table references
# Query tables with catalog prefix
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 aggregate_test_100;
----
100

query I
SELECT COUNT(*) FROM public.aggregate_test_100;
----
100

query I
SELECT COUNT(*) FROM datafusion.public.aggregate_test_100;
----
100


# Qualified table references and fields
# Query fields with prefixes
statement ok
CREATE TABLE test("f.c1" TEXT, "test.c2" INT, "...." INT) AS VALUES
('foofoo', 1, 10),
('foobar', 2, 20),
('foobaz', 3, 30);

query error DataFusion error: Schema error: No field named f1\.c1\. Valid fields are test\."f\.c1", test\."test\.c2", test\."\.\.\.\."\.
SELECT f1.c1 FROM test;

query T
SELECT "f.c1" FROM test
----
foofoo
foobar
foobaz

query T
SELECT test."f.c1" FROM test
----
foofoo
foobar
foobaz

query II
SELECT "test.c2" AS expr1, test."test.c2" AS expr2 FROM test
----
1 1
2 2
3 3

query II
SELECT "....", "...." AS c3 FROM test ORDER BY "...."
----
10 10
20 20
30 30

query TT
EXPLAIN (SELECT "....", "...." AS c3 FROM test ORDER BY "....");
----
logical_plan
Sort: test..... ASC NULLS LAST
--Projection: test....., test..... AS c3
----TableScan: test projection=[....]
physical_plan
SortExec: expr=[....@0 ASC NULLS LAST]
--ProjectionExec: expr=[....@0 as ...., ....@0 as c3]
----MemoryExec: partitions=1, partition_sizes=[1]


# Partial qualified name
statement ok
CREATE TABLE t1(t1_id INT, t1_name TEXT, t1_int INT) AS VALUES
(11, 'a', 1),
(22, 'b', 2),
(33, 'c', 3),
(44, 'd', 3);

statement ok
CREATE TABLE t2(t2_id INT, t2_name TEXT, t2_int INT) AS VALUES
(11, 'z', 3),
(22, 'y', 1),
(44, 'x', 3),
(55, 'w', 3);

query IT
SELECT t1.t1_id, t1_name FROM public.t1;
----
11 a
22 b
33 c
44 d

0 comments on commit ffaa679

Please sign in to comment.