Documentation
¶
Overview ¶
Package parser provides a comprehensive participle-based parser for ClickHouse DDL statements.
This package implements a modern, robust parser using github.com/alecthomas/participle/v2 that can parse and understand all major ClickHouse Data Definition Language (DDL) statements. It provides complete support for databases, tables, dictionaries, and views with full ClickHouse syntax compatibility including advanced features like complex data types, expressions, and cluster operations.
Supported DDL Operations:
- Database operations: CREATE, ALTER, ATTACH, DETACH, DROP, RENAME DATABASE
- Table operations: CREATE, ALTER, ATTACH, DETACH, DROP, RENAME TABLE
- Dictionary operations: CREATE, ATTACH, DETACH, DROP, RENAME DICTIONARY
- View operations: CREATE, ATTACH, DETACH, DROP VIEW and MATERIALIZED VIEW
- Expression parsing: Complex expressions with proper operator precedence
- Data types: All ClickHouse types including Nullable, Array, Tuple, Map, Nested
Key features:
- Complete ClickHouse DDL syntax support with all modern features
- Advanced expression engine with proper operator precedence
- Structured error messages with line and column information
- Type-safe AST representation of all parsed statements
- Support for all engines, data types, and their parameters
- ON CLUSTER support for distributed operations
- Comprehensive test coverage with testdata-driven tests
- Maintainable grammar rules instead of complex regex patterns
Basic usage:
// Parse SQL string with comprehensive DDL support
sql, err := parser.ParseString(`
CREATE DATABASE analytics ENGINE = Atomic COMMENT 'Analytics DB';
CREATE TABLE analytics.events (
id UUID DEFAULT generateUUIDv4(),
timestamp DateTime,
user_id UInt64,
properties Map(String, String) DEFAULT map(),
metadata Nullable(String) CODEC(ZSTD(3))
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp, user_id)
TTL timestamp + INTERVAL 90 DAY;
CREATE DICTIONARY users_dict (
id UInt64 IS_OBJECT_ID,
name String INJECTIVE
) PRIMARY KEY id
SOURCE(HTTP(url 'http://api.example.com/users'))
LAYOUT(HASHED())
LIFETIME(3600);
CREATE MATERIALIZED VIEW daily_stats
ENGINE = MergeTree() ORDER BY date
POPULATE
AS SELECT toDate(timestamp) as date, count() as events
FROM analytics.events GROUP BY date;
`)
// Parse from file using io.Reader
file, err := os.Open("schema.sql")
if err != nil {
log.Fatal(err)
}
defer file.Close()
sql, err := parser.Parse(file)
The parser returns a SQL struct containing all parsed statements, which can be used for schema analysis, migration generation, validation, or any other DDL processing needs.
Index ¶
- func NormalizeDataType(dt *DataType)
- type AddColumnOperation
- type AddConstraintOperation
- type AddIndexOperation
- type AddProjectionOperation
- type AdditionExpression
- type AdditionRest
- type AlterDatabaseAction
- type AlterDatabaseStmt
- type AlterNamedCollectionOperations
- type AlterNamedCollectionStmt
- type AlterRoleStmt
- type AlterTableOperation
- type AlterTableStmt
- type AndExpression
- type AndRest
- type ArrayExpression
- type ArrayType
- type AttachDatabaseStmt
- type AttachDictionaryStmt
- type AttachPartitionFrom
- type AttachPartitionOperation
- type AttachTableStmt
- type AttachViewStmt
- type BetweenComparison
- type BetweenExpression
- type CaseExpression
- type CastExpression
- type ClearColumnOperation
- type CodecClause
- type CodecSpec
- type Column
- type ColumnAttribute
- type CommentAccessor
- type CommentColumnOperation
- type CommentStatement
- type CommonTableExpression
- type ComparisonExpression
- type ComparisonRest
- type ConstraintDefinition
- type CreateDatabaseStmt
- type CreateDictionaryStmt
- func (c *CreateDictionaryStmt) GetLayout() *DictionaryLayout
- func (c *CreateDictionaryStmt) GetLifetime() *DictionaryLifetime
- func (c *CreateDictionaryStmt) GetPrimaryKey() *DictionaryPrimaryKey
- func (c *CreateDictionaryStmt) GetSettings() *DictionarySettings
- func (c *CreateDictionaryStmt) GetSource() *DictionarySource
- type CreateFunctionStmt
- type CreateNamedCollectionStmt
- type CreateRoleStmt
- type CreateTableStmt
- func (c *CreateTableStmt) GetOrderBy() *OrderByClause
- func (c *CreateTableStmt) GetPartitionBy() *PartitionByClause
- func (c *CreateTableStmt) GetPrimaryKey() *PrimaryKeyClause
- func (c *CreateTableStmt) GetSampleBy() *SampleByClause
- func (c *CreateTableStmt) GetSettings() *TableSettingsClause
- func (c *CreateTableStmt) GetTTL() *TableTTLClause
- type CreateViewStmt
- type DataType
- type DataTypeComparable
- type DatabaseEngine
- type DatabaseEngineParam
- type DatabaseRename
- type DefaultClause
- type DeleteOperation
- type DeleteTTLOperation
- type DetachDatabaseStmt
- type DetachDictionaryStmt
- type DetachPartitionOperation
- type DetachTableStmt
- type DetachViewStmt
- type DictionaryClause
- type DictionaryColumn
- type DictionaryColumnAttr
- type DictionaryColumnDefault
- type DictionaryDSLFunc
- type DictionaryDSLParam
- type DictionaryLayout
- type DictionaryLifetime
- type DictionaryLifetimeMaxFirst
- type DictionaryLifetimeMinFirst
- type DictionaryLifetimeMinMax
- type DictionaryParameter
- type DictionaryPrimaryKey
- type DictionaryRename
- type DictionarySetting
- type DictionarySettings
- type DictionarySource
- type DropColumnOperation
- type DropConstraintOperation
- type DropDatabaseStmt
- type DropDictionaryStmt
- type DropFunctionStmt
- type DropIndexOperation
- type DropNamedCollectionStmt
- type DropPartitionOperation
- type DropProjectionOperation
- type DropRoleStmt
- type DropTableStmt
- type DropViewStmt
- type ElseClause
- type EngineParameter
- type Expression
- type ExtractExpression
- type FetchPartitionOperation
- type FrameBound
- type FreezeOperation
- type FromClause
- type FunctionArg
- type FunctionCall
- type FunctionParam
- type FunctionWithAlias
- type GrantStmt
- type GrantTarget
- type Grantee
- type GranteeList
- type GroupByClause
- type HavingClause
- type IdentifierExpr
- type InComparison
- type InExpression
- type IndexDefinition
- type IndexNGramBFType
- type IndexSetType
- type IndexTokenBFType
- type IndexType
- type InterpolateClause
- type InterpolateColumn
- type IntervalExpr
- type IsNullExpr
- type JoinClause
- type JoinCondition
- type LeadingCommentField
- type LimitBy
- type LimitClause
- type Literal
- type LowCardinalityType
- type MapType
- type ModifyColumnOperation
- type ModifyColumnRemove
- type ModifyOrderByOperation
- type ModifySampleByOperation
- type ModifySettingOperation
- type ModifyTTLOperation
- type MovePartitionOperation
- type MoveToTable
- type MultiplicationExpression
- type MultiplicationRest
- type NamedCollectionOverride
- type NamedCollectionParameter
- type NamedCollectionSetParameter
- type NamedCollectionValue
- type NestedColumn
- type NestedType
- type NotExpression
- type NullableType
- type OffsetClause
- type OrExpression
- type OrRest
- type OrderByClause
- type OrderByColumn
- type OrderByExpr
- type OverClause
- type ParametricFunction
- type ParenExpression
- type PartitionByClause
- type PrimaryExpression
- type PrimaryKeyClause
- type PrivilegeItem
- type PrivilegeList
- type ProjectionDefinition
- type ProjectionSelect
- type RemoveSampleByOperation
- type RenameColumnOperation
- type RenameDatabaseStmt
- type RenameDictionaryStmt
- type RenameTableStmt
- type ReplacePartitionOperation
- type ResetSettingOperation
- type RevokeStmt
- type RoleList
- type RoleSetting
- type RoleSettings
- type SQL
- type SampleByClause
- type SelectColumn
- type SelectOrderByClause
- type SelectStatement
- type SetDefaultRoleStmt
- type SetRoleStmt
- type SettingsAssignment
- type SettingsClause
- type SimpleComparison
- type SimpleComparisonOp
- type SimpleDSLParam
- type SimpleParameter
- type SimpleType
- type Statement
- type Subquery
- type SubqueryWithAlias
- type TTLClause
- type TTLDelete
- type TableAlias
- type TableClause
- type TableElement
- type TableEngine
- type TableFunction
- type TableNameWithAlias
- type TableRef
- type TableReference
- type TableRename
- type TableSetting
- type TableSettingsClause
- type TableSource
- type TableTTLClause
- type TopLevelSelectStatement
- type TrailingCommentField
- type TupleElement
- type TupleExpression
- type TupleType
- type TypeParameter
- type UnaryExpression
- type UpdateOperation
- type ViewEngine
- type ViewOrderBy
- type ViewPartitionBy
- type ViewPrimaryKey
- type ViewSampleBy
- type ViewTableTarget
- type WhenClause
- type WhereClause
- type WindowFrame
- type WithClause
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeDataType ¶ added in v0.1.3
func NormalizeDataType(dt *DataType)
NormalizeDataType converts ClickHouse shorthand types to their canonical forms. ClickHouse internally represents certain types differently than their shorthand:
- Decimal32(S) → Decimal(9, S)
- Decimal64(S) → Decimal(18, S)
- Decimal128(S) → Decimal(38, S)
- Decimal256(S) → Decimal(76, S)
Types ¶
type AddColumnOperation ¶
type AddColumnOperation struct {
Add string `parser:"'ADD' 'COLUMN'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Column Column `parser:"@@"`
After *string `parser:"('AFTER' @(Ident | BacktickIdent))?"`
First bool `parser:"@'FIRST'?"`
}
AddColumnOperation represents ADD COLUMN operation
type AddConstraintOperation ¶
type AddConstraintOperation struct {
Add string `parser:"'ADD' 'CONSTRAINT'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
Check string `parser:"'CHECK'"`
Expression Expression `parser:"@@"`
}
AddConstraintOperation represents ADD CONSTRAINT operation
type AddIndexOperation ¶
type AddIndexOperation struct {
Add string `parser:"'ADD' 'INDEX'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
Expression Expression `parser:"@@"`
Type string `parser:"'TYPE' @(Ident | BacktickIdent)"`
Granularity string `parser:"'GRANULARITY' @Number"`
After *string `parser:"('AFTER' @(Ident | BacktickIdent))?"`
First bool `parser:"@'FIRST'?"`
}
AddIndexOperation represents ADD INDEX operation
type AddProjectionOperation ¶
type AddProjectionOperation struct {
Add string `parser:"'ADD' 'PROJECTION'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
SelectClause ProjectionSelect `parser:"@@"`
}
AddProjectionOperation represents ADD PROJECTION operation ClickHouse syntax:
ADD PROJECTION [IF NOT EXISTS] projection_name (SELECT ...)
type AdditionExpression ¶
type AdditionExpression struct {
Multiplication *MultiplicationExpression `parser:"@@"`
Rest []AdditionRest `parser:"@@*"`
}
AdditionExpression handles addition and subtraction
func (*AdditionExpression) Equal ¶ added in v0.1.3
func (a *AdditionExpression) Equal(other *AdditionExpression) bool
Equal compares two Addition expressions
func (*AdditionExpression) String ¶
func (a *AdditionExpression) String() string
type AdditionRest ¶
type AdditionRest struct {
Op string `parser:"@('+' | '-')"`
Multiplication *MultiplicationExpression `parser:"@@"`
}
type AlterDatabaseAction ¶
type AlterDatabaseAction struct {
ModifyComment *string `parser:"'MODIFY' 'COMMENT' @String"`
}
AlterDatabaseAction represents the action to perform on the database
type AlterDatabaseStmt ¶
type AlterDatabaseStmt struct {
LeadingCommentField
Alter string `parser:"'ALTER'"`
Database string `parser:"'DATABASE'"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Action *AlterDatabaseAction `parser:"@@"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AlterDatabaseStmt represents ALTER DATABASE statements Syntax: ALTER DATABASE [db].name [ON CLUSTER cluster] MODIFY COMMENT 'Comment';
type AlterNamedCollectionOperations ¶ added in v0.1.1
type AlterNamedCollectionOperations struct {
SetParams []*NamedCollectionSetParameter `parser:"('SET' @@ (',' @@)*)?"`
DeleteParams []*string `parser:"('DELETE' @(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))*)?"`
}
AlterNamedCollectionOperations represents all operations in an ALTER NAMED COLLECTION statement
type AlterNamedCollectionStmt ¶ added in v0.1.1
type AlterNamedCollectionStmt struct {
Alter string `parser:"'ALTER'"`
Named string `parser:"'NAMED'"`
Collection string `parser:"'COLLECTION'"`
IfExists *string `parser:"(@'IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Operations *AlterNamedCollectionOperations `parser:"@@? ';'"`
}
AlterNamedCollectionStmt represents ALTER NAMED COLLECTION statements. ClickHouse syntax:
ALTER NAMED COLLECTION [IF EXISTS] collection_name [ON CLUSTER cluster] [SET key1 = value1 [OVERRIDABLE | NOT OVERRIDABLE] [, ...]] [DELETE key1, key2, ...] [SET key3 = value3 [OVERRIDABLE | NOT OVERRIDABLE] [DELETE key4]]
type AlterRoleStmt ¶ added in v0.1.2
type AlterRoleStmt struct {
LeadingCommentField
IfExists bool `parser:"'ALTER' 'ROLE' @('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
RenameTo *string `parser:"('RENAME' 'TO' @(Ident | BacktickIdent))?"`
Settings *RoleSettings `parser:"@@?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AlterRoleStmt represents ALTER ROLE statements Syntax: ALTER ROLE [IF EXISTS] name [ON CLUSTER cluster] [RENAME TO new_name] [SETTINGS ...];
type AlterTableOperation ¶
type AlterTableOperation struct {
AddColumn *AddColumnOperation `parser:"@@"`
DropColumn *DropColumnOperation `parser:"| @@"`
ModifyColumn *ModifyColumnOperation `parser:"| @@"`
RenameColumn *RenameColumnOperation `parser:"| @@"`
CommentColumn *CommentColumnOperation `parser:"| @@"`
ClearColumn *ClearColumnOperation `parser:"| @@"`
ModifyTTL *ModifyTTLOperation `parser:"| @@"`
DeleteTTL *DeleteTTLOperation `parser:"| @@"`
AddIndex *AddIndexOperation `parser:"| @@"`
DropIndex *DropIndexOperation `parser:"| @@"`
AddConstraint *AddConstraintOperation `parser:"| @@"`
DropConstraint *DropConstraintOperation `parser:"| @@"`
Update *UpdateOperation `parser:"| @@"`
Delete *DeleteOperation `parser:"| @@"`
Freeze *FreezeOperation `parser:"| @@"`
AttachPartition *AttachPartitionOperation `parser:"| @@"`
DetachPartition *DetachPartitionOperation `parser:"| @@"`
DropPartition *DropPartitionOperation `parser:"| @@"`
MovePartition *MovePartitionOperation `parser:"| @@"`
ReplacePartition *ReplacePartitionOperation `parser:"| @@"`
FetchPartition *FetchPartitionOperation `parser:"| @@"`
ModifyOrderBy *ModifyOrderByOperation `parser:"| @@"`
ModifySampleBy *ModifySampleByOperation `parser:"| @@"`
RemoveSampleBy *RemoveSampleByOperation `parser:"| @@"`
ModifySetting *ModifySettingOperation `parser:"| @@"`
ResetSetting *ResetSettingOperation `parser:"| @@"`
AddProjection *AddProjectionOperation `parser:"| @@"`
DropProjection *DropProjectionOperation `parser:"| @@"`
}
AlterTableOperation represents a single ALTER TABLE operation
type AlterTableStmt ¶
type AlterTableStmt struct {
LeadingCommentField
Alter string `parser:"'ALTER' 'TABLE'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Operations []AlterTableOperation `parser:"@@ (',' @@)*"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AlterTableStmt represents an ALTER TABLE statement. ClickHouse syntax:
ALTER TABLE [IF EXISTS] [db.]table [ON CLUSTER cluster] operation1 [, operation2, ...]
ClickHouse supports many ALTER TABLE operations including: - ADD/DROP/MODIFY/RENAME COLUMN - ADD/DROP INDEX - ADD/DROP CONSTRAINT - ADD/DROP PROJECTION - MODIFY TTL - UPDATE/DELETE data - FREEZE/ATTACH/DETACH/DROP/MOVE/REPLACE PARTITION - MODIFY ORDER BY/SAMPLE BY - MODIFY SETTING
type AndExpression ¶
type AndExpression struct {
Not *NotExpression `parser:"@@"`
Rest []AndRest `parser:"@@*"`
}
AndExpression handles AND operations
func (*AndExpression) Equal ¶ added in v0.1.3
func (a *AndExpression) Equal(other *AndExpression) bool
Equal compares two AND expressions
func (*AndExpression) String ¶
func (a *AndExpression) String() string
String returns the string representation of an AndExpression with proper AND operator placement.
type AndRest ¶
type AndRest struct {
Op string `parser:"@'AND'"`
Not *NotExpression `parser:"@@"`
}
type ArrayExpression ¶
type ArrayExpression struct {
Elements []Expression `parser:"'[' (@@ (',' @@)*)? ']'"`
}
ArrayExpression represents array literals
func (*ArrayExpression) String ¶
func (a *ArrayExpression) String() string
type ArrayType ¶
type ArrayType struct {
Array string `parser:"'Array' '('"`
Type *DataType `parser:"@@"`
Close string `parser:"')'"`
}
ArrayType represents Array(T) where T is any data type
func (*ArrayType) Equal ¶ added in v0.1.7
func (a *ArrayType) Equal(other DataTypeComparable) bool
Equal compares two ArrayType instances
type AttachDatabaseStmt ¶
type AttachDatabaseStmt struct {
LeadingCommentField
Attach string `parser:"'ATTACH'"`
Database string `parser:"'DATABASE'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
Engine *DatabaseEngine `parser:"@@?"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AttachDatabaseStmt represents ATTACH DATABASE statements Syntax: ATTACH DATABASE [IF NOT EXISTS] name [ENGINE = engine(...)] [ON CLUSTER cluster];
type AttachDictionaryStmt ¶
type AttachDictionaryStmt struct {
LeadingCommentField
IfNotExists *string `parser:"'ATTACH' 'DICTIONARY' (@'IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"((@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent))"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AttachDictionaryStmt represents ATTACH DICTIONARY statements. ClickHouse syntax:
ATTACH DICTIONARY [IF NOT EXISTS] [db.]dict_name [ON CLUSTER cluster]
type AttachPartitionFrom ¶
type AttachPartitionFrom struct {
From string `parser:"'FROM'"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Table string `parser:"@(Ident | BacktickIdent)"`
}
AttachPartitionFrom represents FROM clause in ATTACH PARTITION
type AttachPartitionOperation ¶
type AttachPartitionOperation struct {
Attach string `parser:"'ATTACH' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
From *AttachPartitionFrom `parser:"@@?"`
}
AttachPartitionOperation represents ATTACH PARTITION operation
type AttachTableStmt ¶
type AttachTableStmt struct {
LeadingCommentField
Attach string `parser:"'ATTACH' 'TABLE'"`
IfNotExists bool `parser:"('IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AttachTableStmt represents an ATTACH TABLE statement. Used for materialized views: ATTACH TABLE [db.]materialized_view_name ClickHouse syntax:
ATTACH TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
type AttachViewStmt ¶
type AttachViewStmt struct {
LeadingCommentField
Attach string `parser:"'ATTACH'"`
View string `parser:"'VIEW'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
AttachViewStmt represents an ATTACH VIEW statement (for regular views only). ClickHouse syntax:
ATTACH VIEW [IF NOT EXISTS] [db.]view_name [ON CLUSTER cluster]
type BetweenComparison ¶
type BetweenComparison struct {
Not bool `parser:"@'NOT'?"`
Between string `parser:"'BETWEEN'"`
Expr *BetweenExpression `parser:"@@"`
}
BetweenComparison handles BETWEEN and NOT BETWEEN operations
type BetweenExpression ¶
type BetweenExpression struct {
Low AdditionExpression `parser:"@@"`
And string `parser:"'AND'"`
High AdditionExpression `parser:"@@"`
}
BetweenExpression handles BETWEEN operations (part of comparison)
func (BetweenExpression) String ¶
func (b BetweenExpression) String() string
type CaseExpression ¶
type CaseExpression struct {
Case string `parser:"'CASE'"`
WhenClauses []WhenClause `parser:"@@+"`
ElseClause *ElseClause `parser:"@@?"`
End string `parser:"'END'"`
}
CaseExpression represents CASE expressions
func (*CaseExpression) Equal ¶ added in v0.1.3
func (c *CaseExpression) Equal(other *CaseExpression) bool
Equal compares two Case expressions
func (*CaseExpression) String ¶
func (c *CaseExpression) String() string
type CastExpression ¶
type CastExpression struct {
Cast string `parser:"'CAST' '('"`
Expression Expression `parser:"@@"`
As string `parser:"'AS'"`
Type DataType `parser:"@@"`
Close string `parser:"')'"`
}
CastExpression represents type casting
func (*CastExpression) String ¶
func (c *CastExpression) String() string
type ClearColumnOperation ¶
type ClearColumnOperation struct {
Clear string `parser:"'CLEAR' 'COLUMN'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
In string `parser:"'IN'"`
Partition string `parser:"'PARTITION' @(String | Ident | BacktickIdent)"`
}
ClearColumnOperation represents CLEAR COLUMN operation
type CodecClause ¶
type CodecClause struct {
Codec string `parser:"'CODEC' '('"`
Codecs []CodecSpec `parser:"@@ (',' @@)*"`
Close string `parser:"')'"`
}
CodecClause represents compression codec specification
func (*CodecClause) Equal ¶ added in v0.1.3
func (c *CodecClause) Equal(other *CodecClause) bool
Equal compares two CodecClause instances for equality
func (*CodecClause) String ¶ added in v0.1.9
func (c *CodecClause) String() string
String returns the SQL representation of a codec clause.
type CodecSpec ¶
type CodecSpec struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Parameters []TypeParameter `parser:"('(' @@ (',' @@)* ')')?"`
}
CodecSpec represents a single codec specification (e.g., ZSTD, LZ4HC(9))
type Column ¶
type Column struct {
LeadingComments []string `parser:"@(Comment | MultilineComment)*"`
Name string `parser:"@(Ident | BacktickIdent)"`
DataType *DataType `parser:"@@"`
Attributes []ColumnAttribute `parser:"@@*"`
TrailingComments []string `parser:"@(Comment | MultilineComment)*"`
}
Column represents a complete column definition in ClickHouse DDL. It includes the column name, data type, and all possible modifiers such as DEFAULT values, MATERIALIZED expressions, ALIAS definitions, compression CODECs, TTL settings, and comments.
func (*Column) GetCodec ¶
func (c *Column) GetCodec() *CodecClause
GetCodec returns the codec clause for the column, if present
func (*Column) GetComment ¶
GetComment returns the comment for the column, if present
func (*Column) GetDefault ¶
func (c *Column) GetDefault() *DefaultClause
GetDefault returns the default clause for the column, if present
type ColumnAttribute ¶
type ColumnAttribute struct {
Default *DefaultClause `parser:"@@"`
Codec *CodecClause `parser:"| @@"`
TTL *TTLClause `parser:"| @@"`
Comment *string `parser:"| ('COMMENT' @String)"`
}
ColumnAttribute represents any attribute that can appear after the data type This allows attributes to be specified in any order
type CommentAccessor ¶ added in v0.1.9
CommentAccessor is implemented by all statement types that support comments. This interface matches the format package's commentable interface.
type CommentColumnOperation ¶
type CommentColumnOperation struct {
Comment string `parser:"'COMMENT' 'COLUMN'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
Value string `parser:"@String"`
}
CommentColumnOperation represents COMMENT COLUMN operation
type CommentStatement ¶ added in v0.1.3
type CommentStatement struct {
Comment string `parser:"@(Comment | MultilineComment)"`
}
CommentStatement represents a standalone comment line (file-level comments, imports, etc.)
type CommonTableExpression ¶
type CommonTableExpression struct {
Name string `parser:"@(Ident | BacktickIdent)"`
As string `parser:"'AS'"`
Query *SelectStatement `parser:"'(' @@ ')'"`
}
CommonTableExpression represents a single CTE
type ComparisonExpression ¶
type ComparisonExpression struct {
Addition *AdditionExpression `parser:"@@"`
Rest *ComparisonRest `parser:"@@?"`
IsNull *IsNullExpr `parser:"@@?"`
}
ComparisonExpression handles comparison operations
func (*ComparisonExpression) Equal ¶ added in v0.1.3
func (c *ComparisonExpression) Equal(other *ComparisonExpression) bool
Equal compares two Comparison expressions
func (*ComparisonExpression) String ¶
func (c *ComparisonExpression) String() string
String returns the string representation of a ComparisonExpression including operators and IS NULL checks.
type ComparisonRest ¶
type ComparisonRest struct {
SimpleOp *SimpleComparison `parser:"@@"`
InOp *InComparison `parser:"| @@"`
BetweenOp *BetweenComparison `parser:"| @@"`
}
func (*ComparisonRest) Equal ¶ added in v0.1.3
func (c *ComparisonRest) Equal(other *ComparisonRest) bool
Equal compares two ComparisonRest expressions
type ConstraintDefinition ¶
type ConstraintDefinition struct {
Constraint string `parser:"'CONSTRAINT'"`
Name string `parser:"@(Ident | BacktickIdent)"`
Check string `parser:"'CHECK'"`
Expression Expression `parser:"@@"`
}
ConstraintDefinition represents a CONSTRAINT definition within CREATE TABLE ClickHouse syntax:
CONSTRAINT constraint_name CHECK expression
type CreateDatabaseStmt ¶
type CreateDatabaseStmt struct {
LeadingCommentField
Create string `parser:"'CREATE'"`
Database string `parser:"'DATABASE'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Engine *DatabaseEngine `parser:"@@?"`
Comment *string `parser:"('COMMENT' @String)?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
CreateDatabaseStmt represents CREATE DATABASE statements Syntax: CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster] [ENGINE = engine(...)] [COMMENT 'Comment'];
type CreateDictionaryStmt ¶
type CreateDictionaryStmt struct {
LeadingCommentField
Create string `parser:"'CREATE'"`
OrReplace bool `parser:"@('OR' 'REPLACE')?"`
Dictionary string `parser:"'DICTIONARY'"`
IfNotExists *string `parser:"(@'IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"((@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent))"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Columns []*DictionaryColumn `parser:"'(' @@* ')'"`
Clauses []DictionaryClause `parser:"@@*"`
Comment *string `parser:"('COMMENT' @String)?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
CreateDictionaryStmt represents CREATE [OR REPLACE] DICTIONARY statements. ClickHouse syntax:
CREATE [OR REPLACE] DICTIONARY [IF NOT EXISTS] [db.]dict_name [ON CLUSTER cluster] ( column1 Type1 [DEFAULT|EXPRESSION expr] [IS_OBJECT_ID|HIERARCHICAL|INJECTIVE], column2 Type2 [DEFAULT|EXPRESSION expr] [IS_OBJECT_ID|HIERARCHICAL|INJECTIVE], ... ) PRIMARY KEY key1 [, key2, ...] SOURCE(source_type(param1 value1 [param2 value2 ...])) LAYOUT(layout_type[(param1 value1 [param2 value2 ...])]) LIFETIME([MIN min_val MAX max_val] | single_val) [SETTINGS(setting1 = value1 [, setting2 = value2, ...])] [COMMENT 'comment']
func (*CreateDictionaryStmt) GetLayout ¶
func (c *CreateDictionaryStmt) GetLayout() *DictionaryLayout
GetLayout returns the LAYOUT clause if present
func (*CreateDictionaryStmt) GetLifetime ¶
func (c *CreateDictionaryStmt) GetLifetime() *DictionaryLifetime
GetLifetime returns the LIFETIME clause if present
func (*CreateDictionaryStmt) GetPrimaryKey ¶
func (c *CreateDictionaryStmt) GetPrimaryKey() *DictionaryPrimaryKey
GetPrimaryKey returns the PRIMARY KEY clause if present
func (*CreateDictionaryStmt) GetSettings ¶
func (c *CreateDictionaryStmt) GetSettings() *DictionarySettings
GetSettings returns the SETTINGS clause if present
func (*CreateDictionaryStmt) GetSource ¶
func (c *CreateDictionaryStmt) GetSource() *DictionarySource
GetSource returns the SOURCE clause if present
type CreateFunctionStmt ¶ added in v0.1.2
type CreateFunctionStmt struct {
LeadingCommentField
Name string `parser:"'CREATE' 'FUNCTION' @(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Parameters []*FunctionParam `parser:"'AS' ( '(' (@@ (',' @@)*)? ')' | @@ )"`
Expression *Expression `parser:"'->' @@"`
TrailingCommentField
Semicolon bool `parser:"';'?"`
}
CreateFunctionStmt represents CREATE FUNCTION statements Syntax: CREATE FUNCTION name [ON CLUSTER cluster] AS (parameter0, ...) -> expression;
or: CREATE FUNCTION name [ON CLUSTER cluster] AS parameter -> expression;
type CreateNamedCollectionStmt ¶ added in v0.1.1
type CreateNamedCollectionStmt struct {
Create string `parser:"'CREATE'"`
OrReplace bool `parser:"@('OR' 'REPLACE')?"`
Named string `parser:"'NAMED'"`
Collection string `parser:"'COLLECTION'"`
IfNotExists *string `parser:"(@'IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
As string `parser:"'AS'"`
Parameters []*NamedCollectionParameter `parser:"@@*"`
GlobalOverride *NamedCollectionOverride `parser:"@@?"`
Comment *string `parser:"('COMMENT' @String)? ';'"`
}
CreateNamedCollectionStmt represents CREATE [OR REPLACE] NAMED COLLECTION statements. ClickHouse syntax:
CREATE [OR REPLACE] NAMED COLLECTION [IF NOT EXISTS] collection_name [ON CLUSTER cluster] AS key1 = value1 [OVERRIDABLE | NOT OVERRIDABLE], key2 = value2 [OVERRIDABLE | NOT OVERRIDABLE], ... [COMMENT 'comment']
type CreateRoleStmt ¶ added in v0.1.2
type CreateRoleStmt struct {
LeadingCommentField
OrReplace bool `parser:"'CREATE' (@'OR' 'REPLACE')? 'ROLE'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Settings *RoleSettings `parser:"@@?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
CreateRoleStmt represents CREATE ROLE statements Syntax: CREATE ROLE [IF NOT EXISTS | OR REPLACE] name [ON CLUSTER cluster] [SETTINGS ...];
type CreateTableStmt ¶
type CreateTableStmt struct {
LeadingCommentField
Create string `parser:"'CREATE'"`
OrReplace bool `parser:"@('OR' 'REPLACE')?"`
Table string `parser:"'TABLE'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
AsTable *TableSource `parser:"('AS' @@)?"`
Elements []TableElement `parser:"('(' @@ (',' @@)* ')')?"`
PreEngineComments []string `parser:"@(Comment | MultilineComment)*"`
Engine *TableEngine `parser:"@@"`
Clauses []TableClause `parser:"@@*"`
Comment *string `parser:"('COMMENT' @String)?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
CreateTableStmt represents a CREATE TABLE statement with full ClickHouse syntax support. ClickHouse syntax:
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster] [AS [db.]existing_table] -- Copy schema from existing table [( column1 Type1 [DEFAULT|MATERIALIZED|EPHEMERAL|ALIAS expr1] [CODEC(codec1)] [TTL expr1] [COMMENT 'comment'], column2 Type2 [DEFAULT|MATERIALIZED|EPHEMERAL|ALIAS expr2] [CODEC(codec2)] [TTL expr2] [COMMENT 'comment'], ... [INDEX index_name expression TYPE index_type GRANULARITY value], [CONSTRAINT constraint_name CHECK expression], ... )] ENGINE = engine_name([parameters]) [ORDER BY expression] [PARTITION BY expression] [PRIMARY KEY expression] [SAMPLE BY expression] [TTL expression] [SETTINGS name=value, ...] [COMMENT 'comment']
func (*CreateTableStmt) GetOrderBy ¶
func (c *CreateTableStmt) GetOrderBy() *OrderByClause
GetOrderBy returns the ORDER BY clause if present
func (*CreateTableStmt) GetPartitionBy ¶
func (c *CreateTableStmt) GetPartitionBy() *PartitionByClause
GetPartitionBy returns the PARTITION BY clause if present
func (*CreateTableStmt) GetPrimaryKey ¶
func (c *CreateTableStmt) GetPrimaryKey() *PrimaryKeyClause
GetPrimaryKey returns the PRIMARY KEY clause if present
func (*CreateTableStmt) GetSampleBy ¶
func (c *CreateTableStmt) GetSampleBy() *SampleByClause
GetSampleBy returns the SAMPLE BY clause if present
func (*CreateTableStmt) GetSettings ¶
func (c *CreateTableStmt) GetSettings() *TableSettingsClause
GetSettings returns the SETTINGS clause if present
func (*CreateTableStmt) GetTTL ¶
func (c *CreateTableStmt) GetTTL() *TableTTLClause
GetTTL returns the TTL clause if present
type CreateViewStmt ¶
type CreateViewStmt struct {
LeadingCommentField
Create string `parser:"'CREATE'"`
OrReplace bool `parser:"@('OR' 'REPLACE')?"`
Materialized bool `parser:"@'MATERIALIZED'?"`
View string `parser:"'VIEW'"`
IfNotExists bool `parser:"@('IF' 'NOT' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
To *ViewTableTarget `parser:"('TO' @@)?"`
Engine *ViewEngine `parser:"@@?"`
Populate bool `parser:"@'POPULATE'?"`
AsSelect *SelectStatement `parser:"'AS' @@"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
CreateViewStmt represents a CREATE VIEW statement. Supports both regular views and materialized views. ClickHouse syntax:
CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS] [db.]view_name [ON CLUSTER cluster] [TO [db.]table_name] [ENGINE = engine] [POPULATE] AS SELECT ...
type DataType ¶
type DataType struct {
// Nullable wrapper (e.g., Nullable(String))
Nullable *NullableType `parser:"@@"`
// Array types (e.g., Array(String))
Array *ArrayType `parser:"| @@"`
// Tuple types (e.g., Tuple(name String, age UInt8))
Tuple *TupleType `parser:"| @@"`
// Nested types (e.g., Nested(id UInt32, name String))
Nested *NestedType `parser:"| @@"`
// Map types (e.g., Map(String, UInt32))
Map *MapType `parser:"| @@"`
// LowCardinality wrapper (e.g., LowCardinality(String))
LowCardinality *LowCardinalityType `parser:"| @@"`
// Simple or parametric types (e.g., String, FixedString(10), Decimal(10,2))
Simple *SimpleType `parser:"| @@"`
}
DataType represents any ClickHouse data type including primitives, parametric types, and complex types like arrays, tuples, and nested structures.
type DataTypeComparable ¶ added in v0.1.7
type DataTypeComparable interface {
Equal(other DataTypeComparable) bool
TypeName() string
}
DataTypeComparable represents a data type that can be compared for equality.
This interface allows each concrete data type to implement its own comparison logic, including special handling for ClickHouse normalization patterns.
type DatabaseEngine ¶
type DatabaseEngine struct {
Name string `parser:"'ENGINE' '=' @(Ident | BacktickIdent)"`
Parameters []*DatabaseEngineParam `parser:"('(' @@ (',' @@)* ')')?"`
}
DatabaseEngine represents ENGINE = clause for databases
func (*DatabaseEngine) String ¶ added in v0.1.9
func (e *DatabaseEngine) String() string
String returns the SQL representation of a database engine.
type DatabaseEngineParam ¶
type DatabaseEngineParam struct {
Value string `parser:"@(String | Number | Ident | BacktickIdent)"`
}
DatabaseEngineParam represents parameters in ENGINE clause - can be strings, numbers, or identifiers
type DatabaseRename ¶
type DatabaseRename struct {
From string `parser:"@(Ident | BacktickIdent)"`
To string `parser:"'TO' @(Ident | BacktickIdent)"`
}
DatabaseRename represents a single database rename operation
type DefaultClause ¶
type DefaultClause struct {
Type string `parser:"@('DEFAULT' | 'MATERIALIZED' | 'EPHEMERAL' | 'ALIAS')"`
Expression Expression `parser:"@@"`
}
DefaultClause represents DEFAULT, MATERIALIZED, EPHEMERAL, or ALIAS expressions
func (*DefaultClause) Equal ¶ added in v0.1.3
func (d *DefaultClause) Equal(other *DefaultClause) bool
Equal compares two DefaultClause instances for equality
type DeleteOperation ¶
type DeleteOperation struct {
Delete string `parser:"'DELETE'"`
Where Expression `parser:"'WHERE' @@"`
}
DeleteOperation represents DELETE operation
type DeleteTTLOperation ¶
type DeleteTTLOperation struct {
Delete string `parser:"'DELETE' 'TTL'"`
}
DeleteTTLOperation represents DELETE TTL operation
type DetachDatabaseStmt ¶
type DetachDatabaseStmt struct {
LeadingCommentField
Detach string `parser:"'DETACH'"`
Database string `parser:"'DATABASE'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Permanently bool `parser:"@'PERMANENTLY'?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DetachDatabaseStmt represents DETACH DATABASE statements Syntax: DETACH DATABASE [IF EXISTS] [db.]name [ON CLUSTER cluster] [PERMANENTLY] [SYNC];
type DetachDictionaryStmt ¶
type DetachDictionaryStmt struct {
LeadingCommentField
IfExists *string `parser:"'DETACH' 'DICTIONARY' (@'IF' 'EXISTS')?"`
Database *string `parser:"((@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent))"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Permanently *string `parser:"(@'PERMANENTLY')?"`
Sync *string `parser:"(@'SYNC')?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DetachDictionaryStmt represents DETACH DICTIONARY statements. ClickHouse syntax:
DETACH DICTIONARY [IF EXISTS] [db.]dict_name [ON CLUSTER cluster] [PERMANENTLY] [SYNC]
type DetachPartitionOperation ¶
type DetachPartitionOperation struct {
Detach string `parser:"'DETACH' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
}
DetachPartitionOperation represents DETACH PARTITION operation
type DetachTableStmt ¶
type DetachTableStmt struct {
LeadingCommentField
Detach string `parser:"'DETACH' 'TABLE'"`
IfExists bool `parser:"('IF' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Permanently bool `parser:"@'PERMANENTLY'?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DetachTableStmt represents a DETACH TABLE statement. Used for materialized views: DETACH TABLE [db.]materialized_view_name ClickHouse syntax:
DETACH TABLE [IF EXISTS] [db.]table_name [ON CLUSTER cluster] [PERMANENTLY] [SYNC]
type DetachViewStmt ¶
type DetachViewStmt struct {
LeadingCommentField
Detach string `parser:"'DETACH'"`
View string `parser:"'VIEW'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Permanently bool `parser:"@'PERMANENTLY'?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DetachViewStmt represents a DETACH VIEW statement (for regular views only). ClickHouse syntax:
DETACH VIEW [IF EXISTS] [db.]view_name [ON CLUSTER cluster] [PERMANENTLY] [SYNC]
type DictionaryClause ¶
type DictionaryClause struct {
PrimaryKey *DictionaryPrimaryKey `parser:"@@"`
Source *DictionarySource `parser:"| @@"`
Layout *DictionaryLayout `parser:"| @@"`
Lifetime *DictionaryLifetime `parser:"| @@"`
Settings *DictionarySettings `parser:"| @@"`
}
DictionaryClause represents any clause that can appear after columns in a CREATE DICTIONARY statement This allows clauses to be specified in any order
type DictionaryColumn ¶
type DictionaryColumn struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Type string `parser:"@(Ident | BacktickIdent)"`
Default *DictionaryColumnDefault `parser:"@@?"`
Attributes []*DictionaryColumnAttr `parser:"@@*"`
Comma *string `parser:"@','?"`
}
DictionaryColumn represents a column definition in dictionary
type DictionaryColumnAttr ¶
type DictionaryColumnAttr struct {
Name string `parser:"@('IS_OBJECT_ID' | 'HIERARCHICAL' | 'INJECTIVE')"`
}
DictionaryColumnAttr represents column attributes like IS_OBJECT_ID, HIERARCHICAL, INJECTIVE
type DictionaryColumnDefault ¶
type DictionaryColumnDefault struct {
Type string `parser:"(@'DEFAULT' | @'EXPRESSION')"`
Expression Expression `parser:"@@"`
}
DictionaryColumnDefault represents DEFAULT or EXPRESSION clause Supports both simple values and function calls like now()
func (*DictionaryColumnDefault) GetValue ¶
func (d *DictionaryColumnDefault) GetValue() string
GetValue returns the string representation of the default value
type DictionaryDSLFunc ¶
type DictionaryDSLFunc struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Params []*DictionaryDSLParam `parser:"'(' @@* ')'"`
}
DictionaryDSLFunc represents DSL functions in SOURCE parameters Supports any function name including: credentials, header, headers, HTTP, MySQL, etc.
func (*DictionaryDSLFunc) String ¶
func (d *DictionaryDSLFunc) String() string
String returns the string representation of a DictionaryDSLFunc
type DictionaryDSLParam ¶
type DictionaryDSLParam struct {
SimpleParam *SimpleDSLParam `parser:"(@@ ','?)"`
NestedFunc *DictionaryDSLFunc `parser:"| (@@ ','?)"`
}
DictionaryDSLParam represents parameters in DSL functions Supports simple name-value pairs and nested function calls
type DictionaryLayout ¶
type DictionaryLayout struct {
Name string `parser:"'LAYOUT' '(' @(Ident | BacktickIdent)"`
Parameters []*DictionaryParameter `parser:"('(' @@* ')')? ')'"`
}
DictionaryLayout represents LAYOUT clause
type DictionaryLifetime ¶
type DictionaryLifetime struct {
MinMax *DictionaryLifetimeMinMax `parser:"'LIFETIME' '(' (@@"`
Single *string `parser:"| @Number) ')'"`
}
DictionaryLifetime represents LIFETIME clause
type DictionaryLifetimeMaxFirst ¶
type DictionaryLifetimeMaxFirst struct {
MaxValue string `parser:"'MAX' @Number"`
MinValue string `parser:"'MIN' @Number"`
}
DictionaryLifetimeMaxFirst represents MAX value followed by MIN value
type DictionaryLifetimeMinFirst ¶
type DictionaryLifetimeMinFirst struct {
MinValue string `parser:"'MIN' @Number"`
MaxValue string `parser:"'MAX' @Number"`
}
DictionaryLifetimeMinFirst represents MIN value followed by MAX value
type DictionaryLifetimeMinMax ¶
type DictionaryLifetimeMinMax struct {
MinFirst *DictionaryLifetimeMinFirst `parser:"@@"`
MaxFirst *DictionaryLifetimeMaxFirst `parser:"| @@"`
}
DictionaryLifetimeMinMax represents MIN/MAX lifetime values in flexible order
type DictionaryParameter ¶
type DictionaryParameter struct {
DSLFunction *DictionaryDSLFunc `parser:"(@@ ','?)"`
SimpleParam *SimpleParameter `parser:"| (@@ ','?)"`
}
DictionaryParameter represents parameters in SOURCE or LAYOUT
func (*DictionaryParameter) GetName ¶
func (p *DictionaryParameter) GetName() string
GetName returns the parameter name
func (*DictionaryParameter) GetValue ¶
func (p *DictionaryParameter) GetValue() string
GetValue returns the string representation of the parameter value
type DictionaryPrimaryKey ¶
type DictionaryPrimaryKey struct {
Keys []string `parser:"'PRIMARY' 'KEY' @(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))*"`
}
DictionaryPrimaryKey represents PRIMARY KEY clause
type DictionaryRename ¶
type DictionaryRename struct {
FromDatabase *string `parser:"((@(Ident | BacktickIdent) '.')?"`
FromName string `parser:"@(Ident | BacktickIdent))"`
ToDatabase *string `parser:"'TO' ((@(Ident | BacktickIdent) '.')?"`
ToName string `parser:"@(Ident | BacktickIdent))"`
}
DictionaryRename represents a single dictionary rename operation
type DictionarySetting ¶
type DictionarySetting struct {
Name string `parser:"@(Ident | BacktickIdent) '='"`
Value string `parser:"@(String | Number | Ident | BacktickIdent)"`
Comma *string `parser:"@','?"`
}
DictionarySetting represents individual setting
type DictionarySettings ¶
type DictionarySettings struct {
Settings []*DictionarySetting `parser:"'SETTINGS' '(' @@* ')'"`
}
DictionarySettings represents SETTINGS clause
type DictionarySource ¶
type DictionarySource struct {
Name string `parser:"'SOURCE' '(' @(Ident | BacktickIdent)"`
Parameters []*DictionaryParameter `parser:"('(' @@* ')')? ')'"`
}
DictionarySource represents SOURCE clause
type DropColumnOperation ¶
type DropColumnOperation struct {
Drop string `parser:"'DROP' 'COLUMN'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
DropColumnOperation represents DROP COLUMN operation
type DropConstraintOperation ¶
type DropConstraintOperation struct {
Drop string `parser:"'DROP' 'CONSTRAINT'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
DropConstraintOperation represents DROP CONSTRAINT operation
type DropDatabaseStmt ¶
type DropDatabaseStmt struct {
LeadingCommentField
Drop string `parser:"'DROP'"`
Database string `parser:"'DATABASE'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropDatabaseStmt represents DROP DATABASE statements Syntax: DROP DATABASE [IF EXISTS] db [ON CLUSTER cluster] [SYNC];
type DropDictionaryStmt ¶
type DropDictionaryStmt struct {
LeadingCommentField
IfExists *string `parser:"'DROP' 'DICTIONARY' (@'IF' 'EXISTS')?"`
Database *string `parser:"((@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent))"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Sync *string `parser:"(@'SYNC')?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropDictionaryStmt represents DROP DICTIONARY statements. ClickHouse syntax:
DROP DICTIONARY [IF EXISTS] [db.]dict_name [ON CLUSTER cluster] [SYNC]
type DropFunctionStmt ¶ added in v0.1.2
type DropFunctionStmt struct {
LeadingCommentField
IfExists bool `parser:"'DROP' 'FUNCTION' @('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropFunctionStmt represents DROP FUNCTION statements Syntax: DROP FUNCTION [IF EXISTS] name [ON CLUSTER cluster];
type DropIndexOperation ¶
type DropIndexOperation struct {
Drop string `parser:"'DROP' 'INDEX'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
DropIndexOperation represents DROP INDEX operation
type DropNamedCollectionStmt ¶ added in v0.1.1
type DropNamedCollectionStmt struct {
Drop string `parser:"'DROP'"`
Named string `parser:"'NAMED'"`
Collection string `parser:"'COLLECTION'"`
IfExists *string `parser:"(@'IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Semicolon string `parser:"';'"`
}
DropNamedCollectionStmt represents DROP NAMED COLLECTION statements. ClickHouse syntax:
DROP NAMED COLLECTION [IF EXISTS] collection_name [ON CLUSTER cluster]
type DropPartitionOperation ¶
type DropPartitionOperation struct {
Drop string `parser:"'DROP' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
}
DropPartitionOperation represents DROP PARTITION operation
type DropProjectionOperation ¶
type DropProjectionOperation struct {
Drop string `parser:"'DROP' 'PROJECTION'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
DropProjectionOperation represents DROP PROJECTION operation ClickHouse syntax:
DROP PROJECTION [IF EXISTS] projection_name
type DropRoleStmt ¶ added in v0.1.2
type DropRoleStmt struct {
LeadingCommentField
IfExists bool `parser:"'DROP' 'ROLE' @('IF' 'EXISTS')?"`
Names []string `parser:"@(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))*"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropRoleStmt represents DROP ROLE statements Syntax: DROP ROLE [IF EXISTS] name [,...] [ON CLUSTER cluster];
type DropTableStmt ¶
type DropTableStmt struct {
LeadingCommentField
Drop string `parser:"'DROP' 'TABLE'"`
IfExists bool `parser:"('IF' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropTableStmt represents a DROP TABLE statement. Used for materialized views: DROP TABLE [db.]materialized_view_name ClickHouse syntax:
DROP TABLE [IF EXISTS] [db.]table_name [ON CLUSTER cluster] [SYNC]
type DropViewStmt ¶
type DropViewStmt struct {
LeadingCommentField
Drop string `parser:"'DROP'"`
View string `parser:"'VIEW'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
Sync bool `parser:"@'SYNC'?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
DropViewStmt represents a DROP VIEW statement (for regular views only). ClickHouse syntax:
DROP VIEW [IF EXISTS] [db.]view_name [ON CLUSTER cluster] [SYNC]
type ElseClause ¶
ElseClause represents ELSE result
type EngineParameter ¶
type EngineParameter struct {
Expression *Expression `parser:"@@"`
String *string `parser:"| @String"`
Number *string `parser:"| @Number"`
Ident *string `parser:"| @(Ident | BacktickIdent)"`
}
EngineParameter represents a parameter in an ENGINE clause
func (*EngineParameter) Equal ¶ added in v0.1.3
func (p *EngineParameter) Equal(other *EngineParameter) bool
Equal compares two EngineParameter instances for equality
func (*EngineParameter) Value ¶
func (p *EngineParameter) Value() string
Value returns the string representation of the engine parameter
type Expression ¶
type Expression struct {
Case *CaseExpression `parser:"@@"`
Or *OrExpression `parser:"| @@"`
}
Expression represents any ClickHouse expression with proper precedence handling Precedence levels (lowest to highest): 1. CASE (lowest - can contain any sub-expressions) 2. OR 3. AND 4. NOT 5. Comparison (=, !=, <, >, <=, >=, LIKE, IN, BETWEEN) 6. Addition/Subtraction (+, -) 7. Multiplication/Division/Modulo (*, /, %) 8. Unary (+, -, NOT) 9. Primary (literals, identifiers, functions, parentheses)
func (*Expression) Equal ¶ added in v0.1.3
func (e *Expression) Equal(other *Expression) bool
Equal compares two Expression instances for structural equality
func (*Expression) String ¶
func (e *Expression) String() string
String returns the string representation of an Expression.
type ExtractExpression ¶
type ExtractExpression struct {
Extract string `parser:"'EXTRACT' '('"`
Part string `parser:"@('YEAR' | 'MONTH' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND')"`
From string `parser:"'FROM'"`
Expr Expression `parser:"@@"`
Close string `parser:"')'"`
}
ExtractExpression represents EXTRACT expressions
func (*ExtractExpression) String ¶
func (e *ExtractExpression) String() string
type FetchPartitionOperation ¶
type FetchPartitionOperation struct {
Fetch string `parser:"'FETCH' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
From string `parser:"'FROM' @String"`
}
FetchPartitionOperation represents FETCH PARTITION operation
type FrameBound ¶
type FrameBound struct {
Type string `parser:"@('UNBOUNDED' | 'CURRENT' | Number)"`
Direction string `parser:"@('PRECEDING' | 'FOLLOWING' | 'ROW')?"`
}
FrameBound represents window frame boundaries
func (*FrameBound) String ¶
func (f *FrameBound) String() string
String returns the string representation of a FrameBound for window frame boundaries
type FreezeOperation ¶
type FreezeOperation struct {
Freeze string `parser:"'FREEZE'"`
Partition *string `parser:"('PARTITION' @(String | Ident | BacktickIdent))?"`
With *string `parser:"('WITH' 'NAME' @String)?"`
}
FreezeOperation represents FREEZE operation
type FromClause ¶
type FromClause struct {
From string `parser:"'FROM'"`
Table TableRef `parser:"@@"`
Joins []JoinClause `parser:"@@*"`
}
FromClause represents FROM clause with joins
type FunctionArg ¶
type FunctionArg struct {
Star *string `parser:"@'*'"`
Expression *Expression `parser:"| @@"`
}
FunctionArg represents arguments in function calls (can be * or expression)
func (*FunctionArg) Equal ¶ added in v0.1.3
func (f *FunctionArg) Equal(other *FunctionArg) bool
Equal compares two FunctionArg
func (*FunctionArg) String ¶
func (a *FunctionArg) String() string
type FunctionCall ¶
type FunctionCall struct {
Name string `parser:"@(Ident | BacktickIdent)"`
FirstParentheses []FunctionArg `parser:"'(' (@@ (',' @@)*)? ')'"`
// Optional second set of parentheses for parameterized functions
SecondParentheses []FunctionArg `parser:"('(' (@@ (',' @@)*)? ')')?"`
Over *OverClause `parser:"@@?"`
}
FunctionCall represents function invocations, including parameterized functions like quantilesState(0.5, 0.75)(value)
func (*FunctionCall) Equal ¶ added in v0.1.3
func (f *FunctionCall) Equal(other *FunctionCall) bool
Equal compares two FunctionCall
func (*FunctionCall) String ¶
func (f *FunctionCall) String() string
String returns the string representation of a FunctionCall with function name and arguments.
type FunctionParam ¶ added in v0.1.2
type FunctionParam struct {
Name string `parser:"@(Ident | BacktickIdent)"`
}
FunctionParam represents a function parameter Syntax: parameter_name
type FunctionWithAlias ¶
type FunctionWithAlias struct {
Function TableFunction `parser:"@@"`
Alias *string `parser:"('AS' @(Ident | BacktickIdent))?"`
}
FunctionWithAlias represents a table function with optional alias
type GrantStmt ¶ added in v0.1.2
type GrantStmt struct {
LeadingCommentField
Privileges *PrivilegeList `parser:"'GRANT' @@"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
On *GrantTarget `parser:"('ON' @@)?"`
To *GranteeList `parser:"'TO' @@"`
WithGrant bool `parser:"@('WITH' 'GRANT' 'OPTION')?"`
WithReplace bool `parser:"@('WITH' 'REPLACE' 'OPTION')?"`
WithAdmin bool `parser:"@('WITH' 'ADMIN' 'OPTION')?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
GrantStmt represents GRANT statements Syntax: GRANT {privilege | role} [,...] [ON {database.table | *.*}] TO {user | role} [,...] [WITH GRANT OPTION];
type GrantTarget ¶ added in v0.1.2
type GrantTarget struct {
Star1 *string `parser:"( @'*'"`
Star2 *string `parser:" '.' @'*'"`
Database *string `parser:"| @(Ident | BacktickIdent)"`
Table *string `parser:" '.' @(Ident | BacktickIdent | '*'))"`
}
GrantTarget represents the target of a GRANT/REVOKE (database.table or *.*)
type Grantee ¶ added in v0.1.2
type Grantee struct {
Name string `parser:"@(Ident | BacktickIdent)"`
IsCurrent bool `parser:"| @'CURRENT_USER'"`
}
Grantee represents a user or role receiving privileges
type GranteeList ¶ added in v0.1.2
type GranteeList struct {
Items []*Grantee `parser:"@@ (',' @@)*"`
}
GranteeList represents the list of users/roles receiving privileges
type GroupByClause ¶
type GroupByClause struct {
GroupBy string `parser:"'GROUP' 'BY'"`
All bool `parser:"(@'ALL'"`
Columns []Expression `parser:"| @@ (',' @@)*)"`
WithClause *string `parser:"('WITH' @('CUBE' | 'ROLLUP' | 'TOTALS'))?"`
}
GroupByClause represents GROUP BY clause
type HavingClause ¶
type HavingClause struct {
Having string `parser:"'HAVING'"`
Condition Expression `parser:"@@"`
}
HavingClause represents HAVING clause
type IdentifierExpr ¶
type IdentifierExpr struct {
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Table *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
IdentifierExpr represents column names or qualified names
func (*IdentifierExpr) Equal ¶ added in v0.1.3
func (i *IdentifierExpr) Equal(other *IdentifierExpr) bool
Equal compares two IdentifierExpr
func (*IdentifierExpr) String ¶
func (i *IdentifierExpr) String() string
String returns the string representation of an IdentifierExpr with optional database and table qualifiers.
type InComparison ¶
type InComparison struct {
Not bool `parser:"@'NOT'?"`
In string `parser:"'IN'"`
Expr *InExpression `parser:"@@"`
}
InComparison handles IN and NOT IN operations
type InExpression ¶
type InExpression struct {
List []Expression `parser:"'(' @@ (',' @@)* ')'"`
Array *ArrayExpression `parser:"| @@"`
Subquery *Subquery `parser:"| @@"`
}
InExpression handles IN operations with lists, arrays, or subqueries
func (InExpression) String ¶
func (i InExpression) String() string
type IndexDefinition ¶
type IndexDefinition struct {
Index string `parser:"'INDEX'"`
Name string `parser:"@(Ident | BacktickIdent)"`
Expression Expression `parser:"@@"`
Type string `parser:"'TYPE'"`
IndexType IndexType `parser:"@@"`
Granularity *string `parser:"('GRANULARITY' @Number)?"`
}
IndexDefinition represents an INDEX definition within CREATE TABLE ClickHouse syntax:
INDEX index_name expression TYPE index_type [GRANULARITY value]
type IndexNGramBFType ¶
type IndexNGramBFType struct {
NGramBF string `parser:"'ngrambf_v1' '('"`
N string `parser:"@Number"`
Comma1 string `parser:"','"`
Size string `parser:"@Number"`
Comma2 string `parser:"','"`
Hashes string `parser:"@Number"`
Comma3 string `parser:"','"`
Seed string `parser:"@Number"`
Close string `parser:"')'"`
}
IndexNGramBFType represents ngrambf_v1(n, size, hashes, seed) index type
type IndexSetType ¶
type IndexSetType struct {
Set string `parser:"'set' '('"`
MaxRows string `parser:"@Number"`
Close string `parser:"')'"`
}
IndexSetType represents set(max_rows) index type
type IndexTokenBFType ¶
type IndexTokenBFType struct {
TokenBF string `parser:"'tokenbf_v1' '('"`
Size string `parser:"@Number"`
Comma1 string `parser:"','"`
Hashes string `parser:"@Number"`
Comma2 string `parser:"','"`
Seed string `parser:"@Number"`
Close string `parser:"')'"`
}
IndexTokenBFType represents tokenbf_v1(size, hashes, seed) index type
type IndexType ¶
type IndexType struct {
// Simple index types
BloomFilter bool `parser:"@'bloom_filter'"`
MinMax bool `parser:"| @'minmax'"`
Hypothesis bool `parser:"| @'hypothesis'"`
// Parametric index types
Set *IndexSetType `parser:"| @@"`
TokenBF *IndexTokenBFType `parser:"| @@"`
NGramBF *IndexNGramBFType `parser:"| @@"`
// Custom/future index types - fallback to string
Custom *string `parser:"| @(Ident | BacktickIdent)"`
}
IndexType represents different ClickHouse index types
type InterpolateClause ¶ added in v0.1.9
type InterpolateClause struct {
Interpolate string `parser:"'INTERPOLATE'"`
Columns []InterpolateColumn `parser:"('(' (@@ (',' @@)*)? ')')?"`
}
InterpolateClause represents INTERPOLATE clause for WITH FILL
type InterpolateColumn ¶ added in v0.1.9
type InterpolateColumn struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Expression *Expression `parser:"('AS' @@)?"`
}
InterpolateColumn represents a column in INTERPOLATE clause
type IntervalExpr ¶
type IntervalExpr struct {
Interval string `parser:"'INTERVAL'"`
Value string `parser:"@Number"`
Unit string `parser:"@('SECOND' | 'MINUTE' | 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'QUARTER' | 'YEAR')"`
}
IntervalExpr represents INTERVAL expressions
func (*IntervalExpr) String ¶
func (i *IntervalExpr) String() string
type IsNullExpr ¶
type IsNullExpr struct {
Is string `parser:"'IS'"`
Not bool `parser:"@'NOT'?"`
Null string `parser:"'NULL'"`
}
IsNullExpr handles IS NULL and IS NOT NULL expressions as postfix operators
func (*IsNullExpr) Equal ¶ added in v0.1.3
func (i *IsNullExpr) Equal(other *IsNullExpr) bool
Equal compares two IsNullExpr
type JoinClause ¶
type JoinClause struct {
Type string `parser:"@('INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS')?"`
Join string `parser:"@('JOIN' | 'ARRAY' 'JOIN' | 'GLOBAL' 'JOIN' | 'ASOF' 'JOIN')"`
Table TableRef `parser:"@@"`
Condition *JoinCondition `parser:"@@?"`
}
JoinClause represents JOIN operations
type JoinCondition ¶
type JoinCondition struct {
On *Expression `parser:"'ON' @@"`
Using []string `parser:"| 'USING' '(' @(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))* ')'"`
}
JoinCondition represents ON or USING clause in joins
type LeadingCommentField ¶ added in v0.1.9
type LeadingCommentField struct {
LeadingComments []string `parser:"@(Comment | MultilineComment)*"`
}
LeadingCommentField provides leading comment support for statements. This is embedded at the start of statement structs to capture comments that appear before the statement keywords.
func (*LeadingCommentField) GetLeadingComments ¶ added in v0.1.9
func (c *LeadingCommentField) GetLeadingComments() []string
GetLeadingComments returns the leading comments.
type LimitBy ¶
type LimitBy struct {
By string `parser:"'BY'"`
Columns []Expression `parser:"@@ (',' @@)*"`
}
LimitBy represents LIMIT ... BY clause
type LimitClause ¶
type LimitClause struct {
Limit string `parser:"'LIMIT'"`
Count Expression `parser:"@@"`
Offset *OffsetClause `parser:"@@?"`
By *LimitBy `parser:"@@?"`
}
LimitClause represents LIMIT clause
type Literal ¶
type Literal struct {
StringValue *string `parser:"@String"`
Number *string `parser:"| @Number"`
Boolean *string `parser:"| @('TRUE' | 'FALSE')"`
Null bool `parser:"| @'NULL'"`
}
Literal represents literal values
type LowCardinalityType ¶
type LowCardinalityType struct {
LowCardinality string `parser:"'LowCardinality' '('"`
Type *DataType `parser:"@@"`
Close string `parser:"')'"`
}
LowCardinalityType represents LowCardinality(T) where T is a data type
func (*LowCardinalityType) Equal ¶ added in v0.1.7
func (l *LowCardinalityType) Equal(other DataTypeComparable) bool
Equal compares two LowCardinalityType instances
func (*LowCardinalityType) String ¶ added in v0.1.9
func (l *LowCardinalityType) String() string
String returns the SQL representation of a LowCardinality type.
func (*LowCardinalityType) TypeName ¶ added in v0.1.7
func (l *LowCardinalityType) TypeName() string
TypeName returns the type name for LowCardinalityType
type MapType ¶
type MapType struct {
Map string `parser:"'Map' '('"`
KeyType *DataType `parser:"@@"`
Comma string `parser:"','"`
ValueType *DataType `parser:"@@"`
Close string `parser:"')'"`
}
MapType represents Map(K, V) where K and V are data types
func (*MapType) Equal ¶ added in v0.1.7
func (m *MapType) Equal(other DataTypeComparable) bool
Equal compares two MapType instances
type ModifyColumnOperation ¶
type ModifyColumnOperation struct {
Modify string `parser:"'MODIFY' 'COLUMN'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
Type *DataType `parser:"@@?"`
Default *DefaultClause `parser:"@@?"`
Codec *CodecClause `parser:"@@?"`
TTL *Expression `parser:"('TTL' @@)?"`
Comment *string `parser:"('COMMENT' @String)?"`
Remove *ModifyColumnRemove `parser:"@@?"`
}
ModifyColumnOperation represents MODIFY COLUMN operation
type ModifyColumnRemove ¶
type ModifyColumnRemove struct {
Remove string `parser:"'REMOVE'"`
What string `parser:"@('DEFAULT' | 'MATERIALIZED' | 'ALIAS' | 'COMMENT' | 'CODEC' | 'TTL')"`
}
ModifyColumnRemove represents REMOVE clause in MODIFY COLUMN
type ModifyOrderByOperation ¶
type ModifyOrderByOperation struct {
Modify string `parser:"'MODIFY' 'ORDER' 'BY'"`
Expression Expression `parser:"@@"`
}
ModifyOrderByOperation represents MODIFY ORDER BY operation
type ModifySampleByOperation ¶
type ModifySampleByOperation struct {
Modify string `parser:"'MODIFY' 'SAMPLE' 'BY'"`
Expression Expression `parser:"@@"`
}
ModifySampleByOperation represents MODIFY SAMPLE BY operation
type ModifySettingOperation ¶
type ModifySettingOperation struct {
Modify string `parser:"'MODIFY' 'SETTING'"`
Setting TableSetting `parser:"@@"`
}
ModifySettingOperation represents MODIFY SETTING operation
type ModifyTTLOperation ¶
type ModifyTTLOperation struct {
Modify string `parser:"'MODIFY' 'TTL'"`
Expression Expression `parser:"@@"`
Delete *TTLDelete `parser:"@@?"`
}
ModifyTTLOperation represents MODIFY TTL operation
type MovePartitionOperation ¶
type MovePartitionOperation struct {
Move string `parser:"'MOVE' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
To string `parser:"'TO'"`
Disk *string `parser:"(('DISK' @String)"`
Volume *string `parser:"| ('VOLUME' @String)"`
Table *MoveToTable `parser:"| ('TABLE' @@))?"`
}
MovePartitionOperation represents MOVE PARTITION operation
type MoveToTable ¶
type MoveToTable struct {
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
MoveToTable represents destination table in MOVE PARTITION
type MultiplicationExpression ¶
type MultiplicationExpression struct {
Unary *UnaryExpression `parser:"@@"`
Rest []MultiplicationRest `parser:"@@*"`
}
MultiplicationExpression handles multiplication, division, and modulo
func (*MultiplicationExpression) Equal ¶ added in v0.1.3
func (m *MultiplicationExpression) Equal(other *MultiplicationExpression) bool
Equal compares two Multiplication expressions
func (*MultiplicationExpression) String ¶
func (m *MultiplicationExpression) String() string
type MultiplicationRest ¶
type MultiplicationRest struct {
Op string `parser:"@('*' | '/' | '%')"`
Unary *UnaryExpression `parser:"@@"`
}
type NamedCollectionOverride ¶ added in v0.1.1
type NamedCollectionOverride struct {
NotOverridable bool `parser:"@('NOT' 'OVERRIDABLE')"`
Overridable bool `parser:"| @'OVERRIDABLE'"`
}
NamedCollectionOverride represents the OVERRIDABLE or NOT OVERRIDABLE clause
func (*NamedCollectionOverride) IsOverridable ¶ added in v0.1.1
func (o *NamedCollectionOverride) IsOverridable() bool
IsOverridable returns true if the override is explicitly overridable
type NamedCollectionParameter ¶ added in v0.1.1
type NamedCollectionParameter struct {
Key string `parser:"@(Ident | BacktickIdent) '='"`
Value *NamedCollectionValue `parser:"@@"`
Override *NamedCollectionOverride `parser:"@@?"`
Comma *string `parser:"@','?"`
}
NamedCollectionParameter represents a key-value pair in a CREATE NAMED COLLECTION statement
type NamedCollectionSetParameter ¶ added in v0.1.1
type NamedCollectionSetParameter struct {
Key string `parser:"@(Ident | BacktickIdent) '='"`
Value *NamedCollectionValue `parser:"@@"`
Override *NamedCollectionOverride `parser:"@@?"`
}
NamedCollectionSetParameter represents a single SET parameter in an ALTER NAMED COLLECTION
type NamedCollectionValue ¶ added in v0.1.1
type NamedCollectionValue struct {
String *string `parser:"@String"`
Number *float64 `parser:"| @Number"`
Bool *string `parser:"| @('TRUE' | 'FALSE')"`
Null *string `parser:"| @'NULL'"`
}
NamedCollectionValue represents the value part of a named collection parameter
func (*NamedCollectionValue) GetValue ¶ added in v0.1.1
func (v *NamedCollectionValue) GetValue() string
GetValue returns the string representation of the value
type NestedColumn ¶
type NestedColumn struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Type *DataType `parser:"@@"`
}
NestedColumn represents a column within a Nested type
func (*NestedColumn) String ¶ added in v0.1.9
func (c *NestedColumn) String() string
String returns the SQL representation of a nested column.
type NestedType ¶
type NestedType struct {
Nested string `parser:"'Nested' '('"`
Columns []NestedColumn `parser:"@@ (',' @@)*"`
Close string `parser:"')'"`
}
NestedType represents Nested(col1 Type1, col2 Type2, ...)
func (*NestedType) Equal ¶ added in v0.1.7
func (n *NestedType) Equal(other DataTypeComparable) bool
Equal compares two NestedType instances
func (*NestedType) String ¶ added in v0.1.9
func (n *NestedType) String() string
String returns the SQL representation of a Nested type.
func (*NestedType) TypeName ¶ added in v0.1.7
func (n *NestedType) TypeName() string
TypeName returns the type name for NestedType
type NotExpression ¶
type NotExpression struct {
Not bool `parser:"@'NOT'?"`
Comparison *ComparisonExpression `parser:"@@"`
}
NotExpression handles NOT operations
func (*NotExpression) Equal ¶ added in v0.1.3
func (n *NotExpression) Equal(other *NotExpression) bool
Equal compares two NOT expressions
func (*NotExpression) String ¶
func (n *NotExpression) String() string
String returns the string representation of a NotExpression with optional NOT prefix.
type NullableType ¶
type NullableType struct {
Nullable string `parser:"'Nullable' '('"`
Type *DataType `parser:"@@"`
Close string `parser:"')'"`
}
NullableType represents Nullable(T) where T is any data type
func (*NullableType) Equal ¶ added in v0.1.7
func (n *NullableType) Equal(other DataTypeComparable) bool
Equal compares two NullableType instances
func (*NullableType) String ¶ added in v0.1.9
func (n *NullableType) String() string
String returns the SQL representation of a Nullable type.
func (*NullableType) TypeName ¶ added in v0.1.7
func (n *NullableType) TypeName() string
TypeName returns the type name for NullableType
type OffsetClause ¶
type OffsetClause struct {
Offset string `parser:"'OFFSET'"`
Value Expression `parser:"@@"`
}
OffsetClause represents OFFSET clause
type OrExpression ¶
type OrExpression struct {
And *AndExpression `parser:"@@"`
Rest []OrRest `parser:"@@*"`
}
OrExpression handles OR operations (lowest precedence)
func (*OrExpression) Equal ¶ added in v0.1.3
func (o *OrExpression) Equal(other *OrExpression) bool
Equal compares two OR expressions
func (*OrExpression) String ¶
func (o *OrExpression) String() string
String returns the string representation of an OrExpression with proper OR operator placement.
type OrRest ¶
type OrRest struct {
Op string `parser:"@'OR'"`
And *AndExpression `parser:"@@"`
}
type OrderByClause ¶
type OrderByClause struct {
OrderBy string `parser:"'ORDER' 'BY'"`
Expression Expression `parser:"@@"`
}
OrderByClause represents ORDER BY expression
func (*OrderByClause) Equal ¶ added in v0.1.3
func (o *OrderByClause) Equal(other *OrderByClause) bool
Equal compares two OrderByClause instances for equality
type OrderByColumn ¶
type OrderByColumn struct {
Expression Expression `parser:"@@"`
Direction *string `parser:"@('ASC' | 'DESC')?"`
Nulls *string `parser:"('NULLS' @('FIRST' | 'LAST'))?"`
Collate *string `parser:"('COLLATE' @String)?"`
WithFill bool `parser:"@('WITH' 'FILL')?"`
FillFrom *Expression `parser:"('FROM' @@)?"`
FillTo *Expression `parser:"('TO' @@)?"`
FillStep *Expression `parser:"('STEP' @@)?"`
FillStaleness *Expression `parser:"('STALENESS' @@)?"`
}
OrderByColumn represents a single column in ORDER BY
type OrderByExpr ¶
type OrderByExpr struct {
Expression Expression `parser:"@@"`
Desc bool `parser:"@'DESC'?"`
Nulls *string `parser:"('NULLS' @('FIRST' | 'LAST'))?"`
}
OrderByExpr for ORDER BY in OVER clause
func (*OrderByExpr) String ¶
func (o *OrderByExpr) String() string
String returns the string representation of an OrderByExpr for ORDER BY in OVER clauses
type OverClause ¶
type OverClause struct {
Over string `parser:"'OVER'"`
PartitionBy []Expression `parser:"'(' ('PARTITION' 'BY' @@ (',' @@)*)?"`
OrderBy []OrderByExpr `parser:"('ORDER' 'BY' @@ (',' @@)*)?"`
Frame *WindowFrame `parser:"@@? ')'"`
}
OverClause for window functions
func (*OverClause) String ¶
func (o *OverClause) String() string
String returns the string representation of an OverClause for window functions
type ParametricFunction ¶
type ParametricFunction struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Parameters []TypeParameter `parser:"'(' (@@ (',' @@)*)? ')'"`
}
ParametricFunction represents a function call within type parameters (e.g., quantiles(0.5, 0.75))
func (*ParametricFunction) Equal ¶ added in v0.1.3
func (p *ParametricFunction) Equal(other *ParametricFunction) bool
Equal compares two ParametricFunction instances for equality
func (*ParametricFunction) String ¶ added in v0.1.9
func (p *ParametricFunction) String() string
String returns the SQL representation of a parametric function.
type ParenExpression ¶
type ParenExpression struct {
Expression Expression `parser:"'(' @@ ')'"`
}
ParenExpression represents parenthesized expressions
type PartitionByClause ¶
type PartitionByClause struct {
PartitionBy string `parser:"'PARTITION' 'BY'"`
Expression Expression `parser:"@@"`
}
PartitionByClause represents PARTITION BY expression
func (*PartitionByClause) Equal ¶ added in v0.1.3
func (p *PartitionByClause) Equal(other *PartitionByClause) bool
Equal compares two PartitionByClause instances for equality
type PrimaryExpression ¶
type PrimaryExpression struct {
Literal *Literal `parser:"@@"`
Interval *IntervalExpr `parser:"| @@"`
Extract *ExtractExpression `parser:"| @@"`
Cast *CastExpression `parser:"| @@"`
Function *FunctionCall `parser:"| @@"`
Identifier *IdentifierExpr `parser:"| @@"`
Parentheses *ParenExpression `parser:"| @@"`
Tuple *TupleExpression `parser:"| @@"`
Array *ArrayExpression `parser:"| @@"`
}
PrimaryExpression represents the highest precedence expressions
func (*PrimaryExpression) Equal ¶ added in v0.1.3
func (p *PrimaryExpression) Equal(other *PrimaryExpression) bool
Equal compares two Primary expressions
func (*PrimaryExpression) String ¶
func (p *PrimaryExpression) String() string
type PrimaryKeyClause ¶
type PrimaryKeyClause struct {
PrimaryKey string `parser:"'PRIMARY' 'KEY'"`
Expression Expression `parser:"@@"`
}
PrimaryKeyClause represents PRIMARY KEY expression
func (*PrimaryKeyClause) Equal ¶ added in v0.1.3
func (p *PrimaryKeyClause) Equal(other *PrimaryKeyClause) bool
Equal compares two PrimaryKeyClause instances for equality
type PrivilegeItem ¶ added in v0.1.2
type PrivilegeItem struct {
// This is simplified - in reality, privileges can be complex expressions
// We'll parse them as identifiers and let ClickHouse validate
All bool `parser:"@'ALL'"`
Name string `parser:"| @(Ident | BacktickIdent)"`
Columns []string `parser:"('(' @(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))* ')')?"`
}
PrivilegeItem represents a single privilege or role
type PrivilegeList ¶ added in v0.1.2
type PrivilegeList struct {
Items []*PrivilegeItem `parser:"@@ (',' @@)*"`
}
PrivilegeList represents a list of privileges or roles in GRANT/REVOKE
type ProjectionDefinition ¶
type ProjectionDefinition struct {
Projection string `parser:"'PROJECTION'"`
Name string `parser:"@(Ident | BacktickIdent)"`
SelectClause ProjectionSelect `parser:"@@"`
}
ProjectionDefinition represents a PROJECTION definition within CREATE TABLE ClickHouse syntax:
PROJECTION projection_name (SELECT ... [GROUP BY ...] [ORDER BY ...])
type ProjectionSelect ¶
type ProjectionSelect struct {
OpenParen string `parser:"'('"`
SelectStmt SelectStatement `parser:"@@"`
CloseParen string `parser:"')'"`
}
ProjectionSelect represents the SELECT clause within projection parentheses
type RemoveSampleByOperation ¶
type RemoveSampleByOperation struct {
Remove string `parser:"'REMOVE' 'SAMPLE' 'BY'"`
}
RemoveSampleByOperation represents REMOVE SAMPLE BY operation
type RenameColumnOperation ¶
type RenameColumnOperation struct {
Rename string `parser:"'RENAME' 'COLUMN'"`
IfExists bool `parser:"@('IF' 'EXISTS')?"`
From string `parser:"@(Ident | BacktickIdent)"`
To string `parser:"'TO' @(Ident | BacktickIdent)"`
}
RenameColumnOperation represents RENAME COLUMN operation
type RenameDatabaseStmt ¶
type RenameDatabaseStmt struct {
LeadingCommentField
Rename string `parser:"'RENAME'"`
Database string `parser:"'DATABASE'"`
Renames []*DatabaseRename `parser:"@@ (',' @@)*"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
RenameDatabaseStmt represents RENAME DATABASE statements Syntax: RENAME DATABASE name1 TO new_name1 [, name2 TO new_name2, ...] [ON CLUSTER cluster];
type RenameDictionaryStmt ¶
type RenameDictionaryStmt struct {
LeadingCommentField
Renames []*DictionaryRename `parser:"'RENAME' 'DICTIONARY' @@ (',' @@)*"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
RenameDictionaryStmt represents RENAME DICTIONARY statements Syntax: RENAME DICTIONARY [db.]name1 TO [db.]new_name1 [, [db.]name2 TO [db.]new_name2, ...] [ON CLUSTER cluster];
type RenameTableStmt ¶
type RenameTableStmt struct {
LeadingCommentField
Rename string `parser:"'RENAME' 'TABLE'"`
Renames []TableRename `parser:"@@ (',' @@)*"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
RenameTableStmt represents a RENAME TABLE statement. Used for both regular views and materialized views. ClickHouse syntax:
RENAME TABLE [db.]table1 TO [db.]table2, [db.]table3 TO [db.]table4, ... [ON CLUSTER cluster]
type ReplacePartitionOperation ¶
type ReplacePartitionOperation struct {
Replace string `parser:"'REPLACE' 'PARTITION'"`
Partition string `parser:"@(String | Ident | BacktickIdent)"`
From string `parser:"'FROM'"`
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Table string `parser:"@(Ident | BacktickIdent)"`
}
ReplacePartitionOperation represents REPLACE PARTITION operation
type ResetSettingOperation ¶
type ResetSettingOperation struct {
Reset string `parser:"'RESET' 'SETTING'"`
Name string `parser:"@(Ident | BacktickIdent)"`
}
ResetSettingOperation represents RESET SETTING operation
type RevokeStmt ¶ added in v0.1.2
type RevokeStmt struct {
LeadingCommentField
GrantOption bool `parser:"'REVOKE' (@'GRANT' 'OPTION' 'FOR'"`
AdminOption bool `parser:"| @'ADMIN' 'OPTION' 'FOR')?"`
Privileges *PrivilegeList `parser:"@@"`
OnCluster *string `parser:"('ON' 'CLUSTER' @(Ident | BacktickIdent))?"`
On *GrantTarget `parser:"('ON' @@)?"`
From *GranteeList `parser:"'FROM' @@"`
TrailingCommentField
Semicolon bool `parser:"';'"`
}
RevokeStmt represents REVOKE statements Syntax: REVOKE [GRANT OPTION FOR | ADMIN OPTION FOR] {privilege | role} [,...] [ON {database.table | *.*}] FROM {user | role} [,...];
type RoleList ¶ added in v0.1.2
type RoleList struct {
Names []string `parser:"@(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))*"`
}
RoleList represents a list of role names
type RoleSetting ¶ added in v0.1.2
type RoleSetting struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Value *string `parser:"('=' @(Number | String | Ident | BacktickIdent))?"`
}
RoleSetting represents a single role setting
type RoleSettings ¶ added in v0.1.2
type RoleSettings struct {
Settings []*RoleSetting `parser:"'SETTINGS' @@ (',' @@)*"`
}
RoleSettings represents SETTINGS clause for roles
type SQL ¶
type SQL struct {
Statements []*Statement `parser:"@@*"`
}
SQL defines the complete ClickHouse DDL/DML SQL structure
func Parse ¶
Parse parses ClickHouse DDL statements from an io.Reader and returns the parsed SQL structure. This function allows parsing SQL from any source that implements io.Reader, including files, strings, network connections, or in-memory buffers.
Example usage:
// Parse from a string
reader := strings.NewReader("CREATE DATABASE test ENGINE = Atomic;")
sqlResult, err := parser.Parse(reader)
if err != nil {
log.Fatalf("Parse error: %v", err)
}
// Parse from a file
file, err := os.Open("schema.sql")
if err != nil {
log.Fatal(err)
}
defer file.Close()
sqlResult, err = parser.Parse(file)
if err != nil {
log.Fatalf("Parse error: %v", err)
}
// Parse from an HTTP response
resp, err := http.Get("https://example.com/schema.sql")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
sqlResult, err = parser.Parse(resp.Body)
if err != nil {
log.Fatalf("Parse error: %v", err)
}
// Access parsed statements
for _, stmt := range sqlResult.Statements {
if stmt.CreateDatabase != nil {
fmt.Printf("CREATE DATABASE: %s\n", stmt.CreateDatabase.Name)
}
}
Returns an error if the reader cannot be read or contains invalid SQL.
func ParseString ¶
ParseString parses ClickHouse DDL statements from a string and returns the parsed SQL structure. This is the primary parsing function that converts SQL text into structured DDL statements. It supports all implemented ClickHouse DDL operations including database creation, modification, attachment, detachment, and deletion.
Example usage:
sql := `
CREATE DATABASE analytics ENGINE = Atomic COMMENT 'Analytics database';
CREATE TABLE analytics.events (
id UInt64,
user_id UInt64,
event_type LowCardinality(String),
timestamp DateTime DEFAULT now(),
data Map(String, String) DEFAULT map(),
metadata Nullable(String) CODEC(ZSTD)
) ENGINE = MergeTree()
ORDER BY (user_id, timestamp)
PARTITION BY toYYYYMM(timestamp)
SETTINGS index_granularity = 8192;
CREATE DICTIONARY analytics.users_dict (
id UInt64 IS_OBJECT_ID,
name String INJECTIVE
) PRIMARY KEY id
SOURCE(HTTP(url 'http://api.example.com/users'))
LAYOUT(HASHED())
LIFETIME(3600);
CREATE MATERIALIZED VIEW analytics.daily_stats
ENGINE = MergeTree() ORDER BY date
POPULATE
AS SELECT toDate(timestamp) as date, count() as cnt
FROM analytics.events
GROUP BY date;
ALTER DATABASE analytics MODIFY COMMENT 'Updated analytics database';
RENAME DATABASE analytics TO prod_analytics;
RENAME DICTIONARY prod_analytics.users_dict TO prod_analytics.user_data;
RENAME TABLE analytics.old_view TO analytics.new_view;
`
sqlResult, err := parser.ParseString(sql)
if err != nil {
log.Fatalf("Parse error: %v", err)
}
// Access parsed statements
for _, stmt := range sqlResult.Statements {
if stmt.CreateDatabase != nil {
fmt.Printf("CREATE DATABASE: %s\n", stmt.CreateDatabase.Name)
}
if stmt.CreateTable != nil {
name := stmt.CreateTable.Name
if stmt.CreateTable.Database != nil {
name = *stmt.CreateTable.Database + "." + name
}
fmt.Printf("CREATE TABLE: %s with %d columns\n", name, len(stmt.CreateTable.Columns))
}
if stmt.CreateDictionary != nil {
name := stmt.CreateDictionary.Name
if stmt.CreateDictionary.Database != nil {
name = *stmt.CreateDictionary.Database + "." + name
}
fmt.Printf("CREATE DICTIONARY: %s\n", name)
}
if stmt.RenameDatabase != nil {
for _, rename := range stmt.RenameDatabase.Renames {
fmt.Printf("RENAME DATABASE: %s TO %s\n", rename.From, rename.To)
}
}
if stmt.RenameDictionary != nil {
for _, rename := range stmt.RenameDictionary.Renames {
fromName := rename.FromName
if rename.FromDatabase != nil {
fromName = *rename.FromDatabase + "." + fromName
}
toName := rename.ToName
if rename.ToDatabase != nil {
toName = *rename.ToDatabase + "." + toName
}
fmt.Printf("RENAME DICTIONARY: %s TO %s\n", fromName, toName)
}
}
if stmt.CreateView != nil {
viewType := "VIEW"
if stmt.CreateView.Materialized {
viewType = "MATERIALIZED VIEW"
}
name := stmt.CreateView.Name
if stmt.CreateView.Database != nil {
name = *stmt.CreateView.Database + "." + name
}
fmt.Printf("CREATE %s: %s\n", viewType, name)
}
}
Returns an error if the SQL contains syntax errors or unsupported constructs.
type SampleByClause ¶
type SampleByClause struct {
SampleBy string `parser:"'SAMPLE' 'BY'"`
Expression Expression `parser:"@@"`
}
SampleByClause represents SAMPLE BY expression
func (*SampleByClause) Equal ¶ added in v0.1.3
func (s *SampleByClause) Equal(other *SampleByClause) bool
Equal compares two SampleByClause instances for equality
type SelectColumn ¶
type SelectColumn struct {
Star *string `parser:"@'*'"`
Expression *Expression `parser:"| @@"`
Alias *string `parser:"('AS' @(Ident | BacktickIdent))?"`
}
SelectColumn represents a column in SELECT clause
type SelectOrderByClause ¶
type SelectOrderByClause struct {
OrderBy string `parser:"'ORDER' 'BY'"`
Columns []OrderByColumn `parser:"@@ (',' @@)*"`
Interpolate *InterpolateClause `parser:"@@?"`
}
SelectOrderByClause represents ORDER BY clause in SELECT statements
type SelectStatement ¶
type SelectStatement struct {
With *WithClause `parser:"@@?"`
Select string `parser:"'SELECT'"`
Distinct bool `parser:"@'DISTINCT'?"`
Columns []SelectColumn `parser:"@@ (',' @@)*"`
From *FromClause `parser:"@@?"`
Where *WhereClause `parser:"@@?"`
GroupBy *GroupByClause `parser:"@@?"`
Having *HavingClause `parser:"@@?"`
OrderBy *SelectOrderByClause `parser:"@@?"`
Limit *LimitClause `parser:"@@?"`
Settings *SettingsClause `parser:"@@?"`
}
SelectStatement represents a SELECT statement (for subqueries, no semicolon)
type SetDefaultRoleStmt ¶ added in v0.1.2
type SetDefaultRoleStmt struct {
None bool `parser:"'SET' 'DEFAULT' 'ROLE' (@'NONE'"`
All bool `parser:"| @'ALL'"`
Roles *RoleList `parser:"| @@"`
AllExcept *RoleList `parser:"| 'ALL' 'EXCEPT' @@)"`
ToUsers []string `parser:"'TO' @(Ident | BacktickIdent) (',' @(Ident | BacktickIdent))*"`
Semicolon bool `parser:"';'"`
}
SetDefaultRoleStmt represents SET DEFAULT ROLE statements Syntax: SET DEFAULT ROLE {NONE | ALL | name [,...] | ALL EXCEPT name [,...]} TO user [,...];
type SetRoleStmt ¶ added in v0.1.2
type SetRoleStmt struct {
Default bool `parser:"'SET' 'ROLE' (@'DEFAULT'"`
None bool `parser:"| @'NONE'"`
All bool `parser:"| @'ALL'"`
AllExcept *RoleList `parser:"| 'ALL' 'EXCEPT' @@"`
Roles *RoleList `parser:"| @@)"`
Semicolon bool `parser:"';'"`
}
SetRoleStmt represents SET ROLE statements for session management Syntax: SET ROLE {DEFAULT | NONE | ALL | ALL EXCEPT name [,...] | name [,...]};
type SettingsAssignment ¶
type SettingsAssignment struct {
Key string `parser:"@(Ident | BacktickIdent)"`
Value Expression `parser:"'=' @@"`
}
SettingsAssignment represents key=value in SETTINGS
type SettingsClause ¶
type SettingsClause struct {
Settings string `parser:"'SETTINGS'"`
Values []SettingsAssignment `parser:"@@ (',' @@)*"`
}
SettingsClause represents SETTINGS clause
type SimpleComparison ¶
type SimpleComparison struct {
Op *SimpleComparisonOp `parser:"@@"`
Addition *AdditionExpression `parser:"@@"`
}
SimpleComparison handles basic comparison operations
func (*SimpleComparison) Equal ¶ added in v0.1.3
func (s *SimpleComparison) Equal(other *SimpleComparison) bool
Equal compares two SimpleComparison operations
type SimpleComparisonOp ¶
type SimpleComparisonOp struct {
Eq bool `parser:"@'='"`
NotEq bool `parser:"| @'!=' | @'<>'"`
LtEq bool `parser:"| @'<='"`
GtEq bool `parser:"| @'>='"`
Lt bool `parser:"| @'<'"`
Gt bool `parser:"| @'>'"`
Like bool `parser:"| @'LIKE'"`
NotLike bool `parser:"| @('NOT' 'LIKE')"`
}
func (*SimpleComparisonOp) Equal ¶ added in v0.1.3
func (s *SimpleComparisonOp) Equal(other *SimpleComparisonOp) bool
Equal compares two SimpleComparisonOp
func (*SimpleComparisonOp) String ¶
func (c *SimpleComparisonOp) String() string
String returns the string representation of a SimpleComparisonOp (=, !=, <, >, <=, >=, LIKE, NOT LIKE).
type SimpleDSLParam ¶
type SimpleDSLParam struct {
Name string `parser:"@(Ident | BacktickIdent | 'USER' | 'PASSWORD' | 'VALUE' | 'NAME')"`
Value Expression `parser:"@@"`
}
SimpleDSLParam represents simple name-value parameters in DSL functions
type SimpleParameter ¶
type SimpleParameter struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Expression Expression `parser:"@@"`
}
SimpleParameter represents name-value parameters
type SimpleType ¶
type SimpleType struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Parameters []TypeParameter `parser:"('(' @@ (',' @@)* ')')?"`
}
SimpleType represents basic data types and parametric types
func (*SimpleType) Equal ¶ added in v0.1.7
func (s *SimpleType) Equal(other DataTypeComparable) bool
Equal compares two SimpleType instances with special handling for ClickHouse normalization patterns
func (*SimpleType) String ¶ added in v0.1.9
func (s *SimpleType) String() string
String returns the SQL representation of a simple or parametric type.
func (*SimpleType) TypeName ¶ added in v0.1.7
func (s *SimpleType) TypeName() string
TypeName returns the type name for SimpleType
type Statement ¶
type Statement struct {
CommentStatement *CommentStatement `parser:"@@"`
CreateDatabase *CreateDatabaseStmt `parser:"| @@"`
AlterDatabase *AlterDatabaseStmt `parser:"| @@"`
AttachDatabase *AttachDatabaseStmt `parser:"| @@"`
DetachDatabase *DetachDatabaseStmt `parser:"| @@"`
DropDatabase *DropDatabaseStmt `parser:"| @@"`
RenameDatabase *RenameDatabaseStmt `parser:"| @@"`
CreateTable *CreateTableStmt `parser:"| @@"`
AlterTable *AlterTableStmt `parser:"| @@"`
CreateDictionary *CreateDictionaryStmt `parser:"| @@"`
CreateView *CreateViewStmt `parser:"| @@"`
CreateNamedCollection *CreateNamedCollectionStmt `parser:"| @@"`
AlterNamedCollection *AlterNamedCollectionStmt `parser:"| @@"`
CreateRole *CreateRoleStmt `parser:"| @@"`
AlterRole *AlterRoleStmt `parser:"| @@"`
DropRole *DropRoleStmt `parser:"| @@"`
SetRole *SetRoleStmt `parser:"| @@"`
SetDefaultRole *SetDefaultRoleStmt `parser:"| @@"`
Grant *GrantStmt `parser:"| @@"`
Revoke *RevokeStmt `parser:"| @@"`
CreateFunction *CreateFunctionStmt `parser:"| @@"`
DropFunction *DropFunctionStmt `parser:"| @@"`
AttachView *AttachViewStmt `parser:"| @@"`
AttachDictionary *AttachDictionaryStmt `parser:"| @@"`
DetachView *DetachViewStmt `parser:"| @@"`
DetachDictionary *DetachDictionaryStmt `parser:"| @@"`
DropView *DropViewStmt `parser:"| @@"`
DropDictionary *DropDictionaryStmt `parser:"| @@"`
DropNamedCollection *DropNamedCollectionStmt `parser:"| @@"`
AttachTable *AttachTableStmt `parser:"| @@"`
DetachTable *DetachTableStmt `parser:"| @@"`
DropTable *DropTableStmt `parser:"| @@"`
RenameTable *RenameTableStmt `parser:"| @@"`
RenameDictionary *RenameDictionaryStmt `parser:"| @@"`
SelectStatement *TopLevelSelectStatement `parser:"| @@"`
}
Statement represents any DDL or DML statement
type Subquery ¶
type Subquery struct {
OpenParen string `parser:"'('"`
SelectStmt SelectStatement `parser:"@@"`
CloseParen string `parser:"')'"`
}
Subquery represents a subquery expression
type SubqueryWithAlias ¶
type SubqueryWithAlias struct {
Subquery SelectStatement `parser:"'(' @@ ')'"`
Alias *string `parser:"('AS' @(Ident | BacktickIdent))?"`
}
SubqueryWithAlias represents a subquery with optional alias
type TTLClause ¶
type TTLClause struct {
TTL string `parser:"'TTL'"`
Expression Expression `parser:"@@"`
}
TTLClause represents column-level TTL specification
type TTLDelete ¶
type TTLDelete struct {
Delete string `parser:"'DELETE'"`
Where *Expression `parser:"('WHERE' @@)?"`
}
TTLDelete represents DELETE clause in TTL
type TableAlias ¶
type TableAlias struct {
Name *string `parser:"'AS' @(Ident | BacktickIdent)"`
}
TableAlias represents a table alias - requires explicit AS keyword
type TableClause ¶
type TableClause struct {
LeadingComments []string `parser:"@(Comment | MultilineComment)*"`
OrderBy *OrderByClause `parser:"@@"`
PartitionBy *PartitionByClause `parser:"| @@"`
PrimaryKey *PrimaryKeyClause `parser:"| @@"`
SampleBy *SampleByClause `parser:"| @@"`
TTL *TableTTLClause `parser:"| @@"`
Settings *TableSettingsClause `parser:"| @@"`
TrailingComments []string `parser:"@(Comment | MultilineComment)*"`
}
TableClause represents any clause that can appear after ENGINE in a CREATE TABLE statement This allows clauses to be specified in any order
type TableElement ¶
type TableElement struct {
Index *IndexDefinition `parser:"@@"`
Constraint *ConstraintDefinition `parser:"| @@"`
Projection *ProjectionDefinition `parser:"| @@"`
Column *Column `parser:"| @@"`
}
TableElement represents an element within table definition (column, index, constraint, or projection)
type TableEngine ¶
type TableEngine struct {
Engine string `parser:"'ENGINE' '='"`
Name string `parser:"@(Ident | BacktickIdent)"`
Parameters []EngineParameter `parser:"('(' (@@ (',' @@)*)? ')')?"`
TrailingComments []string `parser:"@(Comment | MultilineComment)*"`
}
TableEngine represents the ENGINE clause for tables Examples: ENGINE = MergeTree(), ENGINE = ReplicatedMergeTree('/path', 'replica')
func (*TableEngine) Equal ¶ added in v0.1.3
func (t *TableEngine) Equal(other *TableEngine) bool
Equal compares two TableEngine instances for equality
func (*TableEngine) String ¶ added in v0.1.9
func (e *TableEngine) String() string
String returns the SQL representation of a table engine.
type TableFunction ¶
type TableFunction struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Arguments []FunctionArg `parser:"'(' (@@ (',' @@)*)? ')'"`
}
TableFunction represents table functions like numbers(), remote(), etc.
type TableNameWithAlias ¶
type TableNameWithAlias struct {
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Table string `parser:"@(Ident | BacktickIdent)"`
ExplicitAlias *TableAlias `parser:"@@?"`
ImplicitAlias *string `parser:"| @(Ident | BacktickIdent)"`
}
TableNameWithAlias represents a table name with optional alias
type TableRef ¶
type TableRef struct {
// Try table function first (has parentheses to distinguish it)
Function *FunctionWithAlias `parser:"@@"`
// OR subquery with optional alias
Subquery *SubqueryWithAlias `parser:"| @@"`
// Fall back to table reference if no function call syntax found
TableName *TableNameWithAlias `parser:"| @@"`
}
TableRef represents a table reference (table, subquery, or function)
type TableReference ¶ added in v0.1.3
type TableReference struct {
Database *string `parser:"(@(Ident | BacktickIdent) '.')?"`
Table string `parser:"@(Ident | BacktickIdent)"`
}
TableReference represents a reference to a table in AS clause Format: [db.]table_name
type TableRename ¶
type TableRename struct {
FromDatabase *string `parser:"(@(Ident | BacktickIdent) '.')?"`
FromName string `parser:"@(Ident | BacktickIdent)"`
To string `parser:"'TO'"`
ToDatabase *string `parser:"(@(Ident | BacktickIdent) '.')?"`
ToName string `parser:"@(Ident | BacktickIdent)"`
}
TableRename represents a single table rename operation
type TableSetting ¶
type TableSetting struct {
Name string `parser:"@(Ident | BacktickIdent)"`
Eq string `parser:"'='"`
Value string `parser:"@(String | Number | Ident | BacktickIdent)"`
}
TableSetting represents a single setting in SETTINGS clause
type TableSettingsClause ¶
type TableSettingsClause struct {
Settings []TableSetting `parser:"'SETTINGS' @@ (',' @@)*"`
}
TableSettingsClause represents SETTINGS clause
type TableSource ¶ added in v0.1.4
type TableSource struct {
// Try table function first (has parentheses to distinguish it)
Function *TableFunction `parser:"@@"`
// Fall back to table reference if no function call syntax found
TableRef *TableReference `parser:"| @@"`
}
TableSource represents either a table reference or a table function in AS clause Can be either:
- Simple table reference: [db.]table_name
- Table function: functionName(args...)
Examples:
- AS users
- AS analytics.events
- AS remote('host:9000', 'db', 'table')
- AS s3Table('https://bucket.s3.amazonaws.com/file.csv', 'CSV')
- AS numbers(1000000)
type TableTTLClause ¶
type TableTTLClause struct {
TTL string `parser:"'TTL'"`
Expression Expression `parser:"@@"`
}
TableTTLClause represents table-level TTL expression
func (*TableTTLClause) Equal ¶ added in v0.1.3
func (t *TableTTLClause) Equal(other *TableTTLClause) bool
Equal compares two TableTTLClause instances for equality
type TopLevelSelectStatement ¶
type TopLevelSelectStatement struct {
SelectStatement
Semicolon bool `parser:"';'"`
}
TopLevelSelectStatement represents a top-level SELECT statement (requires semicolon)
type TrailingCommentField ¶ added in v0.1.9
type TrailingCommentField struct {
TrailingComments []string `parser:"@(Comment | MultilineComment)*"`
}
TrailingCommentField provides trailing comment support for statements. This is embedded near the end of statement structs (before Semicolon) to capture comments that appear after the statement body.
func (*TrailingCommentField) GetTrailingComments ¶ added in v0.1.9
func (c *TrailingCommentField) GetTrailingComments() []string
GetTrailingComments returns the trailing comments.
type TupleElement ¶
type TupleElement struct {
// Try to parse name + type first, then fall back to just type
Name *string `parser:"@(Ident | BacktickIdent)"`
Type *DataType `parser:"@@"`
// For unnamed tuples, we just have the type
UnnamedType *DataType `parser:"| @@"`
}
TupleElement represents a single element in a tuple, which can be named or unnamed
func (*TupleElement) String ¶ added in v0.1.9
func (e *TupleElement) String() string
String returns the SQL representation of a tuple element.
type TupleExpression ¶
type TupleExpression struct {
Elements []Expression `parser:"'(' (@@ (',' @@)*)? ')'"`
}
TupleExpression represents tuple literals
func (*TupleExpression) String ¶
func (t *TupleExpression) String() string
type TupleType ¶
type TupleType struct {
Tuple string `parser:"'Tuple' '('"`
Elements []TupleElement `parser:"@@ (',' @@)*"`
Close string `parser:"')'"`
}
TupleType represents Tuple(T1, T2, ...) or named Tuple(name1 T1, name2 T2, ...)
func (*TupleType) Equal ¶ added in v0.1.7
func (t *TupleType) Equal(other DataTypeComparable) bool
Equal compares two TupleType instances
type TypeParameter ¶
type TypeParameter struct {
Function *ParametricFunction `parser:"@@"`
Number *string `parser:"| @Number"`
String *string `parser:"| @String"`
Ident *string `parser:"| @(Ident | BacktickIdent)"`
}
TypeParameter represents a parameter in a parametric type (can be number, identifier, string, or nested function call)
func (*TypeParameter) Equal ¶ added in v0.1.3
func (t *TypeParameter) Equal(other *TypeParameter) bool
Equal compares two TypeParameter instances for equality
type UnaryExpression ¶
type UnaryExpression struct {
Op string `parser:"@('+' | '-')?"`
Primary *PrimaryExpression `parser:"@@"`
}
UnaryExpression handles unary operators
func (*UnaryExpression) Equal ¶ added in v0.1.3
func (u *UnaryExpression) Equal(other *UnaryExpression) bool
Equal compares two Unary expressions
func (*UnaryExpression) String ¶
func (u *UnaryExpression) String() string
type UpdateOperation ¶
type UpdateOperation struct {
Update string `parser:"'UPDATE'"`
Column string `parser:"@(Ident | BacktickIdent)"`
Eq string `parser:"'='"`
Expression Expression `parser:"@@"`
Where *Expression `parser:"('WHERE' @@)?"`
}
UpdateOperation represents UPDATE operation
type ViewEngine ¶
type ViewEngine struct {
Engine string `parser:"'ENGINE' '='"`
Name string `parser:"@(Ident | BacktickIdent)"`
Parameters []EngineParameter `parser:"('(' (@@ (',' @@)*)? ')')?"`
OrderBy *ViewOrderBy `parser:"@@?"`
PartitionBy *ViewPartitionBy `parser:"@@?"`
PrimaryKey *ViewPrimaryKey `parser:"@@?"`
SampleBy *ViewSampleBy `parser:"@@?"`
}
ViewEngine represents ENGINE = clause for materialized views. Materialized views can have ENGINE clauses with additional DDL like ORDER BY. We structure this similar to table engines but with optional materialized view specific clauses.
type ViewOrderBy ¶
type ViewOrderBy struct {
OrderBy string `parser:"'ORDER' 'BY'"`
Expression Expression `parser:"@@"`
}
ViewOrderBy represents ORDER BY in materialized view ENGINE clause
type ViewPartitionBy ¶
type ViewPartitionBy struct {
PartitionBy string `parser:"'PARTITION' 'BY'"`
Expression Expression `parser:"@@"`
}
ViewPartitionBy represents PARTITION BY in materialized view ENGINE clause
type ViewPrimaryKey ¶
type ViewPrimaryKey struct {
PrimaryKey string `parser:"'PRIMARY' 'KEY'"`
Expression Expression `parser:"@@"`
}
ViewPrimaryKey represents PRIMARY KEY in materialized view ENGINE clause
type ViewSampleBy ¶
type ViewSampleBy struct {
SampleBy string `parser:"'SAMPLE' 'BY'"`
Expression Expression `parser:"@@"`
}
ViewSampleBy represents SAMPLE BY in materialized view ENGINE clause
type ViewTableTarget ¶ added in v0.1.4
type ViewTableTarget struct {
// Try table function first (has parentheses to distinguish it)
Function *TableFunction `parser:"@@"`
// Fall back to table reference if no function call syntax found
Database *string `parser:"| ((@(Ident | BacktickIdent) '.')?"`
Table *string `parser:"@(Ident | BacktickIdent))"`
}
ViewTableTarget represents a table target in TO clause of materialized view Can be either:
- Simple table reference: [db.]table_name
- Table function: functionName(args...)
type WhenClause ¶
type WhenClause struct {
When string `parser:"'WHEN'"`
Condition string `parser:"@(~'THEN')+"`
Then string `parser:"'THEN'"`
Result string `parser:"@(~('WHEN' | 'ELSE' | 'END'))+"`
}
WhenClause represents WHEN condition THEN result Using simpler parsing to avoid recursion issues during debugging
type WhereClause ¶
type WhereClause struct {
Where string `parser:"'WHERE'"`
Condition Expression `parser:"@@"`
}
WhereClause represents WHERE clause
type WindowFrame ¶
type WindowFrame struct {
Type string `parser:"@('ROWS' | 'RANGE')"`
Between bool `parser:"@'BETWEEN'?"`
Start FrameBound `parser:"@@"`
End *FrameBound `parser:"('AND' @@)?"`
}
WindowFrame for window functions
func (*WindowFrame) String ¶
func (w *WindowFrame) String() string
String returns the string representation of a WindowFrame for window functions
type WithClause ¶
type WithClause struct {
With string `parser:"'WITH'"`
CTEs []CommonTableExpression `parser:"@@ (',' @@)*"`
}
WithClause represents WITH clause for CTEs