← ClaudeAtlas

clickhouse-golisted

Go ClickHouse OLAP 分析专家 - 表引擎选择、查询优化、批量插入、分页查询、聚合分析、数据管理。适用:大规模数据分析(OLAP)、日志分析、用户行为分析、实时报表、时序数据存储、列式存储高压缩场景。不适用:频繁单行更新/删除的 OLTP 场景(用 PostgreSQL/MySQL)、需要事务和强一致性的业务系统、数据量小于百万行的简单查询。触发词:clickhouse, OLAP, 列式存储, MergeTree, 聚合, 批量插入, 分区, TTL, 物化视图, 宽表
omeyang/Thoth · ★ 0 · AI & Automation · score 73
Install: claude install-skill omeyang/Thoth
# Go ClickHouse 专家 使用 Go clickhouse-go 开发 ClickHouse 功能:$ARGUMENTS --- ## 1. 连接管理 ### 创建连接 ```go func NewClickHouse(ctx context.Context, dsn string) (driver.Conn, error) ``` - 解析 DSN,配置连接池(MaxOpenConns=10, MaxIdleConns=5) - 设置超时(DialTimeout=5s, ReadTimeout=30s) - 验证 Ping ### 包装器模式 ```go type ClickHouse struct { conn driver.Conn } func New(conn driver.Conn) *ClickHouse func (c *ClickHouse) Conn() driver.Conn func (c *ClickHouse) Health(ctx context.Context) error func (c *ClickHouse) Close() error ``` > 完整实现见 [references/examples.md](references/examples.md#1-连接管理) --- ## 2. 表引擎选择 | 引擎 | 适用场景 | 特点 | |------|---------|------| | MergeTree | 通用 OLAP、时序、日志 | 最常用,支持分区/TTL/索引 | | ReplacingMergeTree | 有重复数据 | 按版本号去重,查询用 FINAL | | AggregatingMergeTree | 实时统计、仪表盘 | 配合物化视图预聚合 | | SummingMergeTree | 计数器、累加统计 | 自动求和指定列 | > 完整 DDL 示例见 [references/examples.md](references/examples.md#2-表引擎选择) --- ## 3. 查询操作 ### 基本查询 ```go func (c *ClickHouse) Query(ctx context.Context, query string, args ...any) ([]map[string]any, error) ``` ### 结构体查询 ```go type Event struct { Date time.Time `ch:"event_date"` Time time.Time `ch:"event_time"` UserID uint64 `ch:"user_id"` EventType string `ch:"event_type"` } func (c *ClickHouse) QueryEvents(ctx context.Context, userID uint64, limit int) ([]Event, error) { var events []Event err := c.conn.Select(ctx, &events, ` SELECT event_date, event_time, user_id, event_type FROM events WHERE user_i