Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 17, 2025

This PR implements comprehensive support for ClickHouse CREATE DICTIONARY statements based on the official ClickHouse grammar specification.

Features Implemented

Core Syntax Support

  • CREATE [OR REPLACE] DICTIONARY [IF NOT EXISTS] name [UUID 'uuid'] [ON CLUSTER cluster]
  • Full dictionary schema with attribute definitions and properties
  • All dictionary engine clauses with proper validation

Dictionary Attributes

  • Basic attribute definition: name Type
  • DEFAULT literal - default value for attribute
  • EXPRESSION columnExpr - computed attribute expression
  • HIERARCHICAL - hierarchical dictionary attribute
  • INJECTIVE - injective mapping attribute
  • IS_OBJECT_ID - object ID attribute
  • Support for multiple properties per attribute

Dictionary Engine Clauses

  • PRIMARY KEY columnExprList - optional primary key definition
  • SOURCE(sourceName(args...)) - required data source configuration
  • LIFETIME(value) or LIFETIME(MIN min MAX max) - cache lifetime
  • LAYOUT(layoutName(args...)) - dictionary layout configuration
  • RANGE(MIN minCol MAX maxCol) - range dictionary configuration
  • SETTINGS(name=value, ...) - dictionary-specific settings with parentheses

Examples

Basic Dictionary

CREATE DICTIONARY test.my_dict (
    id UInt64,
    name String DEFAULT '',
    value Float64 EXPRESSION toFloat64OrZero(name)
)
PRIMARY KEY id
SOURCE(MYSQL(host 'localhost' port 3306 db 'test' table 'data'))
LIFETIME(MIN 1000 MAX 2000)
LAYOUT(HASHED())
SETTINGS(max_block_size = 8192);

Complex Dictionary with All Features

CREATE OR REPLACE DICTIONARY test.complex_dict 
UUID '12345678-1234-1234-1234-123456789012'
ON CLUSTER production_cluster
(
    id UInt64 HIERARCHICAL INJECTIVE,
    name String DEFAULT '' EXPRESSION toString(id),
    object_id UInt64 IS_OBJECT_ID
)
PRIMARY KEY id
SOURCE(MYSQL(host 'localhost' port 3306 user 'root' password 'secret'))
LIFETIME(MIN 600 MAX 1200)
LAYOUT(CACHE(size_in_cells 1000))
RANGE(MIN start_date MAX end_date)
SETTINGS(max_block_size=8192, max_insert_block_size=1048576);

Implementation Details

  • Added CreateDictionary AST node with complete visitor support
  • Implemented dictionary-specific parsing functions for all clauses
  • Added proper string formatting that maintains ClickHouse compatibility
  • Integrated into existing DDL parser infrastructure
  • Added comprehensive test coverage with golden file validation

Testing

  • ✅ Comprehensive parsing tests for all dictionary features
  • ✅ Round-trip formatting validation (parse → format → parse)
  • ✅ Complex real-world dictionary examples
  • ✅ All existing tests continue to pass

Fixes #12.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Add the support of CREATE DICTIONARY Add support for CREATE DICTIONARY statement Jul 17, 2025
@Copilot Copilot AI requested a review from git-hulk July 17, 2025 12:25
Copilot finished work on behalf of git-hulk July 17, 2025 12:25
@git-hulk git-hulk marked this pull request as ready for review July 17, 2025 14:13
@git-hulk git-hulk merged commit b84b7e1 into master Jul 17, 2025
1 check passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 16347549962

Details

  • 503 of 929 (54.14%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.7%) to 63.224%

Changes Missing Coverage Covered Lines Changed/Added Lines %
parser/ast_visitor.go 27 50 54.0%
parser/ast.go 221 396 55.81%
parser/parser_table.go 255 483 52.8%
Files with Coverage Reduction New Missed Lines %
parser/parser_table.go 1 65.22%
Totals Coverage Status
Change from base Build 16210909526: -0.7%
Covered Lines: 8092
Relevant Lines: 12799

💛 - Coveralls

Copilot finished work on behalf of git-hulk July 17, 2025 14:19
@Copilot Copilot AI requested a review from git-hulk July 17, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the support of CREATE DICTIONARY
3 participants