Skip to content

Commit

Permalink
feat: lutra query runner (#4134)
Browse files Browse the repository at this point in the history
Co-authored-by: Maximilian Roos <m@maxroos.com>
  • Loading branch information
aljazerzen and max-sixty authored Feb 5, 2024
1 parent d4d9000 commit 114fb19
Show file tree
Hide file tree
Showing 19 changed files with 706 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ jobs:
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Verify minimum rust version
run: cargo minimal-versions test
- run: cargo minimal-versions test --direct
run: cargo minimal-versions test --direct

check-ok-to-merge:
# This indicates to GitHub whether everything in this workflow has passed
Expand Down
127 changes: 127 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"prqlc/prqlc-parser",
"prqlc/prqlc",
"prqlc/prqlc/examples/compile-files", # An example
"lutra/lutra",
"web/book", # The book / docs
]
resolver = "2"
Expand Down
3 changes: 3 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ includes:
zig:
taskfile: ./prqlc/bindings/prqlc-c/examples/minimal-zig
dir: ./prqlc/bindings/prqlc-c/examples/minimal-zig
lutra:
taskfile: ./lutra
dir: ./lutra

vars:
# Keep in sync with .vscode/extensions.json
Expand Down
3 changes: 3 additions & 0 deletions lutra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
example-project/**/*.parquet

.vscode/
14 changes: 14 additions & 0 deletions lutra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Lutra

Query runner for PRQL.

Status: early experimental development.

As prqlc provides conversion from PRQL source to SQL source, Lutra aims to
provide conversion from PRQL source to relational data.

For this to happen, PRQL source needs to include additional annotations (i.e.
`@lutra.sqlite`) that define data sources that contain the source data and can
execute SQL queries.

Lutra can be used as CLI (the binary in `lutra` crate) or as a library.
57 changes: 57 additions & 0 deletions lutra/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: "3"

vars:
packages: -p lutra

tasks:
run:
cmds:
- cmd: cargo run --package lutra -- execute example-project

fmt:
desc: Format prqlc source files
cmds:
- cmd: |
# remove trailing whitespace
rg '\s+$' --files-with-matches --glob '!*.{rs,snap}' . \
| xargs -I _ sh -c "echo Removing trailing whitespace from _ && sd '[\t ]+$' '' _"
- cmd: |
# rustfmt
cargo fmt {{.packages}}
- cmd: |
# no dbg
rg 'dbg!' --glob '*.rs' . --no-heading
ignore_error: true
test-fast:
desc: A fast test used for feedback during development
cmds:
- cmd: |
INSTA_FORCE_PASS=1 cargo nextest run {{.packages}} --no-fail-fast
- cmd: cargo insta review

- cmd: cargo clippy --all-targets {{.packages}}

test:
desc: The full test. Generates coverage report.
env:
# Use a different target dir so we don't poison the cache
CARGO_LLVM_COV_TARGET_DIR: ../target-cov
cmds:
- cmd: |
cargo \
llvm-cov --lcov --output-path lcov.info \
nextest \
{{.packages}}
- cmd:
cargo clippy --all-targets {{.packages}} -- -D warnings

pull-request:
desc: Most checks that run within GH actions for a pull request
cmds:
- task: fmt
- task: test
19 changes: 19 additions & 0 deletions lutra/example-project/Project.prql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

## This module is configured to pull data from an SQLite chinook.db database
@(lutra.sqlite {file="chinook.db"})
module chinook {
let artists <[{artist_id = int, name = text}]>

let genres <[{genre_id = int, name = text}]>
}

let favourite_artists = [
{artist_id = 120, last_listen = @2023-05-18},
{artist_id = 7, last_listen = @2023-05-16},
]

from favourite_artists
join input = (from chinook.artists | select {artist_id, name}) side:left (==artist_id)
derive aid = favourite_artists.artist_id * 2
select {aid, input.name, favourite_artists.last_listen}
sort {-aid}
Binary file added lutra/example-project/chinook.db
Binary file not shown.
7 changes: 7 additions & 0 deletions lutra/example-project/genres.prql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let x = [
{genre_id = 1, title = "Rock"},
{genre_id = 2, title = "Blues"},
]

x
into main
33 changes: 33 additions & 0 deletions lutra/lutra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
description = "Query runner for PRQL"
name = "lutra"

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[features]
cli = ["clap"]
default = ["cli"]

[[bin]]
name = "lutra"
path = "src/cli.rs"
required-features = ["cli"]

[target.'cfg(not(target_family="wasm"))'.dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.18", features = ["derive"], optional = true }
connector_arrow = { version = "0.1.1", features = ["src_sqlite"] }
rusqlite = { version = "0.30.0", features = ["bundled"] }
arrow = { version = "49.0", features = ["prettyprint"] }
env_logger = "0.10.2"
log = "0.4.20"
prqlc = { path = "../../prqlc/prqlc", default-features = false }
walkdir = "2.4.0"

[target.'cfg(not(target_family="wasm"))'.dev-dependencies]
insta = { version = "1.34", features = ["colors"] }
itertools = "0.12.0"
Loading

0 comments on commit 114fb19

Please sign in to comment.