Sub topic 4
Column chunks and pages
This chapter assumes you know what a row group is and that Parquet stores data by column. It covers how one row group is split into column chunks, and how each chunk is split into pages. These are the smallest units a reader decodes.
From row group to column chunk
A row group holds a horizontal slice of the table. Inside it, Parquet stores each column separately. The stored data for one column in one row group is a column chunk.
A file with 10 row groups and 2 columns therefore has 20 column chunks. Each chunk is contiguous on disk. A reader that needs only the id column reads only the id chunks and never touches category.
Pages inside a chunk
A column chunk is divided into pages. A page is the unit that gets encoded, compressed, and decoded as one block. The default target size in many writers is about 1 MB, though the exact value depends on the library.
A chunk contains these page types:
- Dictionary page. Present only when dictionary encoding is used. It holds the distinct values, and it comes first in the chunk.
- Data pages. They hold the actual values, plus the small bookkeeping needed to decode them.
Each page starts with a header. The header records the page type, the number of values, and the compressed and uncompressed sizes. The data pages hold the column's values for consecutive rows, in row order.
Why pages exist
Pages keep memory use bounded. A reader decodes one page at a time instead of a whole chunk. Pages are also the unit of compression, so a reader can decompress only the pages it needs.
Chunk-level statistics decide whether a whole chunk can be skipped. Pages are what make finer skipping possible later, through the page index.
Looking at the layout
You can see the chunk-level view with the file from the earlier chapters. PyArrow reports each chunk's offsets and encodings.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
col = md.row_group(0).column(1)
print(col.path_in_schema)
print(col.encodings)
print(col.has_dictionary_page, col.dictionary_page_offset)
print(col.data_page_offset)
print(col.total_compressed_size)For the category column, which has only four distinct values, you should see a dictionary page offset and dictionary-based encodings in the list. For id, which is unique, the writer may start with a dictionary and fall back to plain encoding when the dictionary grows too large. That fallback is why a chunk can mix encodings.
Common errors
- Assuming a chunk is one block. A chunk is a sequence of pages. Compression and encoding apply per page, not to the whole chunk.
- Confusing chunk with row group. A row group is a set of chunks, one per column. Chunk sizes within one row group differ, because columns compress differently.
- Expecting page boundaries to align across columns. Pages hold different numbers of rows in different columns. A narrow column fits more rows per page than a wide one.
- Setting a tiny page size. Many small pages add header overhead and slow reads. Tune page size only when you have a measured reason.
Exercise
A file has 8 row groups and 5 columns, and none of the columns are nested. How many column chunks does it contain, and what must a reader read to scan one column across the whole file?
Show answer
It contains 8 × 5 = 40 column chunks. To scan one column, the reader reads that column's 8 chunks, one per row group, and skips the other 32. Within each chunk it reads the optional dictionary page and the data pages.