Sub topic 5
The footer: how readers find everything
This chapter assumes you know how a Parquet file divides into row groups, column chunks, and pages, and that you can run basic PyArrow code. Here you will see why Parquet puts its metadata at the end of the file, how a reader uses it, and what mistakes this design leads to.
Why the metadata sits at the end
A writer streams row groups to disk as it receives data. It does not know the final row count, the byte offsets of later chunks, or the min and max values until it has written everything. So it writes the metadata last. This block is the footer.
The end of a Parquet file looks like this:
- The
PAR1magic bytes at the start of the file. - Row groups, each holding column chunks made of pages.
- The footer, which is the file metadata serialized in Thrift's compact format.
- A 4-byte little-endian integer holding the footer length.
- The
PAR1magic bytes again.
How a reader opens a file
A reader does not scan from the beginning. It follows a fixed sequence.
Many readers fetch a larger tail, often 64 KB, in the first request. If the footer fits in that tail, one read is enough. This matters on object storage such as S3, where each request has latency.
What the footer contains
- Schema: column names, types, and nesting.
- Row group list: the row count and total byte size of each row group.
- Column chunk metadata: for every column in every row group, the file offset, codec, encodings, compressed and uncompressed sizes, and statistics.
- Key-value metadata: free-form strings. Writers such as Arrow store their own schema here.
- Created-by string: the library and version that wrote the file.
You can see these fields with PyArrow.
import pyarrow as pa
import pyarrow.parquet as pq
table = pa.table({
"id": list(range(1_000_000)),
"category": ["a", "b", "c", "d"] * 250_000,
})
pq.write_table(table, "events.parquet", row_group_size=100_000, compression="zstd")
md = pq.ParquetFile("events.parquet").metadata
print(md.created_by)
print(md.num_columns, md.num_rows, md.num_row_groups)
print(md.serialized_size)
print(md.schema)serialized_size is the footer size in bytes. The schema printout lists each column with its physical type and repetition.
Footer size grows with the file's structure
The footer holds one entry per column per row group. Its size is roughly proportional to columns × row groups. The data volume matters much less. Two situations make this a problem:
- Very wide tables. A table with 5,000 columns and 100 row groups has 500,000 column chunk entries. The footer can reach tens of megabytes, and every reader must decode all of it, even to read one column.
- Many tiny row groups. Small row groups multiply entries without adding data.
import os
import pyarrow.parquet as pq
for rg_size in [1_000_000, 100_000, 1_000]:
path = f"events_rg{rg_size}.parquet"
pq.write_table(table, path, row_group_size=rg_size, compression="zstd")
footer = pq.ParquetFile(path).metadata.serialized_size
print(rg_size, os.path.getsize(path), footer)The footer grows as row groups shrink, while the file size changes little.
Common errors
- Truncated files. If a writer crashes before writing the footer, the file has no valid end. Readers fail with an error about missing
PAR1magic bytes or an invalid footer length. The data pages may be intact, but the file is unreadable by standard tools. Always close the writer. - Reading a file that is still being written. Because the footer comes last, a partially written file cannot be read. Write to a temporary name and rename it when complete.
- Appending to an existing file. You cannot append a row group without rewriting the footer. Most tools write new files instead.
- Stale metadata in datasets. Some systems cache footers, for example in a
_metadatafile. If files change, the cache no longer matches them.
Exercise
A table has 2,000 columns and is written as 500 row groups. A query needs one column. Why can opening the file still be slow, and what is one way to reduce the cost?
Show answer
The footer has an entry for every column in every row group, about 1,000,000 entries here, and the reader must decode the whole footer before it reads any data. To reduce the cost, write fewer, larger row groups, or split the table into several narrower files.
Exercise
In what order do the last bytes of a Parquet file appear, and why does a reader read them first?
Show answer
The footer comes first, then a 4-byte footer length, then the final PAR1 magic bytes. The reader reads the last 8 bytes to confirm the magic and get the footer length. It then reads the footer to learn where every row group and column chunk lives.