Part 3 · Parquet and columnar files · Chapter 5
Parquet file layout
A Parquet file byte by byte: magic, row groups, column chunks, pages, the Thrift-encoded footer, and how a reader finds what it needs with a tail read and one range per column chunk.
After this chapter you should be able to:
- Draw the physical layout of a Parquet file and name what each byte range holds.
- Read FileMetaData, RowGroup, ColumnChunk and PageHeader fields from parquet.thrift, and decode a page header by hand.
- Predict which byte ranges a reader fetches for a given projection and filter.
- Explain how row group size and page size trade scan efficiency against memory and overhead.
Every Delta and Iceberg table in this book stores its rows in Parquet files. The table formats decide which files make up a version; Parquet decides how a reader gets from a file to the values of one column without reading the others. This chapter takes a Parquet file apart byte by byte, using a small writer and reader built for the book that produce real files: Arrow’s reader reads its files, and it reads Arrow’s.
Spec links point to apache/parquet-format at 6f87925. Implementation links point to Arrow C++ 26.0.0 and parquet-java 1.17.1.
From Dremel to Parquet
Google’s Dremel paper (Melnik et al., PVLDB 3(1), 2010) described a columnar storage format for nested records: shred each record into one column per leaf field, with two small integers per value (repetition and definition levels) that let a reader put the record back together.[Dremel] Parquet was created in 2013 by engineers at Twitter and Cloudera to bring that representation to the Hadoop ecosystem. The spec’s motivation section says it plainly: “We created Parquet to make the advantages of compressed, efficient columnar data representation available to any project in the Hadoop ecosystem,” and it is “built from the ground up with complex nested data structures in mind”.[README]
This chapter covers flat columns. Chapter 6 covers encodings and compression, chapter 7 the levels for nested data, and chapter 8 statistics, page indexes and bloom filters.
- 2010 Dremel: Interactive Analysis of Web-Scale Datasets · Sergey Melnik et al. (Google), PVLDB 3(1)
- 2013 Parquet 1.0 announced · Twitter (Julien Le Dem) and Cloudera (Nong Li)
- 2015-04 Parquet becomes an Apache top-level project · ASF
The bytes
The spec’s glossary defines three levels. A row group is “a logical horizontal partitioning of the data into rows”. A column chunk holds one column’s data for one row group, and column chunks “are guaranteed to be contiguous in the file”. A page is “conceptually an indivisible unit (in terms of compression and encoding)”. So: “a file consists of one or more row groups. A row group contains exactly one column chunk per column. Column chunks contain one or more pages.”[README]
Here is the book’s sample file: 24 rows of (trip_id INT64, city STRING, fare DOUBLE nullable), written with 8 rows per row group and 4 rows per page, no dictionary, no compression. It is 2,084 bytes: 4 bytes of magic, three row groups of three column chunks each, a 728-byte footer, the 4-byte little-endian footer length and the closing magic.
FileMetaData by stepping back 728 bytes from the start of the tail. Byte offsets are from the sample file, and box widths are schematic.[Parquet format] The metadata comes last “to allow for single pass writing”: a writer streams column chunks out as their buffers fill, keeps each chunk’s offsets and statistics in memory, and writes them all at the end. The price is in the spec’s error-recovery section: “If the file metadata is corrupt, the file is lost.”[README] A writer that crashes before the footer leaves a file with no way in, which is one more reason table formats only publish a file after it is complete.
Q1. Which statement matches the spec's hierarchy?
Q2. What does the spec guarantee about a column chunk's bytes?
Q3. What are the last 8 bytes of every (unencrypted) Parquet file?
Q4. Why is the file metadata at the end of the file rather than the start?
The footer
The footer is one Thrift struct, FileMetaData, and “all thrift structures are serialized using the TCompactProtocol”.[README] Its fields, trimmed:[thrift]
struct FileMetaData {
1: required i32 version
2: required list<SchemaElement> schema; // the schema tree, flattened depth-first
3: required i64 num_rows
4: required list<RowGroup> row_groups
5: optional list<KeyValue> key_value_metadata
6: optional string created_by
7: optional list<ColumnOrder> column_orders;
...
}
version. The spec notes that there is “no agreed upon consensus of what constitutes version 2”, so writers should write 1, and readers should accept 1 and 2 interchangeably.[thrift]schema. The tree “flattened to a list by doing a depth-first traversal”, root first. A group element hasnum_children; a leaf has a physicaltype, arepetition_type(REQUIRED, OPTIONAL or REPEATED) and optionally a logical type such asSTRING.[thrift] The physical types are deliberately few: BOOLEAN, INT32, INT64, INT96 (deprecated), FLOAT, DOUBLE, BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY. A string is a BYTE_ARRAY annotatedSTRING.[thrift]row_groups. EachRowGrouphas itsnum_rows, byte sizes and oneColumnChunkper leaf column, in schema order.[thrift]key_value_metadata. Free-form. Arrow stores its own schema here asARROW:schema, which is why Arrow’s version of the sample file has a 1,263-byte footer against this writer’s 728.
Each ColumnChunk wraps a ColumnMetaData, which is what a reader plans with:[thrift]
struct ColumnMetaData {
1: required Type type
2: required list<Encoding> encodings
3: required list<string> path_in_schema
4: required CompressionCodec codec
5: required i64 num_values // includes nulls
6: required i64 total_uncompressed_size // all pages, headers included
7: required i64 total_compressed_size
9: required i64 data_page_offset // first data page
11: optional i64 dictionary_page_offset // the dictionary page, if any
12: optional Statistics statistics; // min_value, max_value, null_count, ...
13: optional list<PageEncodingStats> encoding_stats // pages per (page type, encoding)
...
}
The chunk’s bytes run from its first page (the dictionary page if there is one, else data_page_offset) for total_compressed_size bytes. Statistics holds null_count and min_value/max_value under the column’s sort order, encoded as PLAIN “except that variable-length byte arrays do not include a length prefix”; a writer may store shorter bounds that are not actual values.[thrift] Those statistics are how a reader skips whole row groups without reading them (chapter 8 goes further).
Q1. How are FileMetaData and page headers serialized?
Q2. How does FileMetaData store the schema tree?
Q3. A nullable column chunk holds 8 rows, 2 of them null. What is ColumnMetaData.num_values, and how many values are in the data pages' value sections?
Q4. How is the min_value of a STRING column stored in Statistics?
Q5. What should a writer put in FileMetaData.version at the pin?
Pages
Column chunks are “composed of pages written back to back”. Each page starts with a PageHeader that says its type, its sizes and how it is encoded, so a reader “can skip over pages they are not interested in”.[README][thrift]
The first page of the sample file is a data page for trip_id. Its 41-byte header decodes field by field:
15 00 1: type = DATA_PAGE (0) delta 1, i32, zigzag(0)
15 40 2: uncompressed_page_size = 32 zigzag(32) = 64 = 0x40
15 40 3: compressed_page_size = 32
2c 5: data_page_header (struct) delta 2, type 12
15 08 1: num_values = 4
15 00 2: encoding = PLAIN
15 06 3: definition_level_encoding = RLE (3)
15 06 4: repetition_level_encoding = RLE
1c 5: statistics (struct)
36 00 3: null_count = 0 delta 3, i64
28 08 ec 03 00 … 5: max_value = 1004 binary, 8 bytes little endian
18 08 e9 03 00 … 6: min_value = 1001
00 stop
00 stop
00 stop
After the header come, back to back with no padding, “repetition levels data, definition levels data, encoded values”; uncompressed_page_size covers all three.[README] For a non-nested column the repetition levels are omitted (they would always be 0), and for a required column the definition levels are omitted (they would always be the maximum). So trip_id’s page body is just four PLAIN 8-byte integers: 32 bytes.
The fare column is optional, so its pages carry definition levels: 1 for a value, 0 for a null. In a v1 data page they are RLE/bit-packing hybrid encoded with a 4-byte length prefix.[Encodings] “NULL values are not encoded in the data”: a page of four fares with one null has four definition levels and three values.[README]
1. At level 0 it emits a null. The diagram shows the decoded contents of each page section.[Parquet nulls] With dictionary encoding on, each chunk starts with a dictionary page that holds the distinct values in PLAIN encoding, and the data pages hold indices into it (RLE_DICTIONARY: one byte of bit width, then the indices in the hybrid encoding). “The dictionary page must be placed at the first position of the column chunk. At most one dictionary page can be placed in a column chunk.”[README][Encodings] Chapter 6 covers how writers choose and when they fall back.
Q1. In a data page (v1) of an optional, non-nested column, what follows the page header?
Q2. Where can a dictionary page appear?
Reading a file
“Readers are expected to first read the file metadata to find all the column chunks they are interested in. The columns chunks should then be read sequentially.”[README] On an object store that becomes a small number of range GETs (chapter 3):
- The tail. parquet-java seeks to
size - 8, reads the footer length and checks the magic (PAR1, orPAREfor an encrypted footer), then seeks back and reads exactly the footer.[parquet-java] Arrow C++ saves a round trip by reading a speculative tail offooter_read_sizebytes, 64 KiB by default, and only issues a second read if the footer is bigger than that.[Arrow][Arrow] - Row group selection. With the footer decoded, the reader drops row groups whose statistics cannot satisfy the filter. This needs no data at all.
- Column chunk reads. For each surviving row group, one range per projected column,
[start, start + total_compressed_size). Readers often merge ranges that are close together into one request. - Pages. The chunk is decoded page by page from its headers.
- open(file, size from LIST or the table log). A table format already knows each file's size (Delta add.size, Iceberg file_size_in_bytes), so an engine can hand it to the reader instead of asking S3 with a HEAD request.
- GET Range: last 64 KiB. Arrow reads a speculative tail of footer_read_size bytes (64 KiB by default). The last 8 bytes are the footer length and "PAR1". If the footer fits in the tail, this one request is enough. ParseMetaData ↗
- GET Range: the rest of the footer (only if it was bigger). A footer larger than the tail costs a second request. parquet-java always does it in two steps: seek to the length, then read the whole footer. second read ↗
- FileMetaData: schema, row groups, chunk offsets, statistics. Decoded from Thrift compact. Everything the reader needs to plan is here: which row groups exist, where each column chunk starts and ends, and min/max/null counts. FileMetaData ↗
- project [fare], filter trip_id >= 1017. Row groups whose trip_id statistics cannot match are dropped before any data is read. Only the fare column chunks of the remaining row groups are needed. Statistics ↗
- GET Range: fare chunk of row group 2 (in parallel with others). A column chunk is contiguous, so one range per chunk. Readers may merge nearby ranges to save requests. column chunk ↗
- pages → decode levels and values → batches. Each page header says its type, size and encoding. A dictionary page, if any, comes first in the chunk. column chunks ↗
For SELECT fare WHERE trip_id >= 1017 on the sample file, row groups 0 and 1 have trip_id in [1001, 1008] and [1009, 1016], so only row group 2 is read, and only its trip_id chunk (to apply the filter to each row) and its fare chunk: four requests (tail, footer, two chunks) instead of the whole file. The explorer below computes this for any choice of columns and filter.
Q1. How does Arrow C++ read the footer of a file on S3 by default?
Q2. SELECT fare WHERE trip_id >= 1017. Row group 0 has trip_id min 1001, max 1008. What does the reader fetch from row group 0?
Sizing
Two sizes matter, and the spec’s advice is old:[README]
- Row group size. “Larger row groups allow for larger column chunks which makes it possible to do larger sequential IO. Larger groups also require more buffering in the write path.” The README recommends 512 MB to 1 GB row groups, sized to an HDFS block. A writer buffers a whole row group before it can write it, for every column at once.
- Page size. “Data pages should be considered indivisible so smaller data pages allow for more fine-grained reading (e.g. single row lookup). Larger page sizes incur less space overhead (less page headers) and potentially less parsing overhead.” The README recommends 8 KB.
What implementations actually default to:
| Writer | Row group | Page |
|---|---|---|
parquet-java (parquet.block.size, parquet.page.size) | 128 MiB | 1 MiB, at most 20,000 rows |
| Arrow C++ / pyarrow | 1,048,576 rows | 1 MiB, at most 20,000 rows |
The sample file shows why tiny pages are bad: 718 of its 2,084 bytes are page headers, because each page holds only four values. At 1 MiB per page the headers are noise. Row groups trade the other way: more row groups give the reader more chances to skip with statistics and more units of parallelism, but each one adds a set of column chunks and footer entries. Table formats add a third size on top, the target file size, which the compaction chapter covers.
Q1. What is parquet-java's default row group size (parquet.block.size)?
Q2. What trade-off does page size control?
Try it
The explorer writes the 24-row file in your browser with the settings you pick, and reads it back.
- Click the footer segment (the long one near the end) and expand
row_groups → [0] → columns → [2] → meta_data: that is everything a reader knows about the firstfarechunk before reading it. - Click a page header and compare it with the hand-decoded bytes above.
- Set rows per page to 2, then 8, and watch the page-header share of the file change.
- Turn on dictionary encoding: each chunk now starts with a dictionary page, and
city’s values shrink to a bit width and a few bytes of bit-packed indices (chapter 6). - Change the query. With
city = 'Denver'every row group is skipped from statistics alone; with no filter every projected chunk is read.
24 rows of (trip_id INT64, city STRING, fare DOUBLE nullable). 2084 bytes: 3 row groups, 18 pages, footer 728 bytes. Page headers 718 B, levels 36 B, values 590 B.
Byte ranges · click one
- 0–3 magic "PAR1"
- 4–44 rg 0 · trip_id: data page header
- 45–76 rg 0 · trip_id: values (PLAIN)
- 77–117 rg 0 · trip_id: data page header
- 118–149 rg 0 · trip_id: values (PLAIN)
- 150–186 rg 0 · city: data page header
- 187–226 rg 0 · city: values (PLAIN)
- 227–264 rg 0 · city: data page header
- 265–306 rg 0 · city: values (PLAIN)
- 307–347 rg 0 · fare: data page header
- 348–353 rg 0 · fare: definition levels (hybrid, 4-byte length)
- 354–377 rg 0 · fare: values (PLAIN)
- 378–418 rg 0 · fare: data page header
- 419–424 rg 0 · fare: definition levels (hybrid, 4-byte length)
- 425–456 rg 0 · fare: values (PLAIN)
- 457–497 rg 1 · trip_id: data page header
- 498–529 rg 1 · trip_id: values (PLAIN)
- 530–570 rg 1 · trip_id: data page header
- 571–602 rg 1 · trip_id: values (PLAIN)
- 603–640 rg 1 · city: data page header
- 641–681 rg 1 · city: values (PLAIN)
- 682–719 rg 1 · city: data page header
- 720–760 rg 1 · city: values (PLAIN)
- 761–801 rg 1 · fare: data page header
- 802–807 rg 1 · fare: definition levels (hybrid, 4-byte length)
- 808–831 rg 1 · fare: values (PLAIN)
- 832–872 rg 1 · fare: data page header
- 873–878 rg 1 · fare: definition levels (hybrid, 4-byte length)
- 879–902 rg 1 · fare: values (PLAIN)
- 903–943 rg 2 · trip_id: data page header
- 944–975 rg 2 · trip_id: values (PLAIN)
- 976–1016 rg 2 · trip_id: data page header
- 1017–1048 rg 2 · trip_id: values (PLAIN)
- 1049–1086 rg 2 · city: data page header
- 1087–1128 rg 2 · city: values (PLAIN)
- 1129–1165 rg 2 · city: data page header
- 1166–1205 rg 2 · city: values (PLAIN)
- 1206–1246 rg 2 · fare: data page header
- 1247–1252 rg 2 · fare: definition levels (hybrid, 4-byte length)
- 1253–1276 rg 2 · fare: values (PLAIN)
- 1277–1317 rg 2 · fare: data page header
- 1318–1323 rg 2 · fare: definition levels (hybrid, 4-byte length)
- 1324–1347 rg 2 · fare: values (PLAIN)
- 1348–2075 FileMetaData (Thrift compact)
- 2076–2079 footer length = 728 (little endian)
- 2080–2083 magic "PAR1"
Select a byte range: the footer and page headers decode to their Thrift fields.
A query against this file
| GET Range | bytes | why |
|---|---|---|
2076-2083 | 8 | footer length + "PAR1" |
1348-2075 | 728 | FileMetaData (728 bytes) |
903-1048 | 146 | row group 2, trip_id (to evaluate the filter) |
1206-1347 | 142 | row group 2, fare |
| skipped | 0 | row group 0: trip_id in [1001, 1008] cannot match >= 1017 |
| skipped | 0 | row group 1: trip_id in [1009, 1016] cannot match >= 1017 |
1024 of 2084 bytes in 4 requests. Row-group statistics used for skipping: rg 0 [1001, 1008], rg 1 [1009, 1016], rg 2 [1017, 1024]
Summary
- A Parquet file is
PAR1, column chunks grouped by row group, a Thrift-compactFileMetaData, its 4-byte length andPAR1. Column chunks are contiguous; row groups are only a logical grouping. - The footer holds the flattened schema, and per column chunk its offsets, sizes, encodings and statistics. It is written last, so writing is single-pass and a file without a footer is unreadable.
- Pages are the unit of encoding and compression. A v1 data page is header, repetition levels, definition levels, values; nulls exist only as definition levels. A dictionary page, if any, comes first in the chunk.
- A reader reads the tail, then the footer (Arrow in one 64 KiB read when it fits), drops row groups by statistics, and reads one range per projected column chunk.
- Writers default to 128 MiB (parquet-java) or 1 Mi rows (Arrow) per row group and 1 MiB pages; the spec’s README recommends larger row groups and much smaller pages.
Concepts in this chapter
Explained here
Primary sources
Review this chapter
This chapter has 15 quiz questions.