clickhouse

package
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package clickhouse provides implementation of Clickhouse data warehouse

Index

Constants

View Source
const (
	// MetaOrderBy is the Arrow schema metadata key for a comma-separated list of
	// ORDER BY columns for ClickHouse table creation.
	// Example value: "toDate(timestamp), session_id"
	MetaOrderBy = "d8a.warehouse.clickhouse.order_by"

	// MetaPartitionBy is the Arrow schema metadata key for the PARTITION BY expression
	// for ClickHouse table creation.
	// Example value: "toYYYYMM(timestamp)"
	MetaPartitionBy = "d8a.warehouse.clickhouse.partition_by"
)

Metadata keys for per-table ClickHouse DDL hints stored in Arrow schema metadata. These allow callers to override the driver-level ORDER BY and PARTITION BY defaults on a per-schema basis without changing the warehouse.Driver interface.

View Source
const (
	// PrecisionMetadataKey is the metadata key used to store precision information for DateTime64 types
	PrecisionMetadataKey = "clickhouse.precision"
	// PrecisionMetadataValueSecond is the value indicating second precision for DateTime64 types
	PrecisionMetadataValueSecond = "0"
)
View Source
const ClickhouseMapperName = "clickhouse"

ClickhouseMapperName is the name of the ClickHouse type mapper

Variables

This section is empty.

Functions

func GetOrderBy added in v0.52.0

func GetOrderBy(schema *arrow.Schema) []string

GetOrderBy reads the ORDER BY columns from Arrow schema metadata. Returns nil if the key is absent or the value is empty.

func GetPartitionBy added in v0.52.0

func GetPartitionBy(schema *arrow.Schema) string

GetPartitionBy reads the PARTITION BY expression from Arrow schema metadata. Returns empty string if the key is absent.

func NewClickHouseQueryMapper

func NewClickHouseQueryMapper(opts ...Options) warehouse.QueryMapper

NewClickHouseQueryMapper creates a new ClickHouse query mapper.

func NewClickHouseTableDriver

func NewClickHouseTableDriver(
	chOptions *clickhouse.Options, database string, opts ...Options,
) (warehouse.Driver, error)

NewClickHouseTableDriver creates a new ClickHouse table driver.

func NewFieldTypeMapper

func NewFieldTypeMapper() warehouse.FieldTypeMapper[SpecificClickhouseType]

NewFieldTypeMapper creates a mapper that supports all ClickHouse types with proper circular dependency handling

func SetOrderBy added in v0.52.0

func SetOrderBy(schema *arrow.Schema, columns []string) *arrow.Schema

SetOrderBy returns a new *arrow.Schema with the ClickHouse ORDER BY hint set. The columns are joined with ", " in the DDL; pass them individually. Existing schema metadata is preserved.

func SetPartitionBy added in v0.52.0

func SetPartitionBy(schema *arrow.Schema, expr string) *arrow.Schema

SetPartitionBy returns a new *arrow.Schema with the ClickHouse PARTITION BY hint set. Existing schema metadata is preserved.

Types

type Options

type Options func(*clickhouseQueryMapper)

Options represents a configuration option for ClickHouse query mapper.

func WithEngine

func WithEngine(engine string) Options

WithEngine sets the engine type for ClickHouse tables.

func WithIndexGranularity

func WithIndexGranularity(granularity int) Options

WithIndexGranularity sets the index granularity for ClickHouse tables.

func WithOrderBy

func WithOrderBy(orderBy []string) Options

WithOrderBy sets the order by columns for ClickHouse tables.

func WithPartitionBy

func WithPartitionBy(partitionBy string) Options

WithPartitionBy sets the partition expression for ClickHouse tables.

type SpecificClickhouseType

type SpecificClickhouseType struct {
	TypeAsString         string
	ColumnModifiers      string // e.g., "DEFAULT" for nullable fields stored as NOT NULL with DEFAULT
	DefaultValue         any    // Go-level default value for this type (nil if not applicable)
	DefaultSQLExpression string // SQL expression for DEFAULT clause (e.g., "”", "0", "'1970-01-01'")
	FormatFunc           func(i any, m arrow.Metadata) (any, error)
}

SpecificClickhouseType represents a ClickHouse data type with its string representation and formatting function

func (SpecificClickhouseType) Format

func (t SpecificClickhouseType) Format(i any, m arrow.Metadata) (any, error)

Format formats a value according to the ClickHouse type's formatting function

Jump to

Keyboard shortcuts

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