agentsclimarketplace

Clickhouse hello world

Skill ComeOnOliver/skillshub/skills/jeremylongshore/claude-code-plugins-plus-skills/clickhouse-hello-world

Create your first ClickHouse table, insert data, and run analytical queries. Use when starting a new ClickHouse project, learning MergeTree basics, or testing your ClickHouse connection with real operations. Trigger: "clickhouse hello world", "first clickhouse table", "clickhouse quick start", "create clickhouse table", "clickhouse example".From its SKILL.md

Install
npx -y skills add ComeOnOliver/skillshub --skill clickhouse-hello-world

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

5.5 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it

ClickHouse Hello World

Overview

Create a MergeTree table, insert rows with JSONEachRow, and run your first analytical query -- all using the official @clickhouse/client.

Prerequisites

  • @clickhouse/client installed and connected (see clickhouse-install-auth)

Instructions

Step 1: Create a MergeTree Table

import { createClient } from '@clickhouse/client';

const client = createClient({
  url: process.env.CLICKHOUSE_HOST ?? 'http://localhost:8123',
  username: process.env.CLICKHOUSE_USER ?? 'default',
  password: process.env.CLICKHOUSE_PASSWORD ?? '',
});

await client.command({
  query: `
    CREATE TABLE IF NOT EXISTS events (
      event_id    UUID DEFAULT generateUUIDv4(),
      event_type  LowCardinality(String),
      user_id     UInt64,
      payload     String,
      created_at  DateTime DEFAULT now()
    )
    ENGINE = MergeTree()
    ORDER BY (event_type, created_at)
    PARTITION BY toYYYYMM(created_at)
    TTL created_at + INTERVAL 90 DAY
  `,
});
console.log('Table "events" created.');

Key concepts:

  • MergeTree() -- the foundational ClickHouse engine for analytics
  • ORDER BY -- defines the primary index (sort key); pick columns you filter/group on
  • PARTITION BY -- splits data into parts by month for efficient pruning
  • TTL -- automatic data expiration
  • LowCardinality(String) -- dictionary-encoded string, ideal for columns with < 10K distinct values

Step 2: Insert Data with JSONEachRow

await client.insert({
  table: 'events',
  values: [
    { event_type: 'page_view', user_id: 1001, payload: '{"url":"/home"}' },
    { event_type: 'click',     user_id: 1001, payload: '{"button":"signup"}' },
    { event_type: 'page_view', user_id: 1002, payload: '{"url":"/pricing"}' },
    { event_type: 'purchase',  user_id: 1002, payload: '{"amount":49.99}' },
    { event_type: 'page_view', user_id: 1003, payload: '{"url":"/docs"}' },
  ],
  format: 'JSONEachRow',
});
console.log('Inserted 5 events.');

Step 3: Query the Data

// Count events by type
const rs = await client.query({
  query: `
    SELECT
      event_type,
      count()          AS total,
      uniqExact(user_id) AS unique_users
    FROM events
    GROUP BY event_type
    ORDER BY total DESC
  `,
  format: 'JSONEachRow',
});

const rows = await rs.json<{
  event_type: string;
  total: string;        // ClickHouse returns numbers as strings in JSON
  unique_users: string;
}>();

for (const row of rows) {
  console.log(`${row.event_type}: ${row.total} events, ${row.unique_users} users`);
}

Expected output:

page_view: 3 events, 3 users
click: 1 events, 1 users
purchase: 1 events, 1 users

Step 4: Explore System Tables

// Check table size and row count
const stats = await client.query({
  query: `
    SELECT
      table,
      formatReadableSize(sum(bytes_on_disk)) AS disk_size,
      sum(rows) AS row_count,
      count() AS part_count
    FROM system.parts
    WHERE active AND database = currentDatabase() AND table = 'events'
    GROUP BY table
  `,
  format: 'JSONEachRow',
});
console.log('Table stats:', await stats.json());

MergeTree Engine Quick Reference

EngineUse Case
MergeTreeGeneral-purpose analytics
ReplacingMergeTreeUpserts (dedup by ORDER BY key)
SummingMergeTreeAuto-sum numeric columns on merge
AggregatingMergeTreePre-aggregated materialized views
CollapsingMergeTreeState changes / versioned rows

Common Data Types

TypeExampleNotes
UInt8/16/32/64user_id UInt64Unsigned integers
Int8/16/32/64delta Int32Signed integers
Float32/64price Float64IEEE 754
Decimal(P,S)amount Decimal(18,2)Exact decimal
Stringname StringVariable-length bytes
DateTimecreated_at DateTimeUnix timestamp (seconds)
DateTime64(3)ts DateTime64(3)Millisecond precision
UUIDid UUID128-bit UUID
Array(T)tags Array(String)Variable-length array
LowCardinality(T)status LowCardinality(String)Dictionary encoding

Error Handling

ErrorCauseSolution
Table already existsRe-running CREATEUse IF NOT EXISTS
Unknown columnTypo in column nameCheck DESCRIBE TABLE events
Type mismatchWrong data type in insertMatch types to schema
Memory limit exceededQuery too broadAdd WHERE clauses, use LIMIT

Resources

Next Steps

Proceed to clickhouse-local-dev-loop for Docker-based local development.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.