Chapter 0
Setup and a first checked result
One small question answered end to end, from a list of public files to a count you can check and rerun; then the installation, extensions and source tests the rebuilding chapters rely on.
Every chapter in this booklet runs on DuckDB 2.0.0 and reads public data where it lives. This page installs DuckDB, loads the extensions the chapters use, and runs one small query against the public sources most pipelines read in place, so a failure shows up here rather than halfway through a pipeline. Three kinds of source have no test here: Wikimedia's pageviews API, which Ch 3 reads only when it refreshes its committed copy of the counts; the Amazon review files Ch 2 streams on a cloud machine; and the files the business-workflow chapters (Ch 10 to 13) download whole in their own run.sh.
All test queries are in test_queries.sql. Each reads a small file, a file's metadata or size, a listing, a short API answer, or the first rows of a large file. None of them writes anything to disk. pipeline/run.sh runs them one at a time and writes each result, its wall time and the DuckDB version to public/data/setup/test_results.json, which the tables on this page read.
A first checked result
Before the installation details and the source tests, here is the whole workflow the book repeats, on one small question: how many yellow-cab trip records did New York's Taxi and Limousine Commission publish for January to March 2024? It takes four steps once DuckDB is installed (below).
1. Build the list of files. TLC publishes one parquet file per month over plain HTTPS, which has no directory listing, so the file names are built in SQL from the months:
SET VARIABLE urls = list_transform(range(1, 4), lambda m:
printf('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2024-%02d.parquet', m));2. Count, and know what you counted. One row in these files is one trip record a cab's meter submitted. Counting rows per file answers the question without downloading any trips: DuckDB reads the count from each file's footer.
SELECT filename, count(*) AS trips
FROM read_parquet($urls, filename = true)
GROUP BY filename ORDER BY filename;3. Check it against someone else's number. A row count is not yet a trip count. TLC publishes its own monthly figures, and they can differ from the file rows: Chapter 1 traces most recent yellow-cab gaps to records with an "unknown" rate code that the published figures leave out. Before a count goes into a sentence, decide which of the two the sentence means, and say so.
4. Save it, and make it rerunnable. Put the two statements in a file and write the result out with COPY (…) TO 'q1_2024_trips.csv'. Running duckdb -f that_file.sql then reproduces the result, and a later rerun against the same files should give the same numbers. Every chapter's pipeline is this pattern at a larger scale, with a checks.sql that stops the run when a count or a known value drifts.
There are three ways to use the book, and they need different amounts of setup:
- Read it. Every figure is drawn from small JSON files committed under
public/data/; nothing on these pages queries a database. - Recompute from the published evidence. Those JSON files, and each chapter's
out/manifest.json, are enough to check most sentences; each number on a page carries a comment naming the file and row it came from. - Rebuild from the sources. Each chapter's
pipeline/run.shreads the upstream data. That needs the installation and the source access tested on the rest of this page, and some chapters need a cloud machine or a paid API.
The rest of this page is reference: installation, extensions, credentials, and one test per data source.
Install DuckDB 2.0
Use the 2.0.0 LTS release for both the CLI and Python, so a query copied from a chapter behaves the same in either.
CLI on macOS or Linux. The install script picks the build for your platform, and DUCKDB_VERSION pins the release:
curl https://install.duckdb.org | DUCKDB_VERSION=2.0.0 sh
~/.duckdb/cli/2.0.0/duckdb --version # v2.0.0 (Cyanoptera) d54cbbe3dfThe pinned CLI goes to ~/.duckdb/cli/2.0.0/; add that folder to your PATH. Without DUCKDB_VERSION the script installs the newest release.
CLI on Windows. In PowerShell, download the pinned build and unpack it with the tar that ships with Windows:
curl.exe -LO https://install.duckdb.org/v2.0.0/duckdb-cli-windows-amd64.tar.gz
tar -xzf duckdb-cli-windows-amd64.tar.gz # one file: duckdb.exe
.\duckdb.exe --version # v2.0.0 (Cyanoptera) d54cbbe3dfMove duckdb.exe to a folder on your PATH. On an ARM machine use duckdb-cli-windows-arm64.tar.gz. The same folder holds the macOS and Linux builds (duckdb-cli-osx-universal.tar.gz, duckdb-cli-linux-amd64.tar.gz, duckdb-cli-linux-arm64.tar.gz).
Package managers. winget install DuckDB.cli on Windows and brew install duckdb on macOS install the newest release, then check it with duckdb --version. On 2026-12-03 both carried 2.0.1, and winget had no 2.0.0 package. The runner on this page accepts any 2.0.x CLI, but the results in this booklet come from 2.0.0, so use the pinned build to reproduce them.
Python.
uv add "duckdb==2.0.0" # or: pip install "duckdb==2.0.0"Load the extensions
The setup block of the test file installs and loads seven extensions: four core extensions (httpfs, spatial, ducklake, vss), json, which is built into the CLI, and two community extensions, h3 (Ch 7, Map Lab and G3) and zipfs (the FEC test below).
INSTALL httpfs; LOAD httpfs; -- https://, s3://, hf://
INSTALL spatial; LOAD spatial; -- ST_Read, geometry functions, GDAL
INSTALL json; LOAD json; -- read_json
INSTALL ducklake; LOAD ducklake; -- versioned tables (Ch 14)
INSTALL vss; LOAD vss; -- HNSW index for vector search (Ch 5)
INSTALL h3 FROM community; LOAD h3; -- H3 hexagon cells (Ch 7, Map Lab, G3)
INSTALL zipfs FROM community; LOAD zipfs; -- zip:// paths (FEC bulk files)Anonymous S3 for Overture and NOAA
Overture Maps (s3://overturemaps-us-west-2, region us-west-2) and NOAA's GHCNh archive (s3://noaa-ghcnh-pds, us-east-1) are public buckets. Read each with a secret that has empty credentials, scoped to its bucket:
CREATE OR REPLACE SECRET overture (
TYPE s3, KEY_ID '', SECRET '', REGION 'us-west-2',
SCOPE 's3://overturemaps-us-west-2');
CREATE OR REPLACE SECRET noaa (
TYPE s3, KEY_ID '', SECRET '', REGION 'us-east-1',
SCOPE 's3://noaa-ghcnh-pds');The empty KEY_ID and SECRET are deliberate. If AWS_ACCESS_KEY_ID and related variables are set in your shell, for example because they point at another S3-compatible store, DuckDB signs requests to the public bucket with those keys and AWS answers 403 InvalidAccessKeyId. An explicit empty-credential secret, scoped to the bucket, stops that.
Hugging Face token (optional)
Open Food Facts (Ch 4) is read with an hf:// path. It is public and the test query ran without a token. A token raises the rate limit for heavy reads. Keep it in the environment or a secret, never in a query or a committed file:
CREATE SECRET hf (TYPE huggingface, PROVIDER credential_chain);
-- picks up HF_TOKEN from the environment or the Hugging Face CLI cacheAgent mode
When the 2.0 CLI runs under a coding agent (it checks AI_AGENT, and stdout not being a terminal), it switches to agent mode and prints a one-line notice on startup. In agent mode:
- results print as compact Markdown tables, with column types in the header (
trips:BIGINT); - a result up to 1,000 rows and 10,000 bytes prints whole; a larger one prints its first and last rows with the count, and cells are cut at 500 characters;
- the footer gives the row count and, when the whole result was read, an order-independent hash of it (in our runs the footer appeared on results of ten rows or more, not on shorter ones);
- errors are JSON on stderr;
- a query that reads over a million rows prints an estimate line on stderr (
estimate: ~N rows read).
The manifests do not record this footer hash. Ch 1 and Ch 8 record the md5 of each output file's bytes, the value md5sum prints for the file. The other chapters, the gallery pipelines and Map Lab record bit_xor(hash(row)) over every row read back from each output file, computed in SQL and written as 16 hex digits (Ch 9 writes it as a decimal number). That hash is order-independent like the footer hash but uses a different function, so the two values do not match.
To turn it off, pass an output mode flag such as -csv or -json, which leaves agent mode off, or pass -no-agent. DUCKDB_AGENT_MODE=1 or 0 in the environment forces it either way; the flags win. Use -csv or -json only where a script needs machine-readable output.
Test queries
One query per data source. Run them from the repository root with:
bash chapters/00-setup/pipeline/run.sh # DUCKDB=/path/to/duckdb if the 2.0 CLI is not on PATHThe runner runs the setup block, then each test after the setup block in a fresh CLI call, and times each call from outside. A wall time therefore includes start-up, loading the extensions and creating the secrets; the setup block alone took 0.6 s. The 14 tests took 25.0 s in all, one after another, on 2026-12-03 with DuckDB v2.0.0 on Microsoft Windows 11 Pro 10.0.26300. This runner and most pipelines use bash, curl or the CLI's .shell command, so on Windows run them in Git Bash, as this run did (bash 5.3.15 (MINGW64)), or in WSL. Ch 1 and Ch 8 start from a Python script, run.py.
All 14 test queries passed on 2026-12-03
| DuckDB extension repositories | Every chapter | duckdb_extensions() after the setup block's INSTALL and LOAD lines | 7 loaded | 0.6 | pass |
| NYC TLC trip records | Ch 1, 8, 9; G1, G2, G8 | Parquet footers of yellow 2024-01 to 2024-03, URL list built in SQL | 2,964,624 / 3,007,526 / 3,582,628 trips | 0.8 | pass |
| TLC taxi zones | Ch 1, 9; Map Lab | misc/taxi_zone_lookup.csv, and misc/taxi_zones.zip through GDAL's /vsicurl/ | 265 lookup rows; 263 polygons | 0.9 | pass |
| NYC Open Data (Socrata API) | Ch 1 | TLC Industry Indicators (v6kb-cqej): row count and newest month, computed by the API | 560 rows; newest month 2026-10 | 1.2 | pass |
| Overture Maps places | Ch 7, 14; G3; Map Lab | release list, newest release's place files, row count of its first file from the footer | release 2026-11-18.0: 16 files; 5,627,496 places in the first | 3.1 | pass |
| Census TIGER/Line | Ch 7, 14; G3 | 2024 tract shapefile for DC (state FIPS 11), inside its zip, from the curl copy | 206 tracts | 0.6 | pass |
| ACS 5-year summary file | Ch 7 | table B01003 (total population), 2020-2024, every geography, from the curl copy | 85,382 tract rows; US population 334,922,499 | 0.6 | pass |
| Open Food Facts | Ch 4, 5 | hf://.../product-database/food.parquet metadata | 4,829,288 products | 3.9 | pass |
| FEC bulk data | Ch 6 | cm.txt inside 2026/cm26.zip, and the size of 2024/indiv24.zip (a HEAD request) | 21,145 committees; indiv24.zip 4.2 GB | 2.1 | pass |
| GH Archive | G4 | one hour, 2015-01-01 15:00 UTC | top type PushEvent, 5,815 events | 1.2 | pass |
| Hugging Face Hub metadata | G5 | api/models, top 5 by downloads | top: sentence-transformers/all-MiniLM-L6-v2 | 0.7 | pass |
| NOAA GHCNh hourly | G2 | Central Park (USW00094728) 2026 Parquet file over s3://, with the scoped empty-credential secret | 87,656 observations, 8,095 routine hourly; last 2026-11-28 | 0.9 | pass |
| Iowa Environmental Mesonet ASOS | G2 | Central Park (NYC) one-hour precipitation, routine reports, 2026-04-01 (UTC) | 24 reports, 00:51 to 23:51 UTC | 2.7 | pass |
| Wikimedia clickstream dumps | Ch 3 | English Wikipedia, October 2026: file size (a HEAD request), the first 5 rows, and the bytes downloaded to return them | 464 MB file; first 5 rows read, 35.7 MB downloaded | 5.8 | pass |
The counts show that each read works and give a reference for later runs. The known-value checks each chapter needs (for example TLC's published monthly totals) belong in that chapter's checks.sql. No test reads an S3-compatible store other than AWS, such as Tigris, because no chapter reads one.
Tested with
| Component | Version |
|---|---|
| DuckDB CLI | v2.0.0 (d54cbbe3df) |
| Platform | windows_amd64 |
| Operating system | Microsoft Windows 11 Pro 10.0.26300 |
| Shell | bash 5.3.15 (MINGW64) |
| Run date (UTC) | 2026-12-03 |
| Core extensions | ducklake 417a9117f5, httpfs 77392a7207, spatial a3dbcd1781, vss 3685131eac |
| Built-in extension | json v2.0.0 |
| Community extensions | h3 v1.5.6, zipfs v2.0.0 |
The runner uses the CLI only; the Python package is not part of this run.
TLC: URL lists instead of globs
HTTPS has no directory listing, so yellow_tripdata_*.parquet cannot be globbed. Build the list in SQL and pass the variable to read_parquet:
SET VARIABLE urls = list_transform(range(1, 4), lambda m:
printf('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2024-%02d.parquet', m));
SELECT filename, count(*) AS trips
FROM read_parquet($urls, filename = true)
GROUP BY filename ORDER BY filename;This returned 3 rows in 0.8 s. DuckDB answers the counts from each file's parquet footer, so it does not download the trip data. In 2.0 a table function accepts the $urls variable directly.
Taxi zones: the shapefile is inside a folder in the zip
SELECT count(*) AS polygons
FROM ST_Read('/vsizip//vsicurl/https://d37ci6vzurychx.cloudfront.net/misc/taxi_zones.zip/taxi_zones/taxi_zones.shp');The lookup has 265 rows and the shapefile 263 polygons; the lookup rows with no polygon are ID 264 (zone "N/A", borough "Unknown") and ID 265 (zone "Outside of NYC", borough "N/A"). Pointing ST_Read at the zip alone fails, because the .shp sits in a taxi_zones/ folder inside the archive.
On Windows the same query failed with Could not open GDAL dataset until CURL_CA_BUNDLE pointed at a CA certificate bundle that GDAL's own HTTPS client in the spatial extension could use. Git for Windows ships one at C:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt, and run.sh sets the variable to it when it is unset. A zip://https://… path, read by the zipfs extension through DuckDB's own HTTP client, worked without the variable.
NYC Open Data: a SoQL query in the URL
Ch 1 checks its counts against TLC's own monthly tables on NYC Open Data, which the Socrata API serves as CSV. The API takes a SoQL query in the URL, so it can count or filter before it sends anything:
SELECT table_rows, latest_month
FROM read_csv('https://data.cityofnewyork.us/resource/v6kb-cqej.csv?$select=count(%2A)%20AS%20table_rows,max(month_year)%20AS%20latest_month');The TLC Industry Indicators table had 560 rows, the newest for 2026-10. Write * as %2A in such a URL: DuckDB reads a * in an HTTP path as a glob and stops with an Invalid Input Error.
Overture: read the newest release
Overture keeps each release public for at most 60 days (release calendar), so a query that pins a release ID stops working. The test lists the place files of every release still in the bucket and reads the newest release; release IDs start with the date, so the largest ID is the newest:
SET VARIABLE all_place_files = (
SELECT list(file ORDER BY file)
FROM glob('s3://overturemaps-us-west-2/release/*/theme=places/type=place/*.parquet'));
SET VARIABLE releases = list_sort(list_distinct(
list_transform($all_place_files, lambda f: regexp_extract(f, 'release/([^/]+)/', 1))));
SET VARIABLE release = $releases[-1];
SET VARIABLE place_files = list_filter($all_place_files, lambda f: f LIKE '%/release/' || $release || '/%');
SELECT $release AS release, len($place_files) AS files,
(SELECT count(*) FROM read_parquet($place_files[1])) AS places_in_first_file;Census: download with curl first
On 2026-12-03 www2.census.gov answered DuckDB's own HTTP client with HTTP 403 Forbidden, while curl, and GDAL's /vsicurl/ client once it had a CA bundle, still got the same files. The runner therefore downloads the TIGER/Line and ACS files these tests read with curl into chapters/00-setup/out/census/ and reads them from disk. Do the same before running a chapter that reads Census files, or set CENSUS_ROOT=https://www2.census.gov to read in place where the site lets DuckDB through.
FEC: zipped bulk files
DuckDB reads inside the archive with the zipfs extension:
SET unsafe_disable_etag_checks = true;
SELECT count(*) FROM read_csv('zip://https://www.fec.gov/files/bulk-downloads/2026/cm26.zip/cm.txt',
delim = '|', header = false, all_varchar = true);
RESET unsafe_disable_etag_checks;Without the setting the read failed with HTTP 412 Precondition Failed: fec.gov's CDN answered DuckDB's ETag precondition on a follow-up range request with 412, and DuckDB treats that as the file having changed. The setting turns that check off for the session, so reset it afterwards. The 2026 committee file had 21,145 rows, and indiv24.zip, the 2024 individual-contribution file, is 4.2 GB. The individual-contribution files are much larger than the committee file, so Chapter 6 streams each zip through a short Python script instead of reading it in place. The test reads the size of indiv24.zip with SELECT size FROM read_blob(url), which sends one HEAD request and downloads nothing.
NOAA: GHCNh hourly Parquet
NOAA's ISD archives stopped updating in 2025, so the rain gallery piece (G2) reads their successor, GHCNh, which publishes a Parquet file per station and year:
SELECT count(*) AS observations,
count(*) FILTER (WHERE temperature_Report_Type = 'FM15') AS routine_hourly_reports,
max("DATE") AS last_observation
FROM read_parquet('s3://noaa-ghcnh-pds/hourly/access/by-year/2026/parquet/GHCNh_USW00094728_2026.parquet');For Central Park the 2026 file had 87,656 observations, 8,095 of them routine hourly reports (type FM-15), the last at 2026-11-28 17:25:00 UTC. The test reads it over s3:// with the noaa secret above. G2 reads the same object over HTTPS (https://noaa-ghcnh-pds.s3.amazonaws.com/…), which needs no secret.
G2 also checks GHCNh's wet and dry hours for April 2026 against the Iowa Environmental Mesonet's ASOS download service, which returns a CSV for a URL that names the station, the dates and the fields. Asked for Central Park on 2026-04-01 (UTC), it returned 24 routine reports, from 00:51 to 23:51.
Wikimedia clickstream: a LIMIT still downloads megabytes
Ch 3 reads Wikimedia's monthly clickstream files, one gzipped TSV per wiki and month. The test reads the first 5 rows of the English file for October 2026, then sums the bytes the GET requests returned from DuckDB's HTTP log, kept in memory:
SET VARIABLE clickstream = 'https://dumps.wikimedia.org/other/clickstream/2026-10/clickstream-enwiki-2026-10.tsv.gz';
SET logging_storage = 'memory';
SET logging_level = 'DEBUG';
CREATE TEMP TABLE first_rows AS
FROM read_csv($clickstream, delim = '\t', header = false, quote = '', escape = '', auto_detect = false,
columns = {'prev': 'VARCHAR', 'curr': 'VARCHAR', 'type': 'VARCHAR', 'n': 'BIGINT'})
LIMIT 5;
SELECT sum(TRY_CAST(response.headers['Content-Length'] AS BIGINT)) AS bytes_downloaded
FROM duckdb_logs_parsed('HTTP') WHERE request.type::VARCHAR = 'GET';To return 5 rows, DuckDB downloaded 35.7 MB of the 464 MB file (8%), in 5.8 s. DuckDB fetches a remote file in range requests of 2 MiB, and the CSV reader reads ahead of the rows a query asks for, so a LIMIT on a large compressed file is not a cheap reachability check. For that, SELECT size FROM read_blob(url) sends one HEAD request.
What to do when a test fails
- 403 on an AWS bucket: check the empty-credential secret above.
- 403 from www2.census.gov: download the file with curl first, as
run.shdoes. - HTTP 412 on fec.gov: the ETag setting above.
Could not open GDAL dataseton Windows: setCURL_CA_BUNDLEto a CA bundle file, as above.Could not open GDAL datasetelsewhere: the path inside the zip is wrong; list the archive first.- Community extension not found: it may not be built for 2.0 yet; check the extension's page at duckdb.org/community_extensions.