From 555b1e43332a460b064e7a36d1da6c4e4198f29b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 24 Dec 2025 20:52:28 +0000 Subject: [PATCH] Add SHOW CREATE QUOTA statement parsing Add ShowCreateQuotaQuery AST node to properly handle SHOW CREATE QUOTA statements. The EXPLAIN output format is "SHOW CREATE QUOTA query" to match ClickHouse's expected output. --- ast/ast.go | 10 ++++++++++ internal/explain/explain.go | 2 ++ parser/parser.go | 16 ++++++++++------ parser/testdata/01033_quota_dcl/metadata.json | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index 8fef5608e6..cb4cb5f633 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -629,6 +629,16 @@ func (s *ShowPrivilegesQuery) Pos() token.Position { return s.Position } func (s *ShowPrivilegesQuery) End() token.Position { return s.Position } func (s *ShowPrivilegesQuery) statementNode() {} +// ShowCreateQuotaQuery represents a SHOW CREATE QUOTA statement. +type ShowCreateQuotaQuery struct { + Position token.Position `json:"-"` + Name string `json:"name,omitempty"` +} + +func (s *ShowCreateQuotaQuery) Pos() token.Position { return s.Position } +func (s *ShowCreateQuotaQuery) End() token.Position { return s.Position } +func (s *ShowCreateQuotaQuery) statementNode() {} + // ----------------------------------------------------------------------------- // Expressions diff --git a/internal/explain/explain.go b/internal/explain/explain.go index 419abd4f04..496e799840 100644 --- a/internal/explain/explain.go +++ b/internal/explain/explain.go @@ -117,6 +117,8 @@ func Node(sb *strings.Builder, node interface{}, depth int) { explainShowQuery(sb, n, indent) case *ast.ShowPrivilegesQuery: fmt.Fprintf(sb, "%sShowPrivilegesQuery\n", indent) + case *ast.ShowCreateQuotaQuery: + fmt.Fprintf(sb, "%sSHOW CREATE QUOTA query\n", indent) case *ast.UseQuery: explainUseQuery(sb, n, indent) case *ast.DescribeQuery: diff --git a/parser/parser.go b/parser/parser.go index f5657a4f3c..ca36230c94 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -2642,16 +2642,20 @@ func (p *Parser) parseShow() ast.Statement { if p.currentIs(token.DATABASE) { show.ShowType = ast.ShowCreateDB p.nextToken() + } else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA" { + // SHOW CREATE QUOTA + p.nextToken() + name := "" + if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() { + name = p.current.Value + p.nextToken() + } + return &ast.ShowCreateQuotaQuery{Position: pos, Name: name} } else { show.ShowType = ast.ShowCreate - // Handle SHOW CREATE TABLE, SHOW CREATE QUOTA, etc. + // Handle SHOW CREATE TABLE, etc. if p.currentIs(token.TABLE) { p.nextToken() - } else if p.currentIs(token.DEFAULT) || (p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA") { - // SHOW CREATE QUOTA default - skip QUOTA keyword - if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA" { - p.nextToken() - } } } case token.SETTINGS: diff --git a/parser/testdata/01033_quota_dcl/metadata.json b/parser/testdata/01033_quota_dcl/metadata.json index ef120d978e..9e26dfeeb6 100644 --- a/parser/testdata/01033_quota_dcl/metadata.json +++ b/parser/testdata/01033_quota_dcl/metadata.json @@ -1 +1 @@ -{"todo": true} +{} \ No newline at end of file