Skip to content

Commit 555b1e4

Browse files
committed
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.
1 parent 0076eee commit 555b1e4

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

ast/ast.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,16 @@ func (s *ShowPrivilegesQuery) Pos() token.Position { return s.Position }
629629
func (s *ShowPrivilegesQuery) End() token.Position { return s.Position }
630630
func (s *ShowPrivilegesQuery) statementNode() {}
631631

632+
// ShowCreateQuotaQuery represents a SHOW CREATE QUOTA statement.
633+
type ShowCreateQuotaQuery struct {
634+
Position token.Position `json:"-"`
635+
Name string `json:"name,omitempty"`
636+
}
637+
638+
func (s *ShowCreateQuotaQuery) Pos() token.Position { return s.Position }
639+
func (s *ShowCreateQuotaQuery) End() token.Position { return s.Position }
640+
func (s *ShowCreateQuotaQuery) statementNode() {}
641+
632642
// -----------------------------------------------------------------------------
633643
// Expressions
634644

internal/explain/explain.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ func Node(sb *strings.Builder, node interface{}, depth int) {
117117
explainShowQuery(sb, n, indent)
118118
case *ast.ShowPrivilegesQuery:
119119
fmt.Fprintf(sb, "%sShowPrivilegesQuery\n", indent)
120+
case *ast.ShowCreateQuotaQuery:
121+
fmt.Fprintf(sb, "%sSHOW CREATE QUOTA query\n", indent)
120122
case *ast.UseQuery:
121123
explainUseQuery(sb, n, indent)
122124
case *ast.DescribeQuery:

parser/parser.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,16 +2642,20 @@ func (p *Parser) parseShow() ast.Statement {
26422642
if p.currentIs(token.DATABASE) {
26432643
show.ShowType = ast.ShowCreateDB
26442644
p.nextToken()
2645+
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA" {
2646+
// SHOW CREATE QUOTA <name>
2647+
p.nextToken()
2648+
name := ""
2649+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
2650+
name = p.current.Value
2651+
p.nextToken()
2652+
}
2653+
return &ast.ShowCreateQuotaQuery{Position: pos, Name: name}
26452654
} else {
26462655
show.ShowType = ast.ShowCreate
2647-
// Handle SHOW CREATE TABLE, SHOW CREATE QUOTA, etc.
2656+
// Handle SHOW CREATE TABLE, etc.
26482657
if p.currentIs(token.TABLE) {
26492658
p.nextToken()
2650-
} else if p.currentIs(token.DEFAULT) || (p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA") {
2651-
// SHOW CREATE QUOTA default - skip QUOTA keyword
2652-
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "QUOTA" {
2653-
p.nextToken()
2654-
}
26552659
}
26562660
}
26572661
case token.SETTINGS:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)