Skip to content

Commit d7b6e81

Browse files
kyleconroyclaude
andcommitted
Parse ON CLUSTER before column definitions in CREATE MATERIALIZED VIEW
ClickHouse allows ON CLUSTER to appear either before or after column definitions in CREATE MATERIALIZED VIEW statements. The parser was only checking after column definitions, causing parsing failures for syntax like: CREATE MATERIALIZED VIEW v ON CLUSTER c (x Int) ENGINE=... Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5bb6e5e commit d7b6e81

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

parser/parser.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,15 @@ func (p *Parser) parseCreateView(create *ast.CreateQuery) {
28072807
}
28082808
}
28092809

2810+
// Handle ON CLUSTER (can appear before or after column definitions)
2811+
if p.currentIs(token.ON) {
2812+
p.nextToken()
2813+
if p.currentIs(token.CLUSTER) {
2814+
p.nextToken()
2815+
create.OnCluster = p.parseIdentifierName()
2816+
}
2817+
}
2818+
28102819
// Parse column definitions (e.g., CREATE VIEW v (x UInt64) AS SELECT ...)
28112820
// For MATERIALIZED VIEW, this can also include INDEX, PROJECTION, and PRIMARY KEY
28122821
if p.currentIs(token.LPAREN) {
@@ -2850,8 +2859,8 @@ func (p *Parser) parseCreateView(create *ast.CreateQuery) {
28502859
p.expect(token.RPAREN)
28512860
}
28522861

2853-
// Handle ON CLUSTER
2854-
if p.currentIs(token.ON) {
2862+
// Handle ON CLUSTER (if it appears after column definitions instead of before)
2863+
if create.OnCluster == "" && p.currentIs(token.ON) {
28552864
p.nextToken()
28562865
if p.currentIs(token.CLUSTER) {
28572866
p.nextToken()
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)