From ad9a8879253aba79d9b306eb1c7eba879479fc11 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 13:02:05 +0000 Subject: [PATCH] Parse ALTER QUOTA and plural SHOW CREATE QUOTA ALTER QUOTA now goes through the CREATE QUOTA parser, which matches the CreateQuotaQuery node ClickHouse prints for both. SHOW CREATE QUOTA with more than one name prints as SHOW CREATE QUOTAS. Clears all 24 todo statements in 01297_create_quota. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs --- ast/ast.go | 1 + internal/explain/explain.go | 8 +++-- parser/parser.go | 13 +++++++++ .../testdata/01297_create_quota/metadata.json | 29 +------------------ 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index ff7d21f7e0..23cdf4144b 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -1164,6 +1164,7 @@ func (s *ShowPrivilegesQuery) statementNode() {} type ShowCreateQuotaQuery struct { Position token.Position `json:"-"` Name string `json:"name,omitempty"` + Plural bool `json:"plural,omitempty"` // more than one name was given Format string `json:"format,omitempty"` } diff --git a/internal/explain/explain.go b/internal/explain/explain.go index b12ea07efc..3bef1c5a4a 100644 --- a/internal/explain/explain.go +++ b/internal/explain/explain.go @@ -205,11 +205,15 @@ func Node(sb *strings.Builder, node interface{}, depth int) { case *ast.ShowPrivilegesQuery: fmt.Fprintf(sb, "%sShowPrivilegesQuery\n", indent) case *ast.ShowCreateQuotaQuery: + kw := "QUOTA" + if n.Plural { + kw = "QUOTAS" + } if n.Format != "" { - fmt.Fprintf(sb, "%sSHOW CREATE QUOTA query (children 1)\n", indent) + fmt.Fprintf(sb, "%sSHOW CREATE %s query (children 1)\n", indent, kw) fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Format) } else { - fmt.Fprintf(sb, "%sSHOW CREATE QUOTA query\n", indent) + fmt.Fprintf(sb, "%sSHOW CREATE %s query\n", indent, kw) } case *ast.CreateQuotaQuery: fmt.Fprintf(sb, "%sCreateQuotaQuery\n", indent) diff --git a/parser/parser.go b/parser/parser.go index 9859100e93..8462c8b93d 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -304,6 +304,12 @@ func (p *Parser) parseStatement() ast.Statement { if p.peek.Token == token.IDENT && strings.ToUpper(p.peek.Value) == "ROLE" { return p.parseAlterRole() } + // ALTER QUOTA is printed like CREATE QUOTA + if p.peek.Token == token.IDENT && strings.ToUpper(p.peek.Value) == "QUOTA" { + pos := p.current.Pos + p.nextToken() + return p.parseCreateQuota(pos) + } // ALTER HANDLER is printed like CREATE HANDLER if p.peek.Token == token.IDENT && strings.ToUpper(p.peek.Value) == "HANDLER" { pos := p.current.Pos @@ -7506,6 +7512,13 @@ func (p *Parser) parseShow() ast.Statement { query.Name = p.current.Value p.nextToken() } + for p.currentIs(token.COMMA) { + query.Plural = true + p.nextToken() + if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() { + p.nextToken() + } + } // Parse FORMAT clause if present if p.currentIs(token.FORMAT) { p.nextToken() diff --git a/parser/testdata/01297_create_quota/metadata.json b/parser/testdata/01297_create_quota/metadata.json index 85756f90e5..0967ef424b 100644 --- a/parser/testdata/01297_create_quota/metadata.json +++ b/parser/testdata/01297_create_quota/metadata.json @@ -1,28 +1 @@ -{ - "explain_todo": { - "stmt104": true, - "stmt105": true, - "stmt106": true, - "stmt16": true, - "stmt247": true, - "stmt249": true, - "stmt252": true, - "stmt254": true, - "stmt256": true, - "stmt260": true, - "stmt279": true, - "stmt280": true, - "stmt285": true, - "stmt288": true, - "stmt45": true, - "stmt46": true, - "stmt47": true, - "stmt69": true, - "stmt70": true, - "stmt71": true, - "stmt72": true, - "stmt73": true, - "stmt97": true, - "stmt98": true - } -} +{}