Sub topic 1
Why Columnar Storage Matters
Prerequisites
Assume you know basic tabular data, schemas, Python, and the difference between row-oriented and column-oriented storage.
Why Columnar Storage Matters
A row-oriented file stores all fields for one record together:
id, category, timestamp, amount
1, A, ..., ...A columnar file stores values from the same field together. Parquet is a columnar file format.
This layout helps analytical queries. If a query needs only amount, the reader can load that column without reading id, category, or timestamp. Similar values are also adjacent, so encodings and compression often reduce the file size.
Columnar storage is less convenient for frequently updating individual records. It is optimized for reading selected columns from many records.
Anatomy of a Parquet File
A Parquet file contains data near the beginning and metadata in a footer at the end. The footer describes the schema and where each part of the data is stored. A reader can find the footer, inspect metadata, and then read only the required sections.
Row Groups: the Unit of Horizontal Partitioning
A row group is a horizontal partition: it contains a consecutive set of complete rows. Every row group has one column chunk for each column.
For example, a million-row table might use ten row groups of 100,000 rows:
| Row group | Rows |
|---|---|
| 1 | 100,000 |
| 2 | 100,000 |
Readers can skip entire row groups when metadata shows that they cannot contain requested values. Row group size therefore affects both scan efficiency and memory use.
import pyarrow as pa
import pyarrow.parquet as pq
table = pa.table({
"id": range(1_000_000),
"category": ["a", "b", "c", "d"] * 250_000,
})
pq.write_table(
table,
"events.parquet",
row_group_size=100_000,
)Column Chunks and Pages
A column chunk contains one column’s values for one row group. It is the main unit a reader loads for a selected column.
Column chunks are divided into pages, which are smaller encoded blocks. Pages allow readers to process data incrementally and support finer-grained metadata and skipping. Encodings reduce redundancy inside pages before optional compression is applied.
Exercise
A query selects only amount from one row group. Which data should a Parquet reader avoid loading?
Show answer
It should avoid the other columns' chunks and can avoid any row groups ruled out by metadata.