Using Aggregate Combinators in ClickHouse
ClickHouse aggregate combinators are suffixes appended to aggregate function names, and they can be chained, as in sumArrayIfOrNull. They change how an aggregation behaves without restructuring tables. If computes several conditional aggregates in one query, Distinct deduplicates inputs, and Resample buckets data into fixed-step groups, which arrayZip and arrayJoin can turn back into rows. OrDefault and OrNull control what empty result sets return, while Array and Map aggregate the contents of array and map columns, with worked SQL examples on sample payments and article-read tables.
Related posts
- ClickHouse Newsletter March 2023: Contributing to ClickHouse
ClickHouse mediumAdept
ClickHouse v23.2 ships 18 new features, 30 performance optimisations and 43 bug fixes, headlined by multi-stage PREWHERE, read support for Apache Iceberg v1 tables, and correlation matrix computation. The featured query counts cumulative unique contributors to ClickHouse repositories from GitHub events. A first version uses groupArrayDistinct with a window function over monthly arrays. A more concise version passes uniqState sketches from a subquery and merges them cumulatively with uniqMerge in a window, cutting runtime from 32ms to 24ms. The issue closes with a reading list and upcoming webinars and meetups.
- ClickHouse vs. Elasticsearch: The Mechanics of Count Aggregations
ClickHouse mediumAdept
ClickHouse runs count(*) GROUP BY aggregations in parallel at three levels: SIMD within column values, multiple cores over arbitrary data ranges, and multiple nodes over shards. Partial aggregation states let the results be merged exactly. Elasticsearch's terms aggregation instead uses one thread per shard and merges shard-local top-n results. That approach gives approximate counts across shards unless shard_size is raised, always requires a size limit, and is capped by max_buckets. For continuous summarization, ClickHouse's -State/-Merge combinators with AggregatingMergeTree and materialized views aggregate incrementally during background merges. Elasticsearch transforms must keep raw data and re-aggregate whole buckets on every checkpoint, so they are not real-time.
- SQL Dynamic Column Selection with ClickHouse
ClickHouse mediumAdept
ClickHouse's COLUMNS clause selects columns by regular expression, so you can aggregate over a subset of a wide table without listing every column. Using the NYC yellow taxi dataset loaded into ClickHouse Local, the walkthrough shows how APPLY runs functions or lambdas across the matched columns, including chained aggregation and rounding. REPLACE swaps individual column expressions while leaving the rest unchanged, and EXCEPT drops columns from the match. Together these clauses cut down repetitive typing in analytical SQL.
- ClickHouse release 26.10
ClickHouse mediumAdept
ClickHouse 26.10 ships 104 features, 225 performance optimizations and 739 bug fixes. Headline additions include a `|` function composition operator with `_`/`_1` placeholders, which the analyzer rewrites into ordinary lambdas, and a `written_rows` quota for capping ingestion. Also new are array and map functions such as arrayMinIndex, arrayRemoveAt, mapRemove and mapContainsKeyValue, plus an opt-in `sql_compatible_division_for_integers` setting for PostgreSQL-style truncating division. IN subqueries can now spill their sets to disk via `max_bytes_before_external_set`, so a query that fails under a 512 MiB limit can complete. The release also brings faster GROUP BY, more flexible JOIN conditions and an experimental columns cache.
- Join Types supported in ClickHouse
ClickHouse mediumAdept
ClickHouse supports all standard SQL join types plus analytics-oriented variants: INNER, LEFT/RIGHT/FULL OUTER, CROSS, LEFT/RIGHT SEMI, LEFT/RIGHT ANTI, LEFT/RIGHT/INNER ANY, and ASOF joins. Each type is illustrated with Venn diagrams and runnable queries against a normalized IMDB dataset. The examples show ClickHouse-specific behaviour: non-matching rows get default values rather than NULLs unless configured otherwise. A CROSS JOIN with a WHERE join condition is rewritten into an ALL INNER JOIN, visible via EXPLAIN SYNTAX. ANY joins disable the cartesian product and return only the first match.