Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 8 min read How-to mediumAdept

Analyzing Wimbledon tennis data with chDB

Tennis scoring logic can be encoded as ClickHouse SQL user-defined functions that compute how many points each player needs to win a match, then applied to Wimbledon point-by-point data to show Alcaraz was never close to losing his five-set first-round match against Fognini. The workflow uses clickhouse-local with a persistent path for development, and chDB opens the same database in-process from Python so pytest can run parameterized tests against the UDFs, catching bugs across scoring scenarios. Matches and points are stored in MergeTree tables with tuple columns for per-player state, and a Streamlit and Plotly app visualizes proximity to victory point by point.

Related posts

  • Replacing the HDB: ClickHouse for historical ticker data

    ClickHouse mediumAdept

    ClickHouse can serve as the historical tier (HDB) of a market data system, a low-risk place to adopt a new database. Its columnar storage with dictionary, delta and run-length encodings plus ZSTD/LZ4 compresses tick data well. A worked example loads one month of Binance USD-M futures data (373M trades and about 2B quotes) with clickhouse-local, reading zipped CSVs directly. Plain SQL then handles trading-desk queries: VWAP, hourly OHLC candles and minute-level drill-downs run in tens of milliseconds, and ASOF JOIN matches each trade to the prevailing quote to measure slippage during a sell-off.

  • 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.

  • Using ClickHouse UDFs to integrate with OpenAI models

    ClickHouse mediumAdept

    ClickHouse executable user-defined functions can call the OpenAI chat completions API from SQL, adding sentiment labels or extracted entities to rows at insert or query time. The walkthrough starts with a Bash script and then moves to a Python script with retries and exponential backoff, configured as an executable_pool with chunk headers for parallel, batched invocation. Applying the UDF only to final result rows keeps API calls few, since OpenAI latency far exceeds ClickHouse query time. Aggregating sentiment across many rows means thousands of API calls, so rate limits and latency become the main constraints.

  • Trade secrets: How Coinhall uses ClickHouse to power its blockchain data platform

    ClickHouse easyNovice

    Coinhall, an omnichain trading terminal aggregating swap data from 23 blockchains, moved from BigQuery (about 2-second queries, thousands of dollars per month) to QuestDB and then to self-hosted ClickHouse. In Coinhall's comparison against Rockset, SingleStore and Snowflake, ClickHouse ran candlestick queries in 20 ms, latest-price queries in 8 ms and ASOF JOINs in 50 ms, on a 4 vCPU / 16 GB server costing about $50 a month. After migrating, the team tuned queries around sparse primary indexes and replaced full-table LIMIT BY scans with aggregating tables fed by materialized views. They also avoided or simplified sort-merge joins.

  • ClickHouse Newsletter August 2022: Airlines are maybe not that bad

    ClickHouse mediumAdept

    ClickHouse's August 2022 newsletter introduces ClickBench, a benchmark for analytical databases built on a real-world web analytics dataset, and summarizes the 22.7 release: positional arguments on by default, deprecation of the Ordinary engine, new direct and full_sorting_merge join algorithms, a MongoDB table function, additional table and result filters, and HTTP support in clickhouse-go. The query of the month cleans the OnTime flight dataset with a regex on tail numbers, then uses sequenceMatch to count planes whose delays worsen versus recover within a day. Slightly more delayed planes catch up (about 7.26M) than fall further behind (about 6.88M), though average delays have roughly doubled since the 1990s.

The quest for software engineering knowledge.

Look:
Layout: