Gallery

One dataset, two layouts

120 million yellow-cab trips written as one file, as Hive year/month partitions, and with DuckDB 2.0's PARTITION_PATH and ORDER_BY, then measured by how much of each a query has to read.

Sorting, not partitioning, cut what a query reads

One recent month (August 2026)

0.02.55.07.510.012.5MB readOne file: 12.3One file12.3Hive year/month: 12.5Hive year/month12.5Archive/recent, sorted: 6.4Archive/recent, sorted6.4
Megabytes read for trips by hour in August 2026, by layout
One file12.3
Hive year/month12.5
Archive/recent, sorted6.4

One archive year (2024, four columns)

0.050.0100.0150.0200.0250.0MB readOne file: 240.8One file240.8Hive year/month: 248.0Hive year/month248.0Archive/recent, sorted: 168.4Archive/recent, sorted168.4
Megabytes read for card tips by month in 2024, by layout
One file240.8
Hive year/month248.0
Archive/recent, sorted168.4

One evening (31 Dec 2025 from 6 pm)

0.00.51.01.52.02.5MB readOne file: 1.8One file1.8Hive year/month: 2.5Hive year/month2.5Archive/recent, sorted: 0.2Archive/recent, sorted0.2
Megabytes read for trips by hour on New Year's Eve 2025 from 6 pm, by layout
One file1.8
Hive year/month2.5
Archive/recent, sorted0.2
Megabytes of compressed column data in the row groups a query cannot skip, for three queries over the same 119,594,897 trips in three layouts. Row groups are skipped when their minimum and maximum pickup times, stored in each file's footer, fall outside the query's window. The one file keeps the order of TLC's monthly files, which is already close to time order, so its statistics skip about as much as the Hive folders do. The sorted layout reads 48% less for one month and 89% less for one evening. These are counts from the footers, not timed reads.SourceNYC TLC yellow taxi trip records, January 2024 to August 2026. Files downloaded 2026-10-27.

DuckDB 2.0 added two options to COPY … (PARTITION_BY …). PARTITION_PATH takes an expression that names each partition's folder, so a layout no longer has to be year=2024/month=1/. ORDER_BY sorts the rows before they are written. The third layout here uses both: one folder per past year under archive/, one per month of 2026 under recent/, each sorted by pickup time.

One file119721,700.8
Hive: year/month32321,0121,749.0
Archive by year, recent by month, sorted10741,0121,475.8
3 rows

Sorting also made the data smaller: 1,475.8 MB against 1,700.8 MB for the single file, 13% less, because sorted timestamps compress better. Folders on their own did not cut what a query reads. For the 2024 query, the Hive layout reads 12 files and slightly more data than the single file, since each small file carries its own row-group edges. What the folders give is a way to find, copy or delete one month without reading the rest.

ORDER_BY did not produce one sorted file per partition. The writer split each archive year into many files, 26 for 2024, and sorted the rows within each file, so 26 of them overlap another file's time range. A query still skips most row groups inside each file, but it has to read every file's footer, and the number of files changed from run to run. A test that raised partitioned_write_flush_threshold, so that a year would be written in one batch, ran out of the container's temporary disk space.

Write the archive/recent layout with PARTITION_PATH and ORDER_BYgallery/g08-partition-layouts/pipeline.sqlShow SQL
pipeline.sqlSQL
-- Archive years get month bucket 0, so each year is one partition and one folder.
COPY (SELECT *, year(pickup_at) AS year,
             CASE WHEN year(pickup_at) < 2026 THEN 0 ELSE month(pickup_at) END AS bucket
      FROM a)
TO 'gallery/g08-partition-layouts/out/layouts/c_archive_recent'
    (FORMAT parquet, COMPRESSION zstd, PARTITION_BY (year, bucket),
     PARTITION_PATH CASE WHEN bucket = 0 THEN 'archive/' || year
                         ELSE 'recent/' || year || '/' || lpad(bucket::VARCHAR, 2, '0') END,
     ORDER_BY (pickup_at));

-- A reader names the folder in the path; there are no year=/month= keys to filter on.
SELECT hour(pickup_at) AS hour, count(*) AS trips
FROM read_parquet('gallery/g08-partition-layouts/out/layouts/c_archive_recent/recent/2026/08/*.parquet')
GROUP BY ALL;

Runs at build time in DuckDB 2.0; shown for reading.Open file

The pipeline downloads the 32 monthly files, drops 780 trips whose pickup falls outside their file's month, and writes the three layouts. It then reads every footer with parquet_metadata and counts, for each query, the row groups whose pickup range overlaps the query's window. It fails unless all three layouts hold the same rows and each query returns the same result on all three.

Shell
duckdb -bail :memory: -c ".read gallery/g08-partition-layouts/pipeline.sql"

Full pipeline: gallery/g08-partition-layouts/pipeline.sql. Chapter 1 writes its own working copy of the trip files with PARTITION_BY; Chapter 14 covers keeping public data files versioned.