Sub topic 4
Column chunks and pages
This chapter assumes you know what a row group is, how a Parquet file is laid out from the leading magic bytes to the footer, and why columnar storage helps analytics. It also assumes you can run basic PyArrow code. Here you will look inside a row group: how each column is stored as a column chunk, and how each chunk is cut into pages.
Where column chunks and pages sit
A Parquet file is split horizontally into row groups. Inside one row group, every column gets exactly one column chunk. A column chunk holds all the values of that column for the rows in that row group. Each column chunk is split into pages. A page is the smallest unit that Parquet encodes, compresses, and reads as a whole.
The column chunks of one row group are stored one after another. All of id for the row group comes first, then all of category. This is why a reader that needs only id can read one contiguous byte range per row group and ignore the rest.
Column chunks
A column chunk is the unit of I/O planning. The footer records, for every column chunk:
- The byte offset where the chunk starts.
- Its compressed and uncompressed sizes.
- The compression codec.
- The encodings used.
- The number of values.
- Its statistics (minimum, maximum, null count).
With this information a reader can issue one read request per needed column chunk. It does not have to scan the file to find where a column begins.
Two details are worth knowing. First, the codec is chosen per column chunk, so different columns in one file can use different codecs. Second, the statistics are kept per column chunk, which is the granularity at which row group skipping works. Later chapters cover that in detail.
Pages
Writers do not write a column chunk as one block. They cut it into pages so that a reader can decode data in small pieces and keep memory use low. A page is usually around 1 MB before compression by default in many writers. The exact target depends on the library, and PyArrow's default data_page_size is 1 MiB.
There are three kinds of pages you will meet.
| Page type | Purpose | How many per column chunk |
|---|---|---|
| Dictionary page | Stores the table of distinct values when dictionary encoding is used | At most one, placed first |
| Data page | Stores the actual values (or dictionary indexes) for a run of rows | One or more |
| Index page | Reserved in the format, rarely written in practice | Usually none |
What a data page contains
A data page has a small header followed by a body. The header records the page type, the uncompressed and compressed sizes, and the number of values. The body has up to three parts, in this order:
- Repetition levels, only if the column is inside a repeated (list) structure.
- Definition levels, only if the column can be null or is nested.
- Encoded values, holding only the non-null values.
Because null values are tracked by definition levels, they do not take space in the value section. A column that is mostly null stays small. Definition and repetition levels are covered in the last chapter of this tutorial. For flat columns you can think of definition levels as a compact "is this value present?" marker.
There are two versions of the data page format. Data page v1 compresses the whole body (levels and values) as one block. Data page v2 stores the levels uncompressed and compresses only the values, and it records the level byte lengths in the header. This lets a reader work with levels without decompressing values. PyArrow selects the version with the data_page_version argument, and the default is "1.0".
The dictionary page
When dictionary encoding is on, the writer first collects the distinct values of the column chunk into a dictionary page. Data pages then store small integer indexes into that dictionary. If the dictionary grows too large (the PyArrow default limit is 1 MiB, set by dictionary_pagesize_limit), the writer stops using it and falls back to plain encoding for the remaining pages of that chunk. This fallback is a common reason a high-cardinality column compresses worse than you expect. The next chapter covers encodings.
Why pages exist
Pages serve three purposes.
- Bounded memory. A reader can decode one page at a time instead of materializing an entire column chunk.
- Compression unit. Each page is compressed on its own, so a reader decompresses only the pages it needs.
- Finer skipping. With the optional page index, a reader can skip individual pages inside a column chunk that survived row group filtering. The page index chapter covers this.
There is also a cost. Very small pages add header overhead and reduce compression ratios because each page is compressed separately. Very large pages raise memory use and reduce how precisely a reader can skip data.
Seeing it in code
The footer exposes column chunk details through PyArrow. This example writes a file with two columns and inspects the column chunks of the first row group. It also shows the encodings and the dictionary page offset.
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
rg = md.row_group(0)
for i in range(rg.num_columns):
col = rg.column(i)
print("column:", col.path_in_schema)
print(" codec:", col.compression)
print(" encodings:", col.encodings)
print(" num_values:", col.num_values)
print(" has_dictionary_page:", col.has_dictionary_page)
print(" dictionary_page_offset:", col.dictionary_page_offset)
print(" data_page_offset:", col.data_page_offset)
print(" compressed bytes:", col.total_compressed_size)
print(" uncompressed bytes:", col.total_uncompressed_size)Exact numbers vary with the library version. What you should see:
categoryhas a dictionary page, because it has only four distinct values. Itsdictionary_page_offsetis smaller than itsdata_page_offset, which matches the rule that the dictionary page comes first.num_valuesis 100,000 for both columns, matching the row group size.categoryhas a tiny compressed size compared withid's uncompressed size, because its indexes repeat heavily.
The footer reports column chunk totals but not a list of every page. To see individual pages you need a lower-level tool, such as the parquet-tools or parquet-cli utilities, or the Parquet page index when it is present.
Controlling page size
You can influence page layout when writing. These PyArrow options are the ones you will use most.
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_small_pages.parquet",
row_group_size=100_000,
data_page_size=64 * 1024,
data_page_version="2.0",
compression="zstd",
)
md = pq.ParquetFile("events_small_pages.parquet").metadata
print(md.row_group(0).column(0).total_compressed_size)data_page_size is a target, not a hard limit. Writers check the size after buffering a batch of values, so pages can run somewhat over the target. Setting it lower makes more pages per chunk. That can help selective reads when a page index is present, but it adds header overhead.
Common errors and gotchas
- Assuming one page per column chunk. Small column chunks may have one page, but large ones have many. Code that depends on a single page breaks on large files.
- Expecting statistics per page everywhere. Standard footer statistics are per column chunk. Per-page statistics exist only as the page index, and only if the writer produced it.
- Ignoring dictionary fallback. If a column's
encodingslist showsPLAINbut not a dictionary encoding on later pages, the dictionary limit was probably hit. Raisingdictionary_pagesize_limitmay help, at the cost of a larger dictionary to load. - Confusing compressed and uncompressed size.
total_compressed_sizeis what the reader fetches from storage.total_uncompressed_sizeis the memory needed after decompression, before decoding into Arrow arrays. - Reading the wrong offset. For a chunk with a dictionary page, the chunk starts at the dictionary page offset, not the data page offset. Tools that start at
data_page_offsetwould skip the dictionary.
Summary
Every row group holds one column chunk per column. Each column chunk is a sequence of pages: an optional dictionary page, then data pages. Pages are the unit of encoding and compression, and they keep decoding memory small. The footer describes column chunks, not individual pages, so row group skipping works at chunk level while finer skipping needs extra structures covered later.
Exercise
A column chunk uses dictionary encoding. Which page comes first in the chunk, and what happens if the dictionary grows past the writer's size limit partway through the chunk?
Show answer
The dictionary page comes first, followed by the data pages. If the dictionary exceeds the limit (1 MiB by default in PyArrow), the writer stops adding to it and writes the remaining data pages with plain encoding, so later pages in the same chunk store raw values instead of dictionary indexes.
Exercise
You write a file with row_group_size=100_000 and read md.row_group(0).column(1).num_values. What value do you expect for a flat column with no repeated structure, and why?
Show answer
100,000. Each column chunk holds one value slot for every row in its row group, and for a flat column the number of values equals the number of rows (nulls are counted in num_values but not stored in the value section).