clickhouse
ClickHouseは、大量のデータを高速に分析できるデータベースで、SQLを使って集計や事前計算を行い、イベント追跡や時系列分析、大量データの探索を効率的に行うSkill。
📜 元の英語説明(参考)
ClickHouse is a columnar OLAP database built for real-time analytical queries over massive datasets. It supports a familiar SQL interface with powerful aggregation functions, materialized views for pre-computed rollups, and high-throughput inserts that make it ideal for event tracking, time-series analytics, and ad-hoc exploration of billions of rows.
🇯🇵 日本人クリエイター向け解説
ClickHouseは、大量のデータを高速に分析できるデータベースで、SQLを使って集計や事前計算を行い、イベント追跡や時系列分析、大量データの探索を効率的に行うSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o clickhouse.zip https://jpskill.com/download/14751.zip && unzip -o clickhouse.zip && rm clickhouse.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14751.zip -OutFile "$d\clickhouse.zip"; Expand-Archive "$d\clickhouse.zip" -DestinationPath $d -Force; ri "$d\clickhouse.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
clickhouse.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
clickhouseフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
ClickHouse
ClickHouse は、オンライン分析処理向けに設計されたカラム指向データベース管理システムです。従来の行ベースのデータベースがトランザクションワークロードに優れているのに対し、ClickHouse は数十億行を数秒でスキャンして集計する必要がある場合に威力を発揮します。これは、カラム型ストレージ、ベクトル化されたクエリ実行、および積極的な圧縮によって実現されます。
このスキルでは、Docker を使用した ClickHouse のデプロイ、MergeTree エンジンファミリを使用したテーブルの作成、データの挿入、集計クエリの実行、および Node.js アプリケーションからの接続について説明します。
Docker を使用した ClickHouse のデプロイ
ClickHouse インスタンスを起動する最も速い方法は、公式の Docker イメージを使用することです。これにより、サーバーと組み込みの clickhouse-client CLI の両方が提供されます。
# docker-compose.yml — ClickHouse シングルノードデプロイメント
# HTTP インターフェースを 8123 で、ネイティブプロトコルを 9000 で公開します
docker run -d \
--name clickhouse-server \
-p 8123:8123 \
-p 9000:9000 \
-v clickhouse-data:/var/lib/clickhouse \
-v clickhouse-logs:/var/log/clickhouse-server \
clickhouse/clickhouse-server:latest
コンテナが実行されたら、ネイティブクライアントで接続します。
# CLI — 実行中の ClickHouse インスタンスに接続します
docker exec -it clickhouse-server clickhouse-client
HTTP 経由でクエリを実行することもできます。これは、簡単なヘルスチェックや軽量な統合に役立ちます。
# curl — HTTP インターフェースのクエリ例
curl 'http://localhost:8123/' --data-binary 'SELECT version()'
テーブルエンジンと MergeTree
ClickHouse はテーブルエンジンを通じてデータを編成し、MergeTree はほとんどすべてのことに使用する主力エンジンです。これは、プライマリキーインデックス、データパーティショニング、および継続的な挿入下でもクエリパフォーマンスを高く維持する自動バックグラウンドマージをサポートします。
-- DDL — MergeTree エンジンを使用して events テーブルを作成します
-- 効率的な時間範囲クエリのために月ごとにパーティション分割されます
-- 高速なフィルタリングされた集計のためにイベントタイムスタンプとユーザーで順序付けられます
CREATE TABLE events (
event_id UUID DEFAULT generateUUIDv4(),
user_id UInt64,
event_name LowCardinality(String),
properties String,
created_at DateTime DEFAULT now()
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(created_at)
ORDER BY (created_at, user_id);
ORDER BY 句はプライマリキーを定義し、データがディスク上で物理的にどのようにソートされるかを制御します。これらの列でフィルタリングまたはグループ化するクエリは、ClickHouse が一致しないデータグラニュール全体をスキップできるため、大幅に高速になります。
依然として値の境界付きセットを持つ高カーディナリティの文字列列(イベント名など)の場合、LowCardinality(String) は辞書エンコーディングを適用し、ストレージを大幅に削減し、グループ化クエリを高速化します。
重複排除のための ReplacingMergeTree
インジェストパイプラインが重複するイベントを送信する可能性がある場合、ReplacingMergeTree はバックグラウンドマージ中に同じソートキーを持つ行を折りたたみます。
-- DDL — ReplacingMergeTree を使用して重複排除されたユーザープロファイル
-- 最新の行 (updated_at による) がマージ中に優先されます
CREATE TABLE user_profiles (
user_id UInt64,
display_name String,
plan LowCardinality(String),
updated_at DateTime
) ENGINE = ReplacingMergeTree(updated_at)
ORDER BY user_id;
データの挿入
ClickHouse はバッチ挿入用に最適化されています。一度に 1 行ずつ送信すると動作しますが、リソースを浪費します。少なくとも数千行のバッチを目指してください。
-- DML — イベントレコードのバッチ挿入
INSERT INTO events (user_id, event_name, properties) VALUES
(1001, 'page_view', '{"page": "/dashboard"}'),
(1001, 'button_click', '{"button": "export"}'),
(1002, 'page_view', '{"page": "/settings"}'),
(1003, 'signup', '{}');
ファイルからの一括ロードの場合、ClickHouse は CSV、JSON、および Parquet を直接取り込むことができます。
# CLI — clickhouse-client 経由で CSV ファイルからの一括挿入
cat events.csv | docker exec -i clickhouse-server \
clickhouse-client --query="INSERT INTO events FORMAT CSVWithNames"
集計クエリ
これは、ClickHouse がその価値を発揮する場所です。数百万行にわたる集計クエリは、カラム型スキャンと SIMD アクセラレーションされた計算のおかげで、ミリ秒単位で返されます。
-- 分析 — 過去 30 日間のデイリーアクティブユーザー
SELECT
toDate(created_at) AS day,
uniqExact(user_id) AS dau
FROM events
WHERE created_at >= now() - INTERVAL 30 DAY
GROUP BY day
ORDER BY day;
-- 分析 — 今週最も使用された上位 10 個の機能
SELECT
event_name,
count() AS total,
uniq(user_id) AS unique_users
FROM events
WHERE created_at >= toMonday(now())
GROUP BY event_name
ORDER BY total DESC
LIMIT 10;
-- 分析 — リテンションコホート: 1 月にサインアップしたユーザー
-- 7 日以内に戻ってきたユーザー
SELECT
toDate(s.created_at) AS signup_date,
count(DISTINCT r.user_id) AS retained
FROM events s
INNER JOIN events r ON s.user_id = r.user_id
AND r.created_at BETWEEN s.created_at AND s.created_at + INTERVAL 7 DAY
AND r.event_name != 'signup'
WHERE s.event_name = 'signup'
AND s.created_at BETWEEN '2025-01-01' AND '2025-01-31'
GROUP BY signup_date
ORDER BY signup_date;
マテリアライズドビュー
ClickHouse のマテリアライズドビューは、挿入時にデータを変換するトリガーです。これらはソーステーブルから読み取り、集計された結果を宛先テーブルに書き込み、外部スケジューラなしで事前計算されたロールアップを提供します。
-- DDL — 1 時間ごとのイベント数用の宛先テーブル
CREATE TABLE hourly_event_counts (
hour DateTime,
event_name LowCardinality(String),
count UInt64,
unique_users UInt64
) ENGINE = SummingMergeTree()
ORDER BY (hour, event_name);
-- DDL — events テーブルへのすべての INSERT で hourly_event_counts を設定するマテリアライズドビュー
CREATE MATERIALIZED VIEW mv_hourly_events
TO hourly_event_counts
AS SELECT
toStartOfHour(created_at) AS hour,
event_name,
count() AS count,
uniq(user_id) AS unique_users
FROM events
GROUP BY hour, 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
ClickHouse
ClickHouse is a column-oriented database management system designed for online analytical processing. Where traditional row-based databases excel at transactional workloads, ClickHouse shines when you need to scan and aggregate billions of rows in seconds. It achieves this through columnar storage, vectorized query execution, and aggressive compression.
This skill walks through deploying ClickHouse with Docker, creating tables with the MergeTree engine family, inserting data, running aggregation queries, and connecting from a Node.js application.
Deploying ClickHouse with Docker
The fastest way to get a ClickHouse instance running is with the official Docker image. This gives you both the server and the built-in clickhouse-client CLI.
# docker-compose.yml — ClickHouse single-node deployment
# Exposes the HTTP interface on 8123 and the native protocol on 9000
docker run -d \
--name clickhouse-server \
-p 8123:8123 \
-p 9000:9000 \
-v clickhouse-data:/var/lib/clickhouse \
-v clickhouse-logs:/var/log/clickhouse-server \
clickhouse/clickhouse-server:latest
Once the container is running, connect with the native client:
# CLI — connect to the running ClickHouse instance
docker exec -it clickhouse-server clickhouse-client
You can also query via HTTP, which is useful for quick health checks and lightweight integrations:
# curl — HTTP interface query example
curl 'http://localhost:8123/' --data-binary 'SELECT version()'
Table Engines and MergeTree
ClickHouse organizes data through table engines, and MergeTree is the workhorse you will use for almost everything. It supports primary key indexing, data partitioning, and automatic background merges that keep query performance high even under continuous inserts.
-- DDL — create an events table using MergeTree engine
-- Partitioned by month for efficient time-range queries
-- Ordered by event timestamp and user for fast filtered aggregations
CREATE TABLE events (
event_id UUID DEFAULT generateUUIDv4(),
user_id UInt64,
event_name LowCardinality(String),
properties String,
created_at DateTime DEFAULT now()
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(created_at)
ORDER BY (created_at, user_id);
The ORDER BY clause defines the primary key and controls how data is physically sorted on disk. Queries that filter or group by these columns will be significantly faster because ClickHouse can skip entire data granules that don't match.
For high-cardinality string columns that still have a bounded set of values (like event names), LowCardinality(String) applies dictionary encoding and dramatically reduces storage and speeds up group-by queries.
ReplacingMergeTree for Deduplication
When your ingestion pipeline might send duplicate events, ReplacingMergeTree collapses rows with the same sorting key during background merges:
-- DDL — deduplicated user profiles using ReplacingMergeTree
-- The latest row (by updated_at) wins during merge
CREATE TABLE user_profiles (
user_id UInt64,
display_name String,
plan LowCardinality(String),
updated_at DateTime
) ENGINE = ReplacingMergeTree(updated_at)
ORDER BY user_id;
Inserting Data
ClickHouse is optimized for batch inserts. Sending one row at a time works but wastes resources. Aim for batches of at least a few thousand rows.
-- DML — batch insert of event records
INSERT INTO events (user_id, event_name, properties) VALUES
(1001, 'page_view', '{"page": "/dashboard"}'),
(1001, 'button_click', '{"button": "export"}'),
(1002, 'page_view', '{"page": "/settings"}'),
(1003, 'signup', '{}');
For bulk loading from files, ClickHouse can ingest CSV, JSON, and Parquet directly:
# CLI — bulk insert from a CSV file via clickhouse-client
cat events.csv | docker exec -i clickhouse-server \
clickhouse-client --query="INSERT INTO events FORMAT CSVWithNames"
Aggregation Queries
This is where ClickHouse earns its keep. Aggregation queries over millions of rows return in milliseconds thanks to columnar scanning and SIMD-accelerated computation.
-- Analytics — daily active users over the last 30 days
SELECT
toDate(created_at) AS day,
uniqExact(user_id) AS dau
FROM events
WHERE created_at >= now() - INTERVAL 30 DAY
GROUP BY day
ORDER BY day;
-- Analytics — top 10 most used features this week
SELECT
event_name,
count() AS total,
uniq(user_id) AS unique_users
FROM events
WHERE created_at >= toMonday(now())
GROUP BY event_name
ORDER BY total DESC
LIMIT 10;
-- Analytics — retention cohort: users who signed up in January
-- and returned within 7 days
SELECT
toDate(s.created_at) AS signup_date,
count(DISTINCT r.user_id) AS retained
FROM events s
INNER JOIN events r ON s.user_id = r.user_id
AND r.created_at BETWEEN s.created_at AND s.created_at + INTERVAL 7 DAY
AND r.event_name != 'signup'
WHERE s.event_name = 'signup'
AND s.created_at BETWEEN '2025-01-01' AND '2025-01-31'
GROUP BY signup_date
ORDER BY signup_date;
Materialized Views
Materialized views in ClickHouse are triggers that transform data at insert time. They read from a source table and write aggregated results into a destination table, giving you pre-computed rollups without any external scheduler.
-- DDL — destination table for hourly event counts
CREATE TABLE hourly_event_counts (
hour DateTime,
event_name LowCardinality(String),
count UInt64,
unique_users UInt64
) ENGINE = SummingMergeTree()
ORDER BY (hour, event_name);
-- DDL — materialized view that populates hourly_event_counts
-- on every INSERT into the events table
CREATE MATERIALIZED VIEW mv_hourly_events
TO hourly_event_counts
AS SELECT
toStartOfHour(created_at) AS hour,
event_name,
count() AS count,
uniq(user_id) AS unique_users
FROM events
GROUP BY hour, event_name;
Now every insert into events automatically updates the rollup. Querying hourly_event_counts is near-instant regardless of how large the raw events table grows.
Node.js Client
The official @clickhouse/client package provides a typed, streaming-capable client for Node.js applications.
// clickhouse-client.js — Node.js ClickHouse client setup and query example
// npm install @clickhouse/client
import { createClient } from '@clickhouse/client';
const client = createClient({
url: 'http://localhost:8123',
username: 'default',
password: '',
database: 'default',
});
// Insert a batch of events
async function insertEvents(events) {
await client.insert({
table: 'events',
values: events,
format: 'JSONEachRow',
});
}
// Query daily active users
async function getDailyActiveUsers(days = 30) {
const result = await client.query({
query: `
SELECT toDate(created_at) AS day, uniqExact(user_id) AS dau
FROM events
WHERE created_at >= now() - INTERVAL {days:UInt32} DAY
GROUP BY day ORDER BY day
`,
query_params: { days },
format: 'JSONEachRow',
});
return result.json();
}
// Usage
await insertEvents([
{ user_id: 1001, event_name: 'page_view', properties: '{"page":"/home"}' },
{ user_id: 1002, event_name: 'signup', properties: '{}' },
]);
const dau = await getDailyActiveUsers(7);
console.log('DAU last 7 days:', dau);
await client.close();
The client supports streaming for large result sets via result.stream(), which yields rows in chunks rather than buffering the entire response in memory. For high-throughput ingestion, keep a persistent client instance and batch your inserts on a timer or buffer threshold.