DuckDB vs. clickhouse-local for CLI Data Munging: Architecture, Syntax, and Benchmarks
Traditional Unix text-processing utilities (awk, sed, jq, cut, sort) break down quickly when wrangling multi-gigabyte Parquet, Zstandard-compressed NDJSON, or dirty CSV files with nested schemas and complex joins. Modern embedded OLAP engines solve this directly in the terminal—specifically DuckDB (duckdb) and ClickHouse Local (clickhouse-local).
Both tools package full vectorized, columnar SQL execution engines into standalone single-file binaries that require zero server setup, zero configuration, and zero ETL ingestion steps. However, their SQL ergonomics, binary sizes, out-of-core memory strategies, and ecosystem integrations differ significantly in daily CLI workflows.
Head-to-Head Architectural Comparison
While both engines execute vectorized columnar queries directly over local and remote files, their design philosophies reflect their origins:
| Dimension | DuckDB CLI (duckdb) | ClickHouse Local (clickhouse-local) |
|---|---|---|
| Core Origin | Embedded in-process OLAP engine ("SQLite for analytics") | Standalone CLI wrapper around the ClickHouse server engine |
| Binary Size | ~45 MB – 65 MB (fast download, minimal footprint) | ~450 MB – 650 MB (full ClickHouse server binary) |
| SQL Dialect | PostgreSQL-compatible + ergonomic extensions (EXCLUDE, COLUMNS(), SELECT *) | ClickHouse SQL (MergeTree functions, arrayJoin, quantileTDigest, formatRow) |
| File & Format Support | Parquet, CSV, JSON/NDJSON, Iceberg, Delta Lake, SQLite, Postgres, MySQL | 90+ formats (Parquet, CSV, JSONEachRow, Avro, Protobuf, Cap'n Proto, ORC, Native) |
| Direct File Query Syntax | SELECT * FROM 'events.parquet' (filename as table expression) | SELECT * FROM file('events.parquet', 'Parquet') (or auto-inferred via file()) |
| Memory & Spill-to-Disk | Automatic out-of-core spilling for joins, sorts, and aggregations | Configurable max_bytes_before_external_group_by / max_bytes_before_external_sort |
| Persistent Local Storage | Single portable .duckdb file (duckdb analytics.db) | Directory-based MergeTree storage (--path ./ch_data) |
| Terminal UX & Output | Built-in duckbox tables, Markdown, JSON, CSV, interactive autocomplete | Rich terminal formatting (PrettyCompact, JSONEachRow, Vertical, Bar sparklines) |
Installing Both CLI Tools
Both tools distribute standalone statically linked binaries with no runtime dependencies:
# Install DuckDB CLI (Linux / macOS)
curl [https://install.duckdb.org](https://install.duckdb.org) | sh
# Install ClickHouse binary (provides both clickhouse-local and clickhouse local)
curl [https://clickhouse.com/](https://clickhouse.com/) | sh
sudo ./clickhouse install
Side-by-Side CLI Data Munging Recipes
To compare ergonomics on real-world data engineering tasks, consider a pipeline transforming raw compressed NDJSON application logs (logs/*.json.zst), joining against a CSV lookup table (tenants.csv), and exporting partitioned Parquet files.
1. Schema Inference & Dirty CSV Inspection
DuckDB CLI automatically detects delimiters, quotes, headers, and column types using read_csv_auto—and allows querying file paths directly without a function wrapper:
duckdb -c "
DESCRIBE SELECT * FROM 'raw_exports/orders_*.csv.gz';
"
duckdb -c "
SELECT
status,
COUNT(*) AS total_orders,
ROUND(SUM(amount), 2) AS gross_revenue
FROM 'raw_exports/orders_*.csv.gz'
WHERE created_at >= TIMESTAMP '2026-10-01'
GROUP BY ALL
ORDER BY gross_revenue DESC;
"
ClickHouse Local infers schemas automatically via the file() table function and supports fine-grained format settings (input_format_csv_skip_first_lines, schema_inference_make_columns_nullable):
clickhouse-local --query "
DESCRIBE TABLE file('raw_exports/orders_*.csv.gz');
"
clickhouse-local --query "
SELECT
status,
count() AS total_orders,
round(sum(amount), 2) AS gross_revenue
FROM file('raw_exports/orders_*.csv.gz')
WHERE created_at >= '2026-10-01 00:00:00'
GROUP BY status
ORDER BY gross_revenue DESC
FORMAT PrettyCompact;
"
2. Multi-Format Joins & Nested JSON Unnesting
DuckDB shines when combining PostgreSQL-style UNNEST, lambda list transformations, and COLUMNS() regex selectors:
duckdb -c "
COPY (
SELECT
e.event_id,
t.tenant_tier,
e.ts::TIMESTAMP AS event_time,
UNNEST(e.tags) AS tag_name,
e.metrics.latency_ms::DOUBLE AS latency_ms
FROM read_json_auto('logs/2026-11-*.ndjson.zst') AS e
LEFT JOIN 'metadata/tenants.csv' AS t
ON e.tenant_id = t.id
WHERE e.metrics.status_code >= 500
) TO 'clean/error_events.parquet' (FORMAT PARQUET, COMPRESSION ZSTD);
"
ClickHouse Local excels at high-speed semi-structured log parsing, arrayJoin, and approximate sketch aggregations (quantilesTDigest, uniqHyperLogLog) in a single pass:
clickhouse-local --query "
INSERT INTO FUNCTION file('clean/error_events.parquet', 'Parquet')
SELECT
e.event_id AS event_id,
t.tenant_tier AS tenant_tier,
parseDateTime64BestEffort(e.ts) AS event_time,
arrayJoin(e.tags) AS tag_name,
toFloat64(e.metrics.latency_ms) AS latency_ms
FROM file('logs/2026-11-*.ndjson.zst', 'JSONEachRow') AS e
LEFT JOIN file('metadata/tenants.csv', 'CSVWithNames') AS t
ON e.tenant_id = t.id
WHERE toUInt16(e.metrics.status_code) >= 500
SETTINGS output_format_parquet_compression_method = 'zstd';
"
3. Piping Unix Streams (stdin / stdout)
Both tools integrate cleanly into standard Unix pipes (curl | tool | jq), making them drop-in replacements for multi-stage awk/jq pipelines:
# DuckDB reading NDJSON from /dev/stdin and emitting JSON lines
cat events.ndjson | duckdb -json -c "
SELECT service, COUNT(*) AS failures
FROM read_json_auto('/dev/stdin')
WHERE level = 'ERROR'
GROUP BY service;
"
# ClickHouse Local reading CSV from stdin with explicit input/output formats
cat metrics.csv | clickhouse-local \
--input-format="CSVWithNames" \
--output-format="PrettyCompact" \
--query="
SELECT host, quantile(0.99)(cpu_pct) AS p99_cpu
FROM table
GROUP BY host
ORDER BY p99_cpu DESC;
"
Performance & Operational Trade-Offs on Local Workloads
When benchmarking single-machine CLI munging across 10M–500M rows (roughly 1 GB – 25 GB of Parquet/CSV data):
- Cold Startup & CI/CD Footprint:
duckdb(~50 MB binary) starts in ~15 ms, making it noticeably faster for short shell loops, GitHub Actions steps, and serverless containers where pulling a ~500 MBclickhousebinary adds image bloat. - Complex Multi-Table Joins & Window Functions: DuckDB's cost-based join optimizer and automatic hash-join disk spilling require zero tuning when joining multiple multi-gigabyte Parquet files on a 16 GB laptop.
- Wide Aggregations, Compression & Format Breadth:
clickhouse-localfrequently leads on single-table scan-and-aggregate throughput, regex/URL extraction functions, and niche wire formats (Protobuf, Avro, Cap'n Proto, MySQL dumps, MsgPack). - SQL Portability vs. Production Parity: DuckDB's PostgreSQL-flavored SQL (
GROUP BY ALL,SELECT * EXCLUDE (...),QUALIFY) requires less boilerplate for ad-hoc exploration. Conversely, if your production warehouse runs ClickHouse,clickhouse-localguarantees 100% SQL dialect and function parity (MergeTreecodecs,argMax,windowFunnel) for local CI testing.
Decision Matrix: Which CLI Tool Should You Pick?
| Scenario | Recommended Tool | Why |
|---|---|---|
| Daily ad-hoc CSV/Parquet exploration on a laptop | DuckDB CLI | Zero-boilerplate file paths ('file.parquet'), Postgres SQL ergonomics, tiny binary |
| CI/CD pipelines & Docker images | DuckDB CLI | ~50 MB binary size, ~15 ms cold start, native S3/Iceberg/Delta extensions |
| Local testing for a ClickHouse production cluster | clickhouse-local | Exact same SQL engine, types (LowCardinality, Nullable), and functions as prod |
| Converting exotic formats (Protobuf, Avro, ORC) | clickhouse-local | Unmatched built-in support for 90+ binary, text, and database dump formats |
Memory-constrained heavy joins (< 16 GB RAM) | DuckDB CLI | Out-of-the-box external disk spilling works automatically without memory flags |
Common Mistakes
- Running
clickhouse-localjoins on large files without external sort/group limits: By default, large hash aggregations can trigger anMEMORY_LIMIT_EXCEEDEDerror unless you pass--max_bytes_before_external_group_by=4000000000on memory-constrained machines. - **Using
SELECT *on wide Parquet files during CLI exploration:** Both engines push down column projections into Parquet row groups—selecting only the 3 columns you need instead of 80 columns can cut runtime by 10x. - Forgetting
GROUP BY ALLandEXCLUDEin DuckDB: Writing out 15 grouping columns manually slows down interactive terminal exploration whenGROUP BY ALLinfers non-aggregated expressions automatically.
Summary
Both DuckDB CLI and clickhouse-local eliminate the need to spin up database servers or write slow Python/Pandas scripts for command-line data munging. Choose DuckDB as your default daily driver for lightweight binaries, PostgreSQL-compatible ergonomics, and effortless multi-file joins; reach for clickhouse-local when you need 90+ specialized wire formats, domain-specific analytical functions, or exact SQL parity with a production ClickHouse cluster.