Recompress Parquet with Python
Run this Python script locally with Apache Arrow. The script reads your local file rather than sending it to this website.
Before you start
- Install Python 3 and create an isolated environment using the commands below.
- Work in a folder containing input.parquet. Change the filenames to your own paths and use a new output name to avoid overwriting a file.
- Save the Python code as task.py. On macOS/Linux run .venv/bin/python task.py; on Windows PowerShell run .venv\Scripts\python.exe task.py.
python3 -m venv .venv
.venv/bin/python -m pip install pyarrowpy -m venv .venv
.venv\Scripts\python.exe -m pip install pyarrowimport pyarrow.parquet as pq
source = pq.ParquetFile("input.parquet")
with pq.ParquetWriter("snappy.parquet", source.schema_arrow, compression="snappy") as output:
for batch in source.iter_batches(batch_size=65536):
output.write_batch(batch)
print("Rows:", pq.ParquetFile("snappy.parquet").metadata.num_rows)Limits and output
- Writes Snappy compression inside a normal .parquet file, not a .gz wrapper. The output is not guaranteed to be smaller.
- Rewriting may change row groups, encoding and file metadata. Keep the original and verify schema and values before replacing it.
Documentation: Apache Arrow Parquet documentation