clickhouse

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package clickhouse projects Invariant's canonical protobuf data schema into ClickHouse column and constraint declarations. It deliberately does not choose a table engine, sorting key, partitioning, or other physical policy.

Index

Constants

View Source
const ProjectionVersion = 2

ProjectionVersion is the version of the ClickHouse-to-Iceberg projection model. It is independent of SchemaBundle's canonical IR version.

Variables

This section is empty.

Functions

func ProjectionJSON

func ProjectionJSON(projection *IcebergProjection) ([]byte, error)

ProjectionJSON returns a deterministic JSON representation of a conversion plan. Field order follows SchemaBundle order.

Types

type Column

type Column struct {
	Name              string
	Type              string
	DefaultExpression string
	Comment           string
	FieldPath         string
	StableID          int32
	Synthetic         bool
}

Column is one top-level ClickHouse column declaration.

type Constraint

type Constraint struct {
	Name       string
	Expression string
	FieldPath  string
}

Constraint is one ClickHouse CHECK constraint required by the logical schema. Callers must apply Constraints together with Columns.

type IcebergFieldProjection

type IcebergFieldProjection struct {
	FieldPath           string                   `json:"field_path"`
	Name                string                   `json:"name"`
	StableID            int32                    `json:"stable_id"`
	ClickHouseType      string                   `json:"clickhouse_type"`
	IcebergType         string                   `json:"iceberg_type"`
	PresenceExpression  string                   `json:"presence_expression"`
	ValueExpression     string                   `json:"value_expression"`
	FixedLength         uint32                   `json:"fixed_length,omitempty"`
	Discriminator       string                   `json:"discriminator,omitempty"`
	ProtobufFieldNumber uint32                   `json:"protobuf_field_number,omitempty"`
	Children            []IcebergFieldProjection `json:"children,omitempty"`
}

IcebergFieldProjection is one node in a deterministic structural conversion plan. Expressions use {value} for the current physical value and {case} for a oneof's sibling discriminator. A publisher evaluates ValueExpression only when PresenceExpression is true, then recursively applies Children.

type IcebergProjection

type IcebergProjection struct {
	Version       uint32                   `json:"version"`
	Dataset       string                   `json:"dataset"`
	SourceMessage string                   `json:"source_message"`
	Fields        []IcebergFieldProjection `json:"fields"`
}

IcebergProjection describes how a publisher reads ClickHouse values into the existing Iceberg-compatible representation. It is a conversion plan, not an ingestion runtime or a promise of ClickHouse catalog interoperability.

func ProjectToIceberg

func ProjectToIceberg(
	dataset *datav1.DatasetSchema,
) (*IcebergProjection, []*datav1.MappingDiagnostic, error)

ProjectToIceberg returns a structural conversion plan from the native ClickHouse representation to the schema emitted by data/iceberg, together with diagnostics from both target mappings. In particular, UInt64 and fixed64 use accurateCast({value}, 'Decimal(20, 0)'); every UInt64 value is exactly representable by Iceberg decimal(20,0).

type TableSchema

type TableSchema struct {
	Dataset       string
	SourceMessage string
	Description   string
	Columns       []Column
	Constraints   []Constraint
}

TableSchema is the ClickHouse projection for one canonical dataset. ColumnDeclarations returns a table-body fragment; this type does not select a database, table engine, ORDER BY key, or any other physical layout.

func Schema

Schema maps one canonical dataset to ClickHouse column declarations. Every logical field, including collection children, produces a diagnostic.

func (*TableSchema) ColumnDeclarations

func (schema *TableSchema) ColumnDeclarations() string

ColumnDeclarations returns deterministic ClickHouse column and constraint declarations without surrounding parentheses or a CREATE TABLE statement.

Jump to

Keyboard shortcuts

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