Window and array functions for Git commit sequences
ClickHouse window and array functions can find the longest streak of consecutive commit days per author in the ClickHouse Git repository. Commits are grouped to author/day pairs. A window function with PARTITION BY author and ROWS BETWEEN 1 PRECEDING AND CURRENT ROW fetches each author's previous commit day, and dateDiff flags rows that are exactly one day apart. The flags are collected with groupArray, split on zeros with arraySplit, mapped to lengths and reduced with arrayMax to get each author's longest streak. The query runs in about 28 ms over 62K rows, and the same pattern applies to other sequence-detection problems.
Related posts
- Solving the "Impossible" in ClickHouse: Advent of Code 2025
ClickHouse mediumAdept
All 12 Advent of Code 2025 puzzles are solved in pure ClickHouse SQL, each as a single query that parses the raw input and computes both parts with no UDFs, temporary tables or preprocessing. Imperative patterns are mapped onto ClickHouse features: window functions such as sum() OVER and lagInFrame turn simulations into running totals, arrayJoin with range expands compact ranges into rows, arrayExists with lambdas detects repeating patterns, and arrayFold carries accumulator state for greedy algorithms. Every day includes the full commented CTE-chained query, showing how far ClickHouse's array and higher-order functions can stretch beyond OLAP workloads.
- 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.
- A Story of Open-source GitHub Activity using ClickHouse + Grafana
ClickHouse mediumAdept
A Grafana dashboard backed by ClickHouse analyzes the Grafana repository's ten-year history as a richer alternative to GitHub's Pulse analytics. It combines the GH Archive event dataset (5.5B+ events covering stars, issues, PRs and forks) with commit, file-change and line-level history generated by ClickHouse's git-import tool. Panels use Grafana macros such as $__timeFilter and $__timeInterval to respect dashboard time ranges, with a sample top-committers heatmap query. Findings include founder Torkel's continued heavy commit activity, alerting and Docker support as the most popular issues, and stargazers of both projects typically starring Grafana first.
- 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.
- User-defined functions in ClickHouse Cloud
ClickHouse mediumAdept
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.