pq-glue
Concatenate Parquet files without decoding them.
pq-glue copies the row groups of several Parquet files into one new file. Each column chunk is copied as bytes: it is not decompressed, decoded or re-encoded. The time taken depends on the number of bytes copied, not on the number of columns or how deeply they are nested.
Installation
Python (3.10 or later):
Rust:
Usage
Python:
=
Rust:
use ;
let inputs = ;
let rows = concat?;
concat returns the number of rows written.
Many concatenations at once, each a concat with the same output, run in parallel with
the GIL released (in Rust, pq_glue::concat_many, feature parallel):
=
For many small concatenations, whose time goes on opening files and writing footers,
one call is quicker than a concat per job.
The output file
The output file contains:
- Row groups: every input's row groups, in input order. Each column chunk is unchanged: the same pages, dictionary page, encodings, compression and statistics.
- Schema and metadata: the first input's Parquet schema and key-value metadata. The
key-value metadata includes
ARROW:schema, which pyarrow and Polars use to restore Arrow types such aslarge_stringand field nullability. - Column orders: the inputs' column orders (see Float statistics).
- Indexes and filters: the inputs' page indexes (column and offset indexes) and bloom filters, where the inputs have them.
- Writer and sorting: the inputs'
created_by, format version and row groups' sorting columns, where all the inputs have the same.created_bynames the writer that encoded the column chunks, which readers use to work around known writers' bugs. A file written as separate row groups and glued declares what the file written whole declares. Where the inputs differ, the output has parquet-rs'screated_byand format version, and its row groups declare no sorting columns: parquet-rs gives every row group the same sorting columns, and declaring one row group's for another could be false.
Requirements on the inputs
All inputs must have the same Parquet schema, key-value metadata and column orders.
concat writes nothing and returns an error when:
- the inputs differ in any of those;
- there are no inputs;
- the output path is one of the input paths;
- an input is not a Parquet file or cannot be opened.
In Python these raise ValueError, except a file that cannot be opened, which raises
OSError. In Rust they are variants of pq_glue::Error.
If the copy fails after the output file has been created, the output file is deleted.
Float statistics
A Parquet file declares, for each column, the sort order used for that column's min/max statistics (its column order).
parquet-rs, which pq-glue uses to write the file, declares IEEE 754 total order for every float column. A plain copy would therefore pair statistics computed under one order with a declaration of another. Files written by pyarrow, for example, use the type-defined order. Arrow C++ (pyarrow) then ignores the min/max of those float columns, because IEEE 754 total order also requires NaN counts that the copied statistics do not have.
pq-glue writes the inputs' column orders instead. After parquet-rs writes the footer,
pq-glue rewrites the footer's column_orders list in place:
- Same length: the two encodings are both 3 bytes, so no offsets or lengths change.
- Checked: every entry must be one of the two known encodings, or the output is rejected.
- Verified: the footer is read back and compared with the inputs' column orders.
- Old files: inputs written without column orders (before parquet-format 2.4) get the type-defined order, which is what such files meant.
Performance
Concatenating 66 files (555 MB, 9.4 million rows, 93 nested leaf columns) took 1.1 to 1.5 s with pq-glue, against 61 s with Polars and 56 s with pyarrow. See the benchmarks page for all the figures, and bench/ to reproduce them.
Development
See DEVELOPMENT.md. In short:
License
MIT