Skip to content

Commit 2186056

Browse files
committed
Add CREATE/ALTER ROUTE statement option parsing
- Add Owner and RouteOptions fields to CreateRouteStatement - Add RouteOptions field to AlterRouteStatement - Add RouteOption AST type for route options - Parse WITH clause options: BROKER_INSTANCE, SERVICE_NAME, LIFETIME, ADDRESS, MIRROR_ADDRESS - Parse AUTHORIZATION clause for route ownership
1 parent 7fb18c5 commit 2186056

File tree

7 files changed

+143
-8
lines changed

7 files changed

+143
-8
lines changed

ast/alter_simple_statements.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package ast
22

33
// AlterRouteStatement represents an ALTER ROUTE statement.
44
type AlterRouteStatement struct {
5-
Name *Identifier `json:"Name,omitempty"`
5+
Name *Identifier `json:"Name,omitempty"`
6+
RouteOptions []*RouteOption `json:"RouteOptions,omitempty"`
67
}
78

89
func (s *AlterRouteStatement) node() {}

ast/create_simple_statements.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,22 @@ func (s *CreateQueueStatement) statement() {}
8585

8686
// CreateRouteStatement represents a CREATE ROUTE statement.
8787
type CreateRouteStatement struct {
88-
Name *Identifier `json:"Name,omitempty"`
88+
Name *Identifier `json:"Name,omitempty"`
89+
Owner *Identifier `json:"Owner,omitempty"`
90+
RouteOptions []*RouteOption `json:"RouteOptions,omitempty"`
8991
}
9092

9193
func (s *CreateRouteStatement) node() {}
9294
func (s *CreateRouteStatement) statement() {}
9395

96+
// RouteOption represents an option in CREATE/ALTER ROUTE statement.
97+
type RouteOption struct {
98+
OptionKind string `json:"OptionKind,omitempty"`
99+
Literal ScalarExpression `json:"Literal,omitempty"`
100+
}
101+
102+
func (r *RouteOption) node() {}
103+
94104
// CreateEndpointStatement represents a CREATE ENDPOINT statement.
95105
type CreateEndpointStatement struct {
96106
Name *Identifier `json:"Name,omitempty"`

parser/marshal.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9137,6 +9137,13 @@ func alterRouteStatementToJSON(s *ast.AlterRouteStatement) jsonNode {
91379137
if s.Name != nil {
91389138
node["Name"] = identifierToJSON(s.Name)
91399139
}
9140+
if len(s.RouteOptions) > 0 {
9141+
opts := make([]jsonNode, len(s.RouteOptions))
9142+
for i, opt := range s.RouteOptions {
9143+
opts[i] = routeOptionToJSON(opt)
9144+
}
9145+
node["RouteOptions"] = opts
9146+
}
91409147
return node
91419148
}
91429149

@@ -9933,9 +9940,30 @@ func createRouteStatementToJSON(s *ast.CreateRouteStatement) jsonNode {
99339940
node := jsonNode{
99349941
"$type": "CreateRouteStatement",
99359942
}
9943+
if s.Owner != nil {
9944+
node["Owner"] = identifierToJSON(s.Owner)
9945+
}
99369946
if s.Name != nil {
99379947
node["Name"] = identifierToJSON(s.Name)
99389948
}
9949+
if len(s.RouteOptions) > 0 {
9950+
opts := make([]jsonNode, len(s.RouteOptions))
9951+
for i, opt := range s.RouteOptions {
9952+
opts[i] = routeOptionToJSON(opt)
9953+
}
9954+
node["RouteOptions"] = opts
9955+
}
9956+
return node
9957+
}
9958+
9959+
func routeOptionToJSON(opt *ast.RouteOption) jsonNode {
9960+
node := jsonNode{
9961+
"$type": "RouteOption",
9962+
"OptionKind": opt.OptionKind,
9963+
}
9964+
if opt.Literal != nil {
9965+
node["Literal"] = scalarExpressionToJSON(opt.Literal)
9966+
}
99399967
return node
99409968
}
99419969

parser/parse_ddl.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,8 +3854,16 @@ func (p *Parser) parseAlterRouteStatement() (*ast.AlterRouteStatement, error) {
38543854
// Parse route name
38553855
stmt.Name = p.parseIdentifier()
38563856

3857-
// Skip rest of statement
3858-
p.skipToEndOfStatement()
3857+
// Parse WITH clause
3858+
if p.curTok.Type == TokenWith {
3859+
p.nextToken() // consume WITH
3860+
stmt.RouteOptions = p.parseRouteOptions()
3861+
}
3862+
3863+
// Skip optional semicolon
3864+
if p.curTok.Type == TokenSemicolon {
3865+
p.nextToken()
3866+
}
38593867

38603868
return stmt, nil
38613869
}

parser/parse_statements.go

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7551,11 +7551,99 @@ func (p *Parser) parseCreateRouteStatement() (*ast.CreateRouteStatement, error)
75517551
Name: p.parseIdentifier(),
75527552
}
75537553

7554-
// Skip rest of statement
7555-
p.skipToEndOfStatement()
7554+
// Parse optional AUTHORIZATION clause
7555+
if strings.ToUpper(p.curTok.Literal) == "AUTHORIZATION" {
7556+
p.nextToken() // consume AUTHORIZATION
7557+
stmt.Owner = p.parseIdentifier()
7558+
}
7559+
7560+
// Parse WITH clause
7561+
if p.curTok.Type == TokenWith {
7562+
p.nextToken() // consume WITH
7563+
stmt.RouteOptions = p.parseRouteOptions()
7564+
}
7565+
7566+
// Skip optional semicolon
7567+
if p.curTok.Type == TokenSemicolon {
7568+
p.nextToken()
7569+
}
7570+
75567571
return stmt, nil
75577572
}
75587573

7574+
func (p *Parser) parseRouteOptions() []*ast.RouteOption {
7575+
var options []*ast.RouteOption
7576+
7577+
for p.curTok.Type != TokenSemicolon && p.curTok.Type != TokenEOF {
7578+
optionName := strings.ToUpper(p.curTok.Literal)
7579+
p.nextToken() // consume option name
7580+
7581+
if p.curTok.Type == TokenEquals {
7582+
p.nextToken() // consume =
7583+
}
7584+
7585+
var optionKind string
7586+
switch optionName {
7587+
case "BROKER_INSTANCE":
7588+
optionKind = "BrokerInstance"
7589+
case "SERVICE_NAME":
7590+
optionKind = "ServiceName"
7591+
case "LIFETIME":
7592+
optionKind = "Lifetime"
7593+
case "ADDRESS":
7594+
optionKind = "Address"
7595+
case "MIRROR_ADDRESS":
7596+
optionKind = "MirrorAddress"
7597+
default:
7598+
// Unknown option, skip
7599+
if p.curTok.Type == TokenComma {
7600+
p.nextToken()
7601+
}
7602+
continue
7603+
}
7604+
7605+
// Parse literal value
7606+
var literal ast.ScalarExpression
7607+
if p.curTok.Type == TokenString {
7608+
value := p.curTok.Literal
7609+
// Strip quotes
7610+
if len(value) >= 2 && value[0] == '\'' && value[len(value)-1] == '\'' {
7611+
value = value[1 : len(value)-1]
7612+
}
7613+
literal = &ast.StringLiteral{
7614+
LiteralType: "String",
7615+
Value: value,
7616+
}
7617+
p.nextToken()
7618+
} else if p.curTok.Type == TokenNumber {
7619+
literal = &ast.IntegerLiteral{
7620+
LiteralType: "Integer",
7621+
Value: p.curTok.Literal,
7622+
}
7623+
p.nextToken()
7624+
} else {
7625+
// Unknown value, try to skip
7626+
p.nextToken()
7627+
}
7628+
7629+
if literal != nil {
7630+
options = append(options, &ast.RouteOption{
7631+
OptionKind: optionKind,
7632+
Literal: literal,
7633+
})
7634+
}
7635+
7636+
// Skip comma if present
7637+
if p.curTok.Type == TokenComma {
7638+
p.nextToken()
7639+
} else {
7640+
break
7641+
}
7642+
}
7643+
7644+
return options
7645+
}
7646+
75597647
func (p *Parser) parseCreateEndpointStatement() (*ast.CreateEndpointStatement, error) {
75607648
p.nextToken() // consume ENDPOINT
75617649

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
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)