User-defined functions in ClickHouse Cloud
ClickHouse SQL user-defined functions, now available in ClickHouse Cloud, can reconstruct a file's full commit history across renames in git-import data. ClickHouse lacks recursive CTEs and UDFs cannot recurse, so the workaround chains six UDFs that each call the next. Each one looks up the file's previous path from Rename/Add rows and appends it to an array, which caps the rename depth at five. The resulting array then filters the history with `path IN file_path_history(...)`. Fixing the data at insert time with a stable file ID is noted as the cleaner alternative.
Related posts
- ClickHouse 22.11 Release
ClickHouse mediumAdept
ClickHouse 22.11 ships 15 new features, 5 performance optimisations and 32 bug fixes, headlined by composite time intervals, recursive ** glob patterns, Spark-compatibility functions, INSERT retries and SELECT support for Apache Hudi and Delta Lake. The new insert_keeper_max_retries setting lets long-running inserts survive Keeper/ZooKeeper reconnections by retrying failed blocks instead of failing the whole request, with 5 recommended for most cases. Recursive ** globs, combined with range expansion and set matching in path-accepting table functions such as s3(), allow queries to read only the relevant files. Worked examples over git-import commit data on S3 show this pruning in practice.
- ClickHouse Release 26.3
ClickHouse mediumAdept
ClickHouse 26.3 ships 27 features, 40 performance optimizations and 202 bug fixes. Headline changes are asynchronous inserts enabled by default, JOIN reordering for ANTI/SEMI/FULL joins, and MATERIALIZED CTEs, which evaluate a WITH subquery once into a temporary table. In a UK property-prices example, materializing the CTE roughly halved query time and cut peak memory from 1.5 GiB to about 88 MiB. The release also adds pretty/compact EXPLAIN output, naturalSortKey, JSONExtract support for the JSON type, and experimental WebAssembly UDFs sandboxed with Wasmtime. TTL DELETE can now use vertical merges, and the post explains how horizontal and vertical merges work and when each is chosen.
- ClickHouse Newsletter July 2023: Seeing Clearly
ClickHouse mediumAdept
ClickHouse v23.6 adds 10 features, 12 performance optimisations and 31 bug fixes. Highlights include exploiting natural sort order in almost-sorted columns that aren't in the ordering key, MongoDB integration support up to v6, and a transform function that now works with all data types. The query of the month uses the windowFunnel function on the GitHub Events dataset for a fork-to-PR funnel analysis. About 17% of ClickHouse forkers open a PR within 30 days, which ranks 22nd among repositories with more than 25k stars and 5k forks. The rest of the issue is links and upcoming meetups and trainings.
- ClickHouse and dbt - A Gift from the Community
ClickHouse mediumAdept
The dbt-clickhouse adapter, started by community contributor Dmitriy Sokolov and later taken over as a vendor-supported plugin, maps dbt's view, table, incremental and ephemeral materializations onto ClickHouse features. The default incremental strategy builds a temporary table of changed rows, copies all unchanged rows into a new table and atomically swaps it in, which duplicates the whole dataset on every run. A newer delete+insert strategy uses ClickHouse 22.8's experimental lightweight deletes (tombstones removed during merges) to write only the changed rows and performs significantly better. Its caveats: it needs the experimental setting enabled, and because it modifies the target table directly with no transaction, a failure can leave the model in an invalid state.
- Clone massive tables instantly and experiment safely in ClickHouse
ClickHouse mediumAdept
ClickHouse's `CREATE TABLE ... CLONE AS` creates a full, independent copy of a table almost instantly, without copying any data. It can do this because MergeTree data parts are immutable. Each part directory in the clone hard-links to the source's files, using POSIX hard links locally or metadata indirection on S3. Any later insert, update, delete or merge writes new parts, which gives part-level copy-on-write. Cloning time grows with part count rather than data size, the clone uses almost no extra storage until either table diverges, and shared files stay on disk until nothing references them. That makes clones safe for destructive tests, schema experiments, backfills and migrations.