Skip to content

Commit aafec07

Browse files
Omega359alamb
andauthored
Add sqlite test files, progress bar, and automatic postgres container management into sqllogictests (#13936)
* Fix md5 return_type to only return Utf8 as per current code impl. * Add support for sqlite test files to sqllogictest * Force version 0.24.0 of sqllogictest dependency until issue with labels is fixed. * Removed workaround for bug that was fixed. * Git submodule update ... err update, link to sqlite tests. * Git submodule update * Readd submodule --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 9eca7d1 commit aafec07

File tree

8 files changed

+611
-101
lines changed

8 files changed

+611
-101
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
[submodule "testing"]
55
path = testing
66
url = https://github.com/apache/arrow-testing
7+
[submodule "datafusion-testing"]
8+
path = datafusion-testing
9+
url = https://github.com/apache/datafusion-testing.git
10+
branch = main

datafusion-testing

Submodule datafusion-testing added at e2e320c

datafusion/sqllogictest/Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ datafusion-common = { workspace = true, default-features = true }
4545
datafusion-common-runtime = { workspace = true, default-features = true }
4646
futures = { workspace = true }
4747
half = { workspace = true, default-features = true }
48+
indicatif = "0.17"
4849
itertools = { workspace = true }
4950
log = { workspace = true }
5051
object_store = { workspace = true }
52+
once_cell = { version = "1.20", optional = true }
5153
postgres-protocol = { version = "0.6.7", optional = true }
5254
postgres-types = { version = "0.2.8", features = ["derive", "with-chrono-0_4"], optional = true }
5355
rust_decimal = { version = "1.36.0", features = ["tokio-pg"] }
@@ -56,6 +58,8 @@ rust_decimal = { version = "1.36.0", features = ["tokio-pg"] }
5658
sqllogictest = "=0.24.0"
5759
sqlparser = { workspace = true }
5860
tempfile = { workspace = true }
61+
testcontainers = { version = "0.23", features = ["default"], optional = true }
62+
testcontainers-modules = { version = "0.11", features = ["postgres"], optional = true }
5963
thiserror = "2.0.0"
6064
tokio = { workspace = true }
6165
tokio-postgres = { version = "0.7.12", optional = true }
@@ -65,9 +69,12 @@ avro = ["datafusion/avro"]
6569
postgres = [
6670
"bytes",
6771
"chrono",
68-
"tokio-postgres",
72+
"once_cell",
6973
"postgres-types",
7074
"postgres-protocol",
75+
"testcontainers",
76+
"testcontainers-modules",
77+
"tokio-postgres",
7178
]
7279

7380
[dev-dependencies]

datafusion/sqllogictest/README.md

+42-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ This crate is a submodule of DataFusion that contains an implementation of [sqll
2828
## Overview
2929

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

3334
## Testing setup
3435

3536
1. `rustup update stable` DataFusion uses the latest stable release of rust
3637
2. `git submodule init`
37-
3. `git submodule update`
38+
3. `git submodule update --init --remote --recursive`
3839

3940
## Running tests: TLDR Examples
4041

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

163-
In order to run the sqllogictests running against a previously running Postgres instance, do:
164+
In order to have the sqllogictest run against an existing running Postgres instance, do:
164165

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

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

189+
If you do not want to create a new postgres database and you have docker
190+
installed you can skip providing a PG_URI env variable and the sqllogictest
191+
runner will automatically create a temporary postgres docker container.
192+
For example:
193+
194+
```shell
195+
PG_COMPAT=true cargo test --features=postgres --test sqllogictests
196+
```
197+
188198
## Running Tests: `tpch`
189199

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

218+
## Running Tests: `sqlite`
219+
220+
Test files in `data/sqlite` directory of the datafusion-testing crate were
221+
sourced from the [sqlite test suite](https://www.sqlite.org/sqllogictest/dir?ci=tip) and have been cleansed and updated to
222+
run within DataFusion's sqllogictest runner.
223+
224+
To run the sqlite tests you need to increase the rust stack size and add
225+
`INCLUDE_SQLITE=true` to run the sqlite tests:
226+
227+
```shell
228+
export RUST_MIN_STACK=30485760;
229+
INCLUDE_SQLITE=true cargo test --test sqllogictests
230+
```
231+
232+
Note that there are well over 5 million queries in these tests and running the
233+
sqlite tests will take a long time. You may wish to run them in release-nonlto mode:
234+
235+
```shell
236+
INCLUDE_SQLITE=true cargo test --profile release-nonlto --test sqllogictests
237+
```
238+
239+
The sqlite tests can also be run with the postgres runner to verify compatibility:
240+
241+
```shell
242+
export RUST_MIN_STACK=30485760;
243+
PG_COMPAT=true INCLUDE_SQLITE=true cargo test --features=postgres --test sqllogictests
244+
```
245+
208246
## Updating tests: Completion Mode
209247

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

0 commit comments

Comments
 (0)