---
name: "clickhouse-aggregating-mergetree"
description: "Compute real-time rolling metrics and pre-aggregations with AggregatingMergeTree."
metadata:
  author: "ClickHouse"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create aggregatingmergetree clickhouse"
  - "setup materialized view clickhouse"
  - "use uniqstate uniqmerge"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# ClickHouse AggregatingMergeTree Materialized Views

Builds real-time analytical rollups with ClickHouse: AggregatingMergeTree engines, AggregateFunction types (uniqState, sumState), Materialized Views, and querying with uniqMerge and sumMerge.

## When to Invoke
Invoke this skill whenever you need to:
- create aggregatingmergetree clickhouse
- setup materialized view clickhouse
- use uniqstate uniqmerge

## Execution SOP & Rules
1. Define aggregate columns using AggregateFunction(uniq, UInt64) or AggregateFunction(sum, Float64).
2. Create Materialized Views with CREATE MATERIALIZED VIEW ... TO target_table AS SELECT ...
3. Populate aggregate states in views using -State suffix functions (uniqState, sumState).
4. Query combined rollup values using corresponding -Merge functions in analytical SELECTs.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
