Skip to content

Commit

Permalink
Add support for sqlite test files to sqllogictest
Browse files Browse the repository at this point in the history
  • Loading branch information
Omega359 committed Dec 28, 2024
1 parent f3929a6 commit 2b1af71
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 99 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
[submodule "testing"]
path = testing
url = https://github.com/apache/arrow-testing
[submodule "datafusion-testing"]
path = datafusion-testing
url = https://github.com/apache/datafusion-testing.git
branch = main
1 change: 1 addition & 0 deletions datafusion-testing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2e320c9477a6d8ab09662eae255887733c0e304
9 changes: 8 additions & 1 deletion datafusion/sqllogictest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ datafusion-common = { workspace = true, default-features = true }
datafusion-common-runtime = { workspace = true, default-features = true }
futures = { workspace = true }
half = { workspace = true, default-features = true }
indicatif = "0.17"
itertools = { workspace = true }
log = { workspace = true }
object_store = { workspace = true }
once_cell = { version = "1.20", optional = true }
postgres-protocol = { version = "0.6.7", optional = true }
postgres-types = { version = "0.2.8", features = ["derive", "with-chrono-0_4"], optional = true }
rust_decimal = { version = "1.36.0", features = ["tokio-pg"] }
sqllogictest = "0.25.0"
sqlparser = { workspace = true }
tempfile = { workspace = true }
testcontainers = { version = "0.23", features = ["default"], optional = true }
testcontainers-modules = { version = "0.11", features = ["postgres"], optional = true }
thiserror = "2.0.0"
tokio = { workspace = true }
tokio-postgres = { version = "0.7.12", optional = true }
Expand All @@ -63,9 +67,12 @@ avro = ["datafusion/avro"]
postgres = [
"bytes",
"chrono",
"tokio-postgres",
"once_cell",
"postgres-types",
"postgres-protocol",
"testcontainers",
"testcontainers-modules",
"tokio-postgres",
]

[dev-dependencies]
Expand Down
44 changes: 41 additions & 3 deletions datafusion/sqllogictest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ This crate is a submodule of DataFusion that contains an implementation of [sqll
## Overview

This crate uses [sqllogictest-rs](https://github.com/risinglightdb/sqllogictest-rs) to parse and run `.slt` files in the
[`test_files`](test_files) directory of this crate.
[`test_files`](test_files) directory of this crate or the [`data/sqlite`](sqlite)
directory of the datafusion-testing crate.

## Testing setup

Expand Down Expand Up @@ -160,7 +161,7 @@ cargo test --test sqllogictests -- information
Test files that start with prefix `pg_compat_` verify compatibility
with Postgres by running the same script files both with DataFusion and with Postgres

In order to run the sqllogictests running against a previously running Postgres instance, do:
In order to have the sqllogictest run against an existing running Postgres instance, do:

```shell
PG_COMPAT=true PG_URI="postgresql://[email protected]/postgres" cargo test --features=postgres --test sqllogictests
Expand All @@ -172,7 +173,7 @@ The environment variables:
2. `PG_URI` contains a `libpq` style connection string, whose format is described in
[the docs](https://docs.rs/tokio-postgres/latest/tokio_postgres/config/struct.Config.html#url)

One way to create a suitable a posgres container in docker is to use
One way to create a suitable a postgres container in docker is to use
the [Official Image](https://hub.docker.com/_/postgres) with a command
such as the following. Note the collation **must** be set to `C` otherwise
`ORDER BY` will not match DataFusion and the tests will diff.
Expand All @@ -185,6 +186,15 @@ docker run \
postgres
```

If you do not want to create a new postgres database and you have docker
installed you can skip providing a PG_URI env variable and the sqllogictest
runner will automatically create a temporary postgres docker container.
For example:

```shell
PG_COMPAT=true cargo test --features=postgres --test sqllogictests
```

## Running Tests: `tpch`

Test files in `tpch` directory runs against the `TPCH` data set (SF =
Expand All @@ -205,6 +215,34 @@ Then you need to add `INCLUDE_TPCH=true` to run tpch tests:
INCLUDE_TPCH=true cargo test --test sqllogictests
```

## Running Tests: `sqlite`

Test files in `data/sqlite` directory of the datafusion-testing crate were
sourced from the sqlite test suite and have been cleansed and updated to
run within DataFusion's sqllogictest runner.

To run the sqlite tests you need to increase the rust stack size and add
`INCLUDE_SQLITE=true` to run the sqlite tests:

```shell
export RUST_MIN_STACK=30485760;
INCLUDE_SQLITE=true cargo test --test sqllogictests
```

Note that there are well over 5 million queries in these tests and running the
sqlite tests will take a long time. You may wish to run them in release-nonlto mode:

```shell
INCLUDE_SQLITE=true cargo test --profile release-nonlto --test sqllogictests
```

The sqlite tests can also be run with the postgres runner to verify compatibility:

```shell
export RUST_MIN_STACK=30485760;
PG_COMPAT=true INCLUDE_SQLITE=true cargo test --features=postgres --test sqllogictests
```

## Updating tests: Completion Mode

In test script completion mode, `sqllogictests` reads a prototype script and runs the statements and queries against the
Expand Down
Loading

0 comments on commit 2b1af71

Please sign in to comment.