Sub topic 3
Inspecting Row Groups and Statistics with PyArrow
Assume you know Python, tabular data, schemas, and the difference between row-oriented and column-oriented storage. This chapter shows how Parquet metadata controls filtered reads.
Inspecting metadata with PyArrow
A Parquet footer stores file-level and row-group metadata. PyArrow exposes it through ParquetFile.
import pyarrow.parquet as pq
metadata = pq.ParquetFile("events.parquet").metadata
print(metadata.num_rows, metadata.num_row_groups)
column = metadata.row_group(0).column(0)
print(column.path_in_schema)
print(column.compression)
print(column.total_compressed_size)
print(column.total_uncompressed_size)
stats = column.statistics
print(stats.min, stats.max, stats.null_count)A row group contains one column chunk for each column. The statistics describe values in that chunk.
Predicate pushdown and row-group skipping
Predicate pushdown applies a filter before reading data. For example, this read requests only id values at least 950,000:
result = pq.read_table(
"events.parquet",
columns=["id"],
filters=[("id", ">=", 950_000)],
)
print(result.num_rows)A reader can skip a row group when its maximum id is below 950,000. Statistics cannot skip a group safely when ranges overlap the predicate.
Choosing row-group size and codec
Larger row groups improve compression and reduce metadata overhead. Smaller groups improve skipping and reduce the amount read for selective queries.
| Workload | Useful starting choice |
|---|---|
| Large analytical scans | 128–512 MiB row groups, Zstandard |
| Fast general-purpose reads | Moderate groups, Snappy |
| Maximum compression | Zstandard or Gzip, with slower writes or reads |
Test representative data. Encodings such as dictionary and run-length encoding reduce patterns before compression, so codec results depend on the column values.
Finer-grained skipping
A page index records statistics and offsets for individual pages inside a column chunk. Readers that support it can skip pages even when a row group remains relevant. Support and writer settings vary, so treat page indexes as an optimization rather than a guarantee.
Bloom filters
A Bloom filter is a compact probabilistic structure for membership checks. It can reject row groups that definitely do not contain a requested value. False positives are possible; false negatives are not. Bloom filters are most useful for selective equality lookups.
Nested data
Parquet represents nested lists and structs with definition levels and repetition levels. Definition levels record how deeply a value exists, including null fields. Repetition levels record whether a value continues the current list or starts a new record. These levels let Parquet reconstruct nested data without storing every row as a separate object.
Exercise
A filtered query reads nearly every row group. What should you investigate first?
Show answer
Check whether the filter column has useful value ranges, whether row groups are too large, and whether the data is ordered in a way that makes statistics selective.