clickhouse

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package clickhouse provides a ClickHouse DDL parser.

Strategy

ClickHouse DDL diverges from standard SQL primarily in two ways:

  1. Types use functional wrappers: Nullable(String), Array(Int64), Map(K,V), LowCardinality(T), Enum8('a'=1), DateTime64(3), FixedString(N), etc.
  2. Every CREATE TABLE ends with a table engine clause: ) ENGINE = MergeTree() ORDER BY id;

The SQLite parser (internal/schema/parser) already handles balanced-parenthesis type arguments (captureParenArgs) and correctly preserves e.g. VARCHAR(255) as a single column type string. This same mechanism works for ClickHouse wrapper types — the parser sees Nullable as the type name and (String) as the paren arg, resulting in the column type string "Nullable(String)".

The only pre-processing step needed is to strip the ENGINE clause (everything from ") ENGINE" onward, keeping the closing ")" of the column list) before handing the DDL to the SQLite parser.

Documented Bounds

The following ClickHouse DDL constructs are NOT parsed:

  • MATERIALIZED / ALIAS / DEFAULT column expressions (silently ignored after the type name, consistent with how other parsers handle DEFAULT).
  • SETTINGS clauses (stripped along with ENGINE).
  • PARTITION BY, PRIMARY KEY, ORDER BY, SAMPLE BY table-level clauses (stripped).
  • TTL expressions.
  • Nested(...) complex type (falls through to "any" in the type mapper).
  • COMMENT column annotations.
  • ALTER TABLE variations beyond ADD COLUMN (inherited SQLite parser behaviour).

Map(K, V) with spaces around the comma: the preprocessor normalises "Map(K, V)" → "Map(K,V)" to ensure the SQLite tokenizer emits the full type as a single unit without embedded spaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser implements diagnostic.SchemaParser for ClickHouse DDL.

func New

func New() *Parser

New creates a new ClickHouse DDL parser.

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, path string, content []byte) (*model.Catalog, []diagnostic.Diagnostic, error)

Parse parses ClickHouse DDL content and returns a catalog.

It preprocesses the input to strip ClickHouse-specific table engine clauses before delegating to the SQLite parser.

Jump to

Keyboard shortcuts

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