clickhouse

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package clickhouse 提供 ClickHouse 批量写入 Sink 支持批量写入、定时刷新和可选的字段映射

Index

Constants

View Source
const TypeName = "sink-clickhouse"

TypeName 组件注册名称

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClickHouse 连接配置
	CKAddress  []string `json:"ck_address"`  // ClickHouse 服务器地址列表
	CKUser     string   `json:"ck_user"`     // 用户名
	CKPassword string   `json:"ck_password"` // 密码
	CKDatabase string   `json:"ck_database"` // 数据库名

	// 目标表
	Table string `json:"table"` // 目标表名(必填)

	// 批量写入配置
	BatchSize       int `json:"batch_size"`        // 批量写入大小(默认 1000)
	FlushIntervalMs int `json:"flush_interval_ms"` // 刷新间隔毫秒(默认 1000)

	// 字段映射(可选)
	// key: Record 中的字段名, value: ClickHouse 表中的列名
	// 为空时直接使用 Record 的 key 作为列名
	FieldMapping map[string]string `json:"field_mapping"`

	// 连接调优(可选)
	DialTimeoutSec     int `json:"dial_timeout_sec"`      // 连接超时秒数(默认 60)
	MaxOpenConns       int `json:"max_open_conns"`        // 最大连接数(默认 10)
	MaxIdleConns       int `json:"max_idle_conns"`        // 最大空闲连接数(默认 5)
	ConnMaxLifetimeSec int `json:"conn_max_lifetime_sec"` // 连接最大生命周期秒数(默认 1800)
}

Config ClickHouse Sink 配置

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink ClickHouse 批量写入 Sink

func New

func New() *Sink

New 创建新的 ClickHouse Sink

func (*Sink) Close

func (s *Sink) Close() error

Close 关闭 ClickHouse 连接

func (*Sink) Consume

func (s *Sink) Consume(ctx context.Context, in <-chan types.Record) error

Consume 消费数据并批量写入 ClickHouse

func (*Sink) Count

func (s *Sink) Count() int64

Count 返回已写入的记录数

func (*Sink) Init

func (s *Sink) Init(config []byte) error

Init 初始化 Sink,解析配置并建立 ClickHouse 连接

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL