How you lay files out on disk decides how much data every query must read, and in cloud warehouses and lakes that is directly what you pay for.
Row formats and column formats
CSV and JSON are row-oriented text. To compute the average of one column, a reader still has to parse every field of every row. They carry no types, so "007" and 7 are only distinguished by convention.
Parquet and ORC are columnar and binary. Values of one column are stored together, compressed and typed. A query that needs two columns out of fifty reads only those two, and min and max statistics in the file let it skip whole chunks.
Compression and size
Similar values sit next to each other in a column, so compression works very well. The same table is often several times smaller in Parquet than in CSV, which means less storage and less data to scan.
Partitioning
Partitioning splits a table into folders by the value of a column, most often the date.
events/year=2026/month=01/day=15/part-0000.parquet
events/year=2026/month=01/day=16/part-0000.parquetA query with WHERE day = '2026-01-15' reads one folder and ignores the rest. This is called partition pruning.
Choosing the partition column
- Pick a column that queries filter on almost every time, usually an event date.
- Keep cardinality moderate. Partitioning by user id creates millions of tiny folders.
- A common rule of thumb is files of roughly 100 MB to 1 GB, though the best size depends on your engine. Thousands of tiny files make listing and opening them slower than reading the data.
import csv
def sum_column(path, name):
# A CSV reader must parse every field of every row, even though we only use one column.
with open(path, newline="") as handle:
return sum(float(row[name]) for row in csv.DictReader(handle))Takeaway
Use a columnar format with types for anything analysed repeatedly, partition by the column you filter on most, and keep files a sensible size. Keep CSV for exchange with people and for small inputs.
Comments