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

(#4462) Postgres compatibility tests using sqllogictest #4834

Merged
merged 21 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ parquet-test-utils = { path = "../../parquet-test-utils" }
rstest = "0.16.0"
sqllogictest = "0.10.0"
test-utils = { path = "../../test-utils" }
tokio-postgres = "0.7.7"
thiserror = "1.0.37"

testcontainers = "0.14.0"
melgenek marked this conversation as resolved.
Show resolved Hide resolved
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
nix = "0.26.1"

Expand Down
5 changes: 4 additions & 1 deletion datafusion/core/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ pub fn parquet_test_data() -> String {
/// Returns either:
/// The path referred to in `udf_env` if that variable is set and refers to a directory
/// The submodule_data directory relative to CARGO_MANIFEST_PATH
fn get_data_dir(udf_env: &str, submodule_data: &str) -> Result<PathBuf, Box<dyn Error>> {
pub fn get_data_dir(
udf_env: &str,
submodule_data: &str,
) -> Result<PathBuf, Box<dyn Error>> {
// Try user defined env.
if let Ok(dir) = env::var(udf_env) {
let trimmed = dir.trim().to_string();
Expand Down
8 changes: 8 additions & 0 deletions datafusion/core/tests/sqllogictests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Run only the tests in `information_schema.slt`:
cargo test -p datafusion --test sqllogictests -- information
```

#### Running tests: Postgres compatibility mode

In this mode, `sqllogictests` runs the statements and queries in a `.slt` file, comparing outputs of postgres and datafusion.

```
cargo test -p datafusion --test sqllogictests -- --postgres
```

#### 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE aggregate_test_100_by_sql
(
c1 character varying NOT NULL,
c2 integer NOT NULL,
c3 smallint NOT NULL,
c4 smallint,
c5 integer,
c6 bigint NOT NULL,
c7 smallint NOT NULL,
c8 integer NOT NULL,
c9 bigint NOT NULL,
c10 character varying NOT NULL,
c11 double precision NOT NULL,
c12 double precision NOT NULL,
c13 character varying NOT NULL
);

COPY aggregate_test_100_by_sql
FROM '/opt/data/csv/aggregate_test_100.csv'
DELIMITER ','
CSV HEADER;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

query I
select length('ä');
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.

query IIIIIIIIII
SELECT
c9,
row_number() OVER (PARTITION BY c2 ORDER BY c9) row_num,
lead(c9) OVER (PARTITION BY c2 ORDER BY c9) lead_c9,
lag(c9) OVER (PARTITION BY c2 ORDER BY c9) lag_c9,
first_value(c9) OVER (PARTITION BY c2 ORDER BY c9) first_c9,
first_value(c9) OVER (PARTITION BY c2 ORDER BY c9 DESC) first_c9_desc,
last_value(c9) OVER (PARTITION BY c2 ORDER BY c9) last_c9,
last_value(c9) OVER (PARTITION BY c2 ORDER BY c9 DESC) last_c9_desc,
nth_value(c9, 2) OVER (PARTITION BY c2 ORDER BY c9) second_c9,
nth_value(c9, 2) OVER (PARTITION BY c2 ORDER BY c9 DESC) second_c9_desc
FROM aggregate_test_100_by_sql
ORDER BY c9;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

query I
melgenek marked this conversation as resolved.
Show resolved Hide resolved
SELECT
t1.c9 result
FROM aggregate_test_100_by_sql t1
INNER JOIN aggregate_test_100_by_sql t2
ON t1.c9 = t2.c9
ORDER BY result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.

# 100 100 7.8100000000000000 781 125 -117 --- postgres
# 100 100 7.81 781 125 -117 --- datafusion

query IIRIII
SELECT
count(*) AS count_all,
count(c3) AS count_c3,
round(avg(c3), 0) AS avg,
melgenek marked this conversation as resolved.
Show resolved Hide resolved
sum(c3) AS sum,
max(c3) AS max,
min(c3) AS min
FROM aggregate_test_100_by_sql;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

query I
SELECT * FROM (
SELECT c2
FROM aggregate_test_100_by_sql t1
EXCEPT
SELECT c2
FROM aggregate_test_100_by_sql t2
WHERE c2 IN (3, 4)
) s
ORDER BY c2
melgenek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

query I
SELECT * FROM (
SELECT c2
FROM aggregate_test_100_by_sql t1
EXCEPT ALL
SELECT c2
FROM aggregate_test_100_by_sql t2
WHERE c2 IN (3, 4)
) s
ORDER BY c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

query IIRIII
select
c2,
sum(c3) sum_c3,
round(avg(c3), 0) avg_c3,
max(c3) max_c3,
min(c3) min_c3,
count(c3) count_c3
from aggregate_test_100_by_sql
group by c2
order by c2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

query I
SELECT * FROM (
SELECT c2
FROM aggregate_test_100_by_sql t1
INTERSECT
SELECT c2
FROM aggregate_test_100_by_sql t2
WHERE c2 IN (3, 4)
) s
ORDER BY c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

query I
SELECT * FROM (
SELECT c2
FROM aggregate_test_100_by_sql t1
INTERSECT ALL
SELECT c2
FROM aggregate_test_100_by_sql t2
WHERE c2 IN (3, 4)
) s
ORDER BY c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

query RRRRR
SELECT
abs(-1.1) as abs,
round(exp(2.0), 0) as exp,
sin(3.0) as sin,
cos(4.0) as cos,
round(tan(5.0)) as tan;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

query IIIIIII
SELECT
SUM(c5) OVER(ORDER BY c13 ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) as summation2,
SUM(c2) OVER(PARTITION BY c5 ORDER BY c13 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as summation10,
SUM(c2) OVER(PARTITION BY c1 ORDER BY c13 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as summation14,
SUM(c5) OVER(ORDER BY c5 ROWS BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING) as summation5,
SUM(c5) OVER(ORDER BY c5 ROWS BETWEEN UNBOUNDED PRECEDING AND 2 FOLLOWING) as summation6,
SUM(c2) OVER(PARTITION BY c5, c7, c9 ORDER BY c13, c5 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as summation20,
SUM(c2) OVER(PARTITION BY c5 ORDER BY c13, c5 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as summation21
FROM aggregate_test_100_by_sql
ORDER BY c9;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

query IIIII
SELECT
SUM(c2) OVER(ORDER BY c5 ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as summation1,
SUM(c2) OVER(ORDER BY c5 ROWS BETWEEN 2 FOLLOWING AND 3 FOLLOWING) as summation2,
SUM(c2) OVER(ORDER BY c5 ROWS BETWEEN 2 FOLLOWING AND UNBOUNDED FOLLOWING) as summation3,
SUM(c2) OVER(ORDER BY c5 RANGE BETWEEN 2 FOLLOWING AND UNBOUNDED FOLLOWING) as summation4,
SUM(c2) OVER(ORDER BY c5 RANGE BETWEEN 1 PRECEDING AND 1 PRECEDING) as summation5
FROM aggregate_test_100_by_sql
ORDER BY c9;
Loading