A Parquet file is not one long block of numbers. It is cut into row groups, each row group into one chunk per column, each chunk into pages, and every page is encoded and then compressed. Knowing the layers explains every speed trick in the next topics, because each of them skips at one of these levels.
The idea in plain words
Where we are. The previous topic showed that columns are stored apart and that the footer says where. This one goes one level down: the row group is the block a reader can fetch alone, and the encoding decides how few bytes a column needs before the codec in the next topic even starts.
A horizontal block of a Parquet file: a fixed number of rows, stored as one chunk per column. Each row group carries its own metadata, so a reader can fetch one, or skip it, without touching the others.
Row groups: the block you can fetch alone
The writer's row_group_size sets how many rows go in each block. Too small and the file drowns in per-group overhead; too large and a reader cannot skip finely or hold a block in memory. write_grouped picks the size, group_rows reads the result back from the footer, and read_group fetches one block without reading the others.
# Cut the table into row groups of 10,000 rows and list them from the footerprint("row groups:", write_grouped(table, "g.parquet", 10000))print("rows in each:", group_rows("g.parquet"))
row groups: 4 rows in each: [10000, 10000, 10000, 3493]
# Fetch only the last row group, the tail of the last stock's barslast = read_group("g.parquet", 3)print(last.num_rows, "rows;", "first date:", last.column("date")[0], "| last date:", last.column("date")[-1])
3493 rows; first date: 2012-09-28 | last date: 2026-08-21
Encodings: fewer bytes before compression
Inside a chunk, values are first encoded. PLAIN writes every value in full. Dictionary encoding (RLE_DICTIONARY) writes each distinct value once and then a small integer per row, with runs of the same integer folded by RLE. A column like symbol, with five distinct values over 33,000 rows, collapses to almost nothing. A column of prices, almost all distinct, can even grow, as the output below shows.
# Dictionary encoding on and off: the encodings of symbol, and the bytes each setting gives symbol and closedef chunk_size(path, name): group = pq.ParquetFile(path).metadata.row_group(0) return sum(group.column(c).total_compressed_size for c in range(group.num_columns) if group.column(c).path_in_schema == name)for flag in (True, False): names = encodings_of(table, "d.parquet", "symbol", flag) print("dictionary", flag, names, "| symbol bytes:", chunk_size("d.parquet", "symbol"), "| close bytes:", chunk_size("d.parquet", "close"))
dictionary True ['PLAIN', 'RLE', 'RLE_DICTIONARY'] | symbol bytes: 161 | close bytes: 229798 dictionary False ['PLAIN', 'RLE'] | symbol bytes: 11167 | close bytes: 177572
Engines default to around a million rows or about 128 MB per group, because a block should be big enough to compress well and small enough to fit in memory. For files you query by date range, write rows in date order first: then each row group covers a narrow range and the next topics can skip most of them.
What the tasks ask
- 1`write_grouped` and `group_rows`Pass
row_group_sizetopq.write_table, then readmetadata.num_row_groupsand eachrow_group(g).num_rows. - 2`read_group`
pq.ParquetFile(path).read_row_group(index)fetches that block alone. - 3`encodings_of`Write with
use_dictionary=..., then find the column chunk bypath_in_schemaand returnsorted(chunk.encodings).
symbol column far more than the close column?Lab · what's graded
4 tasks · 100 pts- Choose the row-group size:
write_grouped25 pts - List the row groups:
group_rows25 pts - Read one row group alone:
read_group25 pts - See how a column is encoded:
encodings_of25 pts