Skip to content

Commit 07d83ca

Browse files
eitsupipre-commit-ci[bot]max-sixty
authored
fix(prqlc): allow prqlc compile | duckdb (PRQL#2594)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <[email protected]>
1 parent ac33534 commit 07d83ca

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

prql-compiler/prqlc/README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
## Installation
44

5-
`prqlc` can be installed with `cargo`:
5+
`prqlc` is a single, dependency-free binary that compiles PRQL into SQL.
6+
precompiled binaries are available for Linux, macOS, and Windows on the
7+
[PRQL release page](https://github.com/PRQL/prql/releases).
8+
9+
`prqlc` can be installed via `cargo`:
610

711
```sh
12+
# From crates.io
813
cargo install prqlc
914
```
1015

11-
...or built from source:
12-
1316
```sh
17+
# From a local PRQL repository
1418
cargo install --path prql-compiler/prqlc
1519
```
1620

@@ -22,6 +26,10 @@ brew install prql/prql/prql-compiler
2226

2327
## Usage
2428

29+
### prqlc compile
30+
31+
This command is working as a filter to compile PRQL string into SQL string.
32+
2533
```sh
2634
$ echo "from employees | filter has_dog | select salary" | prqlc compile
2735

@@ -32,3 +40,46 @@ FROM
3240
WHERE
3341
has_dog
3442
```
43+
44+
PRQL query can be executed with CLI tools working with SQL, such as
45+
[DuckDB CLI](https://duckdb.org/docs/api/cli.html).
46+
47+
```sh
48+
$ curl -sL https://raw.githubusercontent.com/PRQL/prql/0.8.1/prql-compiler/tests/integration/data/chinook/albums.csv -o albums.csv
49+
$ echo "from `albums.csv` | take 3" | prqlc compile | duckdb
50+
┌──────────┬───────────────────────────────────────┬───────────┐
51+
│ album_id │ title │ artist_id │
52+
│ int64 │ varchar │ int64 │
53+
├──────────┼───────────────────────────────────────┼───────────┤
54+
│ 1 │ For Those About To Rock We Salute You │ 1 │
55+
│ 2 │ Balls to the Wall │ 2 │
56+
│ 3 │ Restless and Wild │ 2 │
57+
└──────────┴───────────────────────────────────────┴───────────┘
58+
```
59+
60+
Executing this command without any argument will start interactive mode,
61+
allowing you to write PRQL query interactively. In this mode, after you write
62+
PRQL and press `Ctrl-D` (Linux, macOS) or `Ctrl-Z` (Windows) to display the
63+
compiled SQL.
64+
65+
```sh
66+
$ prqlc compile
67+
```
68+
69+
As with using it as a filter, you can pass the SQL string output to the DuckDB
70+
CLI, etc.
71+
72+
```sh
73+
$ prqlc compile | duckdb
74+
from `albums.csv`
75+
take 3
76+
77+
┌──────────┬───────────────────────────────────────┬───────────┐
78+
│ album_id │ title │ artist_id │
79+
│ int64 │ varchar │ int64 │
80+
├──────────┼───────────────────────────────────────┼───────────┤
81+
│ 1 │ For Those About To Rock We Salute You │ 1 │
82+
│ 2 │ Balls to the Wall │ 2 │
83+
│ 3 │ Restless and Wild │ 2 │
84+
└──────────┴───────────────────────────────────────┴───────────┘
85+
```

prql-compiler/prqlc/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl Command {
292292
// it's confusing whether it's waiting for input or not. This
293293
// offers the prompt.
294294
if input.is_stdin() && atty::is(atty::Stream::Stdin) {
295-
println!("Enter PRQL, then ctrl-d:\n");
295+
println!("# Enter PRQL, then press ctrl-d or ctrl-z (windows) to compile:\n");
296296
}
297297

298298
let file_tree = input.read_to_tree()?;

web/book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
- [Integrations](./integrations/README.md)
6969

70+
- [CLI](./integrations/cli.md)
7071
- [Jupyter](./integrations/jupyter.md)
7172
- [DuckDB](./integrations/duckdb.md)
7273
- [Prefect](./integrations/prefect.md)

web/book/src/integrations/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{#include ../../../../prql-compiler/prqlc/README.md}}

0 commit comments

Comments
 (0)