---
title: "Window and array functions for Git commit sequences"
description: "ClickHouse window and array functions can find the longest streak of consecutive commit days per author in the ClickHouse Git repository."
url: "https://swe.quest/articles/window-and-array-functions-for-git-commit-sequences-a4af91b5110ad48f"
canonical: "https://clickhouse.com/blog/clickhouse-window-array-functions-git-commits"
source: "ClickHouse"
published: "2022-11-16"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["sql","analytics"]
---

# Window and array functions for Git commit sequences

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-11-16, 7 min read, How-to. Original: [https://clickhouse.com/blog/clickhouse-window-array-functions-git-commits](https://clickhouse.com/blog/clickhouse-window-array-functions-git-commits)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- SQL GROUP BY and aggregates ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- basic window function concepts

## Keywords

ClickHouse, window functions, git-import, arraySplit, groupArray, arrayMap

## Related posts

- [Solving the "Impossible" in ClickHouse: Advent of Code 2025](https://swe.quest/articles/solving-the-impossible-in-clickhouse-advent-of-code-2025-a7dba91c6e7476ad.md): ClickHouse · 2025-12-31 · Medium · 42 min read · SQL, Analytics & OLAP, Algorithms
  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.
- [ClickHouse Newsletter July 2023: Seeing Clearly](https://swe.quest/articles/clickhouse-newsletter-july-2023-seeing-clearly-a153c241f5923252.md): ClickHouse · 2023-07-24 · Medium · 10 min read · Analytics & OLAP, SQL, Databases
  ClickHouse v23.6 adds 10 features, 12 performance optimisations and 31 bug fixes.
- [A Story of Open-source GitHub Activity using ClickHouse + Grafana](https://swe.quest/articles/a-story-of-open-source-github-activity-using-clickhouse-grafana-e5bfce9fb90140f3.md): ClickHouse · 2023-02-10 · Medium · 4 min read · Analytics & OLAP, Observability, SQL, Open source
  A Grafana dashboard backed by ClickHouse analyzes the Grafana repository's ten-year history as a richer alternative to GitHub's Pulse analytics.
- [ClickHouse Newsletter March 2023: Contributing to ClickHouse](https://swe.quest/articles/clickhouse-newsletter-march-2023-contributing-to-clickhouse-86808ac436001235.md): ClickHouse · 2023-03-23 · Medium · 6 min read · SQL, Analytics & OLAP
  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.
- [User-defined functions in ClickHouse Cloud](https://swe.quest/articles/user-defined-functions-in-clickhouse-cloud-33c541eadcfd2cd4.md): ClickHouse · 2022-12-08 · Medium · 6 min read · SQL, Analytics & OLAP, Version control
  ClickHouse SQL user-defined functions, now available in ClickHouse Cloud, can reconstruct a file's full commit history across renames in git-import data.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
