# parquet-cli
A Parquet CLI for AI agents.
Parquet is a format, and **how the data is laid out has degrees of freedom**.
DuckDB made its own trade-offs; there are empty positions between them.
`pqt` is a bench for that space: it measures a file, says what could be
better, and lets you write it another way to see what it weighs.
Two directions have to be looked after, and they pull against each other:
**compact** (a small file) and **scanning** (a cheap read). `pqt` does not give
you one "best" — it makes the trade-off visible.
Every command is non-interactive, and every command has a JSON form, so the
caller is usually a script rather than a person.
> The tool's own messages are in Chinese for now; the numbers are the point.
## Install
```sh
cargo install parquet-cli
```
The binary is called `pqt`.
## Use
```sh
pqt info events.parquet # size, rows, row groups, who wrote it
pqt info events.parquet --lookup-cost # what one lookup reads
pqt info events.parquet --row-groups # the row groups, with their sizes
pqt schema events.parquet # the columns and their types
pqt columns events.parquet # per-column statistics
pqt columns events.parquet --scan # ... and the exact distinct counts
pqt advise events.parquet # what could be better about this file
pqt compare shards/ # where several files disagree with each other
pqt bench events.parquet --with "zstd:19" # what it would weigh written that way
pqt sort events.parquet --by id --out sorted.parquet # write it again, in order
pqt to events.parquet --out events.csv --format csv
pqt head events.parquet -n 5 # the first rows
pqt cat a.parquet b.parquet # the rows of several files
pqt validate events.parquet # is the file sound?
```
### The JSON form
Every command takes `--json`, and then prints one object on stdout:
```sh
pqt --json info events.parquet
```
```json
{
"file": "events.parquet",
"size_bytes": 48852480,
"rows": 2439233,
"row_groups": 18,
"columns": 51,
"bytes_per_row": 20.03,
"compressions": ["ZSTD"],
"encodings": ["DELTA_BINARY_PACKED", "PLAIN", "RLE"]
}
```
`pqt head --format jsonl` keeps the types of the values (numbers stay
numbers), which is what a program wants; `--format csv` and `--format table`
are there for a person.
### What one lookup reads
A reader pays the footer before it can read anything, and then it reads one
row group. `pqt info --lookup-cost` says what that costs.
```sh
pqt info events.parquet --lookup-cost
```
```
file /tmp/cols.parquet
size_bytes 1021553
rows 100000
row_groups 10
columns 4
footer_bytes 25830
metadata_bytes 4716
what one lookup reads:
the footer 25830 bytes (every reader pays this first)
one row group 99572 bytes (average), 102166 bytes (largest)
⇒ typical 125402 bytes, worst 127996 bytes
rows per group 10000 (average), 7840 to 10240 (not even)
```
`--row-groups` lists the row groups with their sizes, and `pqt columns` reports
the min and max of every column in every row group — the numbers a reader uses
to skip a group it does not need.
### Writing it again, and saying what it cost
A compression experiment is one question: *what would this file weigh if it
were written this way?* `pqt bench` answers it.
```sh
pqt bench events.parquet --with "zstd:19" --with "row_group_size=1000"
```
```
the settings you asked for (compression=zstd, compression_level=19, row_group_size=1000, …)
rewritten 792550 bytes
difference -229003 bytes (-22.4%)
```
### The settings, in DuckDB's words
The options are named after DuckDB's `COPY ... TO` options, so that somebody
who knows DuckDB already knows them:
```sh
pqt bench events.parquet --with "compression=zstd" --with "compression_level=19"
pqt bench events.parquet --with "row_group_size=1000"
pqt bench events.parquet --with "dictionary=off"
pqt bench events.parquet --with "write_bloom_filter=on"
```
The short form works too (`zstd:19`, `row-group:1000`, `dictionary:off`).
`--sweep` tries one setting at a time, starting from the file's own, and
reports what each weighs. The file being read is never touched.
The options it knows:
| `compression` / `codec` / `compression_level` | the codec (uncompressed · snappy · gzip · lzo · brotli · lz4 · zstd) and its level |
| `row_group_size` / `row_group_size_bytes` | how many rows / bytes in a row group |
| `data_page_size_limit` / `dictionary_size_limit` | how big a data page or a dictionary page may get |
| `write_bloom_filter` / `bloom_filter_false_positive_ratio` / `bloom_filter_max_ndv` | the bloom filter a point lookup uses |
| `write_page_index` | whether the page index is written (the offset index and the per-page statistics) |
| `parquet_version` | v1 or v2 (the data page version) |
| `kv_metadata` | key-value metadata |
| `statistics_truncate_length` / `column_index_truncate_length` | how long the statistics may get (the metadata gets smaller) |
| `write_row_group_number_distinct_values` | the distinct count per row group (pruning uses it) |
| `dictionary` / `dictionary.<column>` | the dictionary, for every column or for one |
| `encoding` / `encoding.<column>` | the encoding (plain · delta · delta-length-bytes) |
| `data_page_row_count_limit` | rows per data page |
| `created_by` | who wrote it |
Two of them are ours. `dictionary=off` turns the dictionary off (or on for one
column: `dictionary.id=off`). And
**`dictionary_compression_ratio_threshold`** says how much of a column's rows
may have a different value before the dictionary stops paying for itself — a
column above it is written without one. DuckDB decides this on its own (and
deprecated the option that used to say so); here you can say it.
That one option is worth a lot. On a file of 100,000 rows with four columns,
written by DuckDB with Snappy:
| DuckDB's file | 1,021,553 |
| ours, with the file's own settings | 1,322,595 (+29.5%) |
| **ours, with `dictionary_compression_ratio_threshold=0.5`** | **972,577 (−4.8%)** |
A misspelled option is an error (`unknown option: compresion`), and an option
we do not do yet says so (`field_ids is a DuckDB option we do not do yet`) —
nothing is quietly ignored.
### Advising on a file
`pqt advise` looks at the data and says what could be better. It reads the
footer only, so it is cheap:
```sh
pqt advise events.parquet
```
```
column type bytes share distinct
id int64 401360 39.3% 100000
country utf8 3437 0.3% 7
score decimal128(21,1) 525980 51.5% 100000
warning type-too-wide score: 精度 21 > 18 ⇒ 一个值 16 字节;用得着那么多位吗
warning column-dominates score: 这一列占了全文件的 51.5%(525980 字节)
```
The rules it knows: a type that is wider than the values need, a string column
whose values repeat but that was written without a dictionary, a column that
takes most of the file, a column that is mostly empty, a column whose values
are all the same, a column whose row groups overlap (the rows are not in
order), row groups that are too small, and a footer that takes a big share of
the file.
`--scan` reads the data as well, so the advice can use the distinct values.
`--contrast N` goes one step further: it rewrites the `N` largest columns with
a constant in them, so the difference in size says whether a column is
expensive because of its values or because of its shape. That costs a rewrite
of the file, so it is opt-in.
### Comparing several files
A directory of shards drifts: one day a column is added, another day a column
grows. `pqt compare` says where the files disagree, before a query silently
drops a column.
```sh
pqt compare shards/
```
```
file rows size_bytes row_groups columns
week=2026-06-01/events.parquet 50000 202291 1 2
week=2026-06-15/events.parquet 200000 1871596 2 4
column week=2026-06-01/events.parquet week=2026-06-15/events.parquet
id 200883 801181
score 0 1054732
error column-missing week=2026-06-01/events.parquet: 少了列「score」,别的文件有
warning size-jump week=2026-06-15/events.parquet: 列「id」的字节从 200883 涨到 801181(4.0 倍)
```
The shape most of the files have is the yardstick, so one shard that drifted
does not define what the others look like. It reports the columns that are
missing or extra, the columns whose type changed, and the columns whose bytes
changed a lot.
### Three things worth doing
**Sort it.** When the rows are in the order of the key you query by, the min and
max of every row group say something, and a reader can skip the groups it does
not need. It is worth bytes too: the same values shuffled and then written again
came out 26.8% bigger.
```sh
pqt sort file.parquet --by id --out sorted.parquet
```
`pqt advise` says when a file is not in order: `not-sorted` means the row
groups' ranges overlap, so a predicate cannot skip any of them.
**Keep only the columns you read.**
```sh
pqt to file.parquet --out slim.parquet --format parquet --columns "id,country"
```
On the file above, four columns down to two saved 67.2%.
**Watch the metadata.** The footer is what every reader pays before it can read
anything, and it grows with the number of row groups. `write_bloom_filter`,
`statistics_truncate_length` and `write_page_index` each cost something — measure
before turning them on.
### Checking a file
`pqt validate` compares the footer with the file's own bytes: the row
counts have to add up, the column chunks have to fit inside the file, and they
must not overlap. It exits with 1 when something is wrong, so it can be used in
a pipeline.
### Scripts
Everything the command line can do is in the scripts too, in the same
vocabulary, and a script can put them together however it likes. The scripts
are Luau.
```sh
pqt script experiment.luau file.parquet
```
```lua
local cost = pqt.lookup_cost("file.parquet")
print("a lookup reads " .. cost.lookup_reads_typical)
local bench = pqt.bench("file.parquet", { compression = "zstd", compression_level = 19 })
print("zstd:19 rewrites to " .. bench.runs[1].bytes)
```
The API is `pqt.info` `pqt.schema` `pqt.columns` `pqt.advise` `pqt.compare`
`pqt.bench` `pqt.sort` `pqt.project` `pqt.list` `pqt.lookup_cost`
`pqt.prune` `pqt.rows` `pqt.write` and `pqt.options` (the settings we know).
A plan is a table; the translation to the writer happens in Rust.
`pqt.prune` is the one that makes this a lab rather than a reader: it answers
**what the file's own statistics say a reader could skip** — a different number
from what any engine actually read, and the gap between the two is where the
problems are.
```lua
local stats = pqt.prune("events.parquet", { column = "id", op = ">", value = 90000 })
print(stats.groups_read, "of", stats.groups_total, "row groups have to be read")
```
`pqt.rows` hands out batches (not rows), and `pqt.write` writes a table of
records out as Parquet. The scripts also have `io`, `json`, `csv` and the file
parts of `os` — Luau comes with the rest of the standard library.
### The tests are written in Lua
[`test/`](test) is the corpus: one experiment per file, each asserting what it
found.
```sh
cargo run --release -- test test/
```
```
6 passed, 0 failed
OK 写了一份 28557 字节的文件,每列的份额都算得出来
OK 排过序的文件,谓词 id>40000 只要读 2/10 个行组
OK 同样的行,排过序的能跳,打乱的跳不掉 —— advise 也看得出来
OK CSV → Lua 过滤 → parquet:5000 行里留下 2500
OK 两个片差在哪,compare 说得出来
OK 一次查找读 23540 字节;zstd:19 比默认小 145516 字节
```
[`script/`](script) has seven you can run as they are:
[`sort-and-prune.luau`](script/sort-and-prune.luau) (sorting, and what it does
for pruning) · [`where-do-the-bytes-go.luau`](script/where-do-the-bytes-go.luau)
(which column costs what) · [`tune-it.luau`](script/tune-it.luau) (write it another
way and see what it weighs) ·
[`compact-vs-scannable.luau`](script/compact-vs-scannable.luau) (the trade-off
between a small file and a cheap lookup) ·
[`write-only-what-you-read.luau`](script/write-only-what-you-read.luau) (keep only
the columns you read) ·
[`metadata-cost.luau`](script/metadata-cost.luau) (what the metadata costs) ·
[`shard-check.luau`](script/shard-check.luau) (where a set of shards disagrees).
[`skill/SKILL.md`](skill/SKILL.md) is the skill: it is how an agent is meant to
drive this.
## Where it comes from
The questions it answers are the ones that came up while building Sumimi's cold
layer (Parquet archives of a web analytics database): how much smaller is a
Parquet copy than the DuckDB file, which columns cost the most bytes, and
whether the row groups are the size they should be.
## Release
The version lives in `Cargo.toml`. To cut a release:
```sh
# bump the version, then:
git tag v0.1.8
git push origin v0.1.8
```
GitHub Actions then publishes the crate to crates.io, builds the binaries for
macOS, Linux and Windows, and puts them in a GitHub release.
## License
Apache-2.0. See [LICENSE](LICENSE).