Sub topic 5
The footer: how readers find everything
This chapter assumes you know the row group, column chunk, and page hierarchy from the earlier chapters. It also assumes you can run short PyArrow scripts. Here you will see how a reader locates all of that structure, what the footer stores, and what goes wrong when the footer is large or missing.
Why the metadata sits at the end
A Parquet file is written in one forward pass. The writer emits row group 1, then row group 2, and so on. While it writes, it does not yet know how many rows the file will hold. It also does not know the byte offset of the last column chunk or the final min and max values of each chunk.
All of that information exists only when the last row group is done. So the writer puts the file metadata at the very end, in a section called the footer. This has three consequences:
- A writer can stream data to disk without buffering the whole file. It only needs to hold one row group in memory at a time.
- A reader cannot start at the top of the file. It has to read the end first.
- A file whose writer crashed before writing the footer cannot be read, even though the data bytes may be intact.
The tail of the file
The last bytes of every Parquet file have a fixed shape:
| Position | Size | Content |
|---|---|---|
| Start of file | 4 bytes | Magic bytes `PAR1` |
| Row group data | variable | Column chunks, with optional page index and Bloom filter regions |
| Footer | variable | `FileMetaData`, serialized with Thrift's compact protocol |
| Footer length | 4 bytes | Unsigned little-endian integer, the footer size in bytes |
| End of file | 4 bytes | Magic bytes `PAR1` again |
The footer is a Thrift structure. Thrift is a serialization framework that Parquet uses to encode its metadata in a compact binary form. You never parse it by hand in practice, but the layout of the last eight bytes is simple enough to read yourself.
import os
import struct
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")
path = "events.parquet"
size = os.path.getsize(path)
with open(path, "rb") as f:
head = f.read(4)
f.seek(-8, os.SEEK_END)
tail = f.read(8)
footer_length = struct.unpack("<I", tail[:4])[0]
footer_start = size - 8 - footer_length
print("leading magic:", head)
print("trailing magic:", tail[4:])
print("footer length:", footer_length, "bytes")
print("footer starts at byte", footer_start, "of", size)Both magic values print as b'PAR1'. The footer length is small compared with the file size, because it describes the data and does not contain it.
How a reader opens a file
A reader follows a fixed sequence. It does not scan the file.
On local disk the extra seek is cheap. On object storage such as Amazon S3, every request has latency, so many readers fetch the final 64 KB or so in a single request, hoping the footer fits. If the footer length shows it is larger, they issue a second request for the rest. Keep this in mind: a bigger footer can mean more round trips before any data is read.
What the footer contains
The footer holds a FileMetaData structure. These are its main parts:
- Schema. The full list of columns, their physical types, logical types, and nesting. The reader needs this to decode anything.
- Row count. The total number of rows in the file.
- Row group list. One entry per row group, with its row count and byte sizes.
- Column chunk metadata. For each column chunk in each row group: the codec, the encodings used, compressed and uncompressed sizes, value count, the byte offsets of the first data page (and the dictionary page, if any), and the statistics.
- Locations of optional structures. Offsets for the page index and Bloom filter of a column chunk, when the writer produced them. The structures themselves live outside the footer, and the footer only points to them.
- Key-value metadata. Free-form string pairs that writers can attach.
- Writer identity. A
created_bystring such as the library name and version.
The important point is that the footer is a complete map. Given the footer, a reader knows the exact byte range of every column chunk. It can then request only the ranges for the columns and row groups it needs. Skipping a column chunk costs nothing beyond not fetching those bytes.
Reading the footer with PyArrow
ParquetFile reads the footer when you open the file and does not load any column data. Everything reachable from .metadata and .schema_arrow comes from the footer.
import pyarrow.parquet as pq
pf = pq.ParquetFile("events.parquet")
md = pf.metadata
print("created_by:", md.created_by)
print("format_version:", md.format_version)
print("rows:", md.num_rows)
print("row groups:", md.num_row_groups)
print("columns:", md.num_columns)
print("footer size:", md.serialized_size)
print(pf.schema_arrow)md.serialized_size should equal the footer length you read from the raw bytes above. This confirms that PyArrow is reading the same structure.
Now look at one column chunk. The footer holds every field printed here.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
col = md.row_group(0).column(0)
print(col.path_in_schema, col.compression)
print(col.total_compressed_size, col.total_uncompressed_size)
print(col.data_page_offset, col.dictionary_page_offset)
stats = col.statistics
print(stats.has_min_max, stats.min, stats.max, stats.null_count)The offsets tell a reader where in the file to seek. dictionary_page_offset is None when the chunk has no dictionary page. The statistics are what let a reader decide to skip the chunk, which later chapters cover in detail.
Custom metadata
The footer can carry your own key-value pairs. Writers use this for provenance, schema versions, or, as PyArrow does, to store the original Arrow schema so types like timestamps with time zones round-trip.
import pyarrow as pa
import pyarrow.parquet as pq
small = pa.table({"id": [1, 2, 3]})
small = small.replace_schema_metadata({"source": "clickstream", "owner": "data-team"})
pq.write_table(small, "tagged.parquet")
md = pq.ParquetFile("tagged.parquet").metadata
for key, value in md.metadata.items():
print(key, value[:60])Keys and values come back as bytes. You will see your two pairs and also an ARROW:schema entry that PyArrow added. Nothing in the data pages changes. Only the footer grows.
Edge cases and failure modes
Truncated or incomplete files. If a writer is killed mid-write, the file has PAR1 at the start but no footer. Readers fail with an error about a missing magic number or an invalid footer length. The row group bytes are still on disk, but without the footer nothing says where one chunk ends and the next begins. Treat such files as lost, and write to a temporary name then rename on success so readers never see partial files.
You cannot append in place. Adding a row group means overwriting the old footer and writing a new one. Libraries do not do this safely. The normal pattern is to write new files and let a table layer, such as a directory of files, combine them.
Large footers. Footer size grows with columns multiplied by row groups. A file with 5,000 columns and 500 row groups holds 2.5 million column chunk entries. A reader must fetch and decode all of them even to read one column, because the footer is a single unit. This is one reason very wide tables and very small row groups hurt open time. The row group sizing chapter returns to this trade-off.
Many small files. Each file has its own footer, and each footer costs at least one read. Thousands of tiny files multiply that cost. Engines often cache footers for repeated queries.
Encrypted footers. Parquet supports modular encryption. With an encrypted footer, the file ends in the magic PARE instead of PAR1. A reader without the key cannot read the schema or the statistics. Plaintext-footer mode keeps the footer readable while encrypting the column data.
Stale statistics in the footer. Statistics describe the file as written. If you rewrite the data some other way, you must write a new file with a new footer. There is no partial update.
Summary of the reader's decisions
After one read of the footer, a reader can:
- Validate that the file is Parquet from the magic bytes.
- Learn the schema and decide which columns to project.
- Compare filter values against each chunk's statistics and drop row groups.
- Compute exact byte ranges for the chunks that remain.
None of these steps touches data pages. That is why a well-formed footer turns a large file into something a reader can query by fetching a small fraction of it.
Exercise
You open a Parquet file on object storage and get an error saying the footer is missing, but the file is 2 GB. What most likely happened, and can you recover the data by reading it with a different library?
Show answer
The writer most likely stopped before finishing, so the footer, footer length, and closing PAR1 were never written. A different library will not help, because the footer holds the schema and the offsets of every column chunk. Without it no reader can tell where chunks begin or how to decode them. Rewrite the file from the source, and in future write to a temporary name and rename it after the writer closes successfully.
Exercise
Using the raw bytes of a file, how do you find where the footer starts, and why does PyArrow's metadata.serialized_size need to agree with that value?
Show answer
Read the last 8 bytes. The first 4 are the footer length as an unsigned little-endian integer, and the last 4 are PAR1. The footer starts at file size minus 8 minus the footer length. serialized_size is the size of that same Thrift-encoded structure, so the two numbers must match. If they do not, you are not reading the footer you think you are.
Exercise
A table has 2,000 columns and the writer used very small row groups, producing 1,000 row groups per file. A query reads one column. Why is opening the file still slow, and what would you change?
Show answer
The footer lists metadata for every column chunk, which here is 2,000 times 1,000, or 2 million entries. The reader must fetch and decode the whole footer even to read one column. Use larger row groups to cut the number of entries, and consider splitting very wide tables into narrower files or tables.