Sub topic 3
Row groups: the unit of horizontal partitioning
This chapter assumes you know what a columnar format is, can read a table schema, and can run basic Python with PyArrow. It covers how Parquet splits a table into row groups and why that split matters for reads and writes.
What a row group is
A Parquet file stores a table in columns. It does not store the whole table as one block per column, though. It first cuts the table into horizontal slices, and each slice is a row group. Inside a row group, the data is stored column by column.
A row group holds a contiguous range of rows. For a table with one million rows and a row group size of 100,000, the file has ten row groups. Row group 0 holds rows 0 to 99,999, row group 1 holds rows 100,000 to 199,999, and so on.
Why Parquet splits rows
Row groups give the format three practical benefits.
- Bounded memory on write. A writer buffers one row group at a time, compresses it, and flushes it. It never needs the whole table in memory.
- Parallel reads. Each row group can be read and decoded independently. A query engine can assign different row groups to different threads or workers.
- Skipping. The footer stores statistics for each column in each row group. A reader can use them to ignore row groups that cannot match a filter. A later chapter covers this in detail.
Writing a file with a chosen row group size
The row_group_size argument sets the maximum number of rows per row group.
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",
)This produces ten row groups of 100,000 rows each, compressed with Zstandard.
Checking the result
You can confirm the layout by reading the footer. Reading the footer does not load any column data.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
print(md.num_rows, md.num_row_groups)
for i in range(md.num_row_groups):
print(i, md.row_group(i).num_rows)The first line prints 1000000 10. The loop prints ten lines, each with 100,000 rows.
The trade-off in row group size
Row group size is a balance. Each column chunk inside a row group is encoded and compressed on its own, so the size affects both file efficiency and read behavior.
| Property | Small row groups | Large row groups |
|---|---|---|
| Compression and encoding | Less repeated data per chunk, so a lower ratio | More repeated data per chunk, so a higher ratio |
| Footer size | Larger, because there are more entries | Smaller |
| Skipping granularity | Fine, so a filter can skip more precisely | Coarse, so a filter skips whole large blocks |
| Write memory | Low | High, because a whole group is buffered |
| Parallelism | Many units, but with more overhead per unit | Fewer units, which can limit parallel readers |
Very small row groups are a common mistake. A file with thousands of tiny row groups has a large footer and many small reads, and its chunks compress poorly. Very large row groups can exhaust writer memory and reduce parallelism. A later chapter gives guidance on choosing a value for a given workload.
Common errors
- Assuming one row group per file. Some tools write a single huge row group by default. Always check
num_row_groupsinstead of assuming. - Appending by rewriting rows in place. Parquet files are immutable. To add data you write new row groups or new files. You cannot edit a row group in place.
- Confusing row groups with partitions. Directory partitioning, such as
date=2026-12-01/, splits data across files. Row groups split data inside one file.
Exercise
A file has 2,500,000 rows and was written with row_group_size=1_000_000. How many row groups does it have, and how many rows are in the last one?
Show answer
Three row groups. The first two hold 1,000,000 rows each, and the last holds the remaining 500,000 rows.
Exercise
You write a file with only 1,000 rows per row group and notice that reads are slow and the file is large. Name two reasons related to row group size.
Show answer
The footer grows because it has an entry for every row group and column chunk. Each small chunk also compresses and encodes poorly, and reads must issue many small requests.