Skip to content

Commit 69aba48

Browse files
committed
Add DROP SEQUENCE/SEARCH PROPERTY LIST/SERVER ROLE/AVAILABILITY GROUP/FEDERATION
- Create AST types for all 5 DROP statements - Add parsing functions for each DROP statement type - Add JSON marshaling for each DROP statement type - Enable DropStatementsTests110 (2 tests) Tests now at 147 passing (up from 145).
1 parent 17bdd99 commit 69aba48

File tree

8 files changed

+248
-2
lines changed

8 files changed

+248
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// DropAvailabilityGroupStatement represents a DROP AVAILABILITY GROUP statement.
4+
type DropAvailabilityGroupStatement struct {
5+
Name *Identifier
6+
IsIfExists bool
7+
}
8+
9+
func (d *DropAvailabilityGroupStatement) node() {}
10+
func (d *DropAvailabilityGroupStatement) statement() {}

ast/drop_federation_statement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// DropFederationStatement represents a DROP FEDERATION statement.
4+
type DropFederationStatement struct {
5+
Name *Identifier
6+
IsIfExists bool
7+
}
8+
9+
func (d *DropFederationStatement) node() {}
10+
func (d *DropFederationStatement) statement() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// DropSearchPropertyListStatement represents a DROP SEARCH PROPERTY LIST statement.
4+
type DropSearchPropertyListStatement struct {
5+
Name *Identifier
6+
IsIfExists bool
7+
}
8+
9+
func (d *DropSearchPropertyListStatement) node() {}
10+
func (d *DropSearchPropertyListStatement) statement() {}

ast/drop_sequence_statement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// DropSequenceStatement represents a DROP SEQUENCE statement.
4+
type DropSequenceStatement struct {
5+
Objects []*SchemaObjectName
6+
IsIfExists bool
7+
}
8+
9+
func (d *DropSequenceStatement) node() {}
10+
func (d *DropSequenceStatement) statement() {}

ast/drop_server_role_statement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// DropServerRoleStatement represents a DROP SERVER ROLE statement.
4+
type DropServerRoleStatement struct {
5+
Name *Identifier
6+
IsIfExists bool
7+
}
8+
9+
func (d *DropServerRoleStatement) node() {}
10+
func (d *DropServerRoleStatement) statement() {}

parser/parser.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@ func (p *Parser) parseDropStatement() (ast.Statement, error) {
230230
return p.parseDropExternalStatement()
231231
}
232232

233+
// Handle keyword-based DROP statements
234+
switch strings.ToUpper(p.curTok.Literal) {
235+
case "SEQUENCE":
236+
return p.parseDropSequenceStatement()
237+
case "SEARCH":
238+
return p.parseDropSearchPropertyListStatement()
239+
case "SERVER":
240+
return p.parseDropServerRoleStatement()
241+
case "AVAILABILITY":
242+
return p.parseDropAvailabilityGroupStatement()
243+
case "FEDERATION":
244+
return p.parseDropFederationStatement()
245+
}
246+
233247
return nil, fmt.Errorf("unexpected token after DROP: %s", p.curTok.Literal)
234248
}
235249

@@ -338,6 +352,119 @@ func (p *Parser) parseDropCredentialStatement(isDatabaseScoped bool) (*ast.DropC
338352
return stmt, nil
339353
}
340354

355+
func (p *Parser) parseDropSequenceStatement() (*ast.DropSequenceStatement, error) {
356+
// Consume SEQUENCE
357+
p.nextToken()
358+
359+
stmt := &ast.DropSequenceStatement{}
360+
361+
// Parse comma-separated list of schema object names
362+
for {
363+
name, err := p.parseSchemaObjectName()
364+
if err != nil {
365+
return nil, err
366+
}
367+
stmt.Objects = append(stmt.Objects, name)
368+
369+
if p.curTok.Type == TokenComma {
370+
p.nextToken()
371+
} else {
372+
break
373+
}
374+
}
375+
376+
// Skip optional semicolon
377+
if p.curTok.Type == TokenSemicolon {
378+
p.nextToken()
379+
}
380+
381+
return stmt, nil
382+
}
383+
384+
func (p *Parser) parseDropSearchPropertyListStatement() (*ast.DropSearchPropertyListStatement, error) {
385+
// Consume SEARCH
386+
p.nextToken()
387+
388+
// Expect PROPERTY
389+
if strings.ToUpper(p.curTok.Literal) != "PROPERTY" {
390+
return nil, fmt.Errorf("expected PROPERTY after SEARCH, got %s", p.curTok.Literal)
391+
}
392+
p.nextToken()
393+
394+
// Expect LIST
395+
if strings.ToUpper(p.curTok.Literal) != "LIST" {
396+
return nil, fmt.Errorf("expected LIST after PROPERTY, got %s", p.curTok.Literal)
397+
}
398+
p.nextToken()
399+
400+
stmt := &ast.DropSearchPropertyListStatement{}
401+
stmt.Name = p.parseIdentifier()
402+
403+
// Skip optional semicolon
404+
if p.curTok.Type == TokenSemicolon {
405+
p.nextToken()
406+
}
407+
408+
return stmt, nil
409+
}
410+
411+
func (p *Parser) parseDropServerRoleStatement() (*ast.DropServerRoleStatement, error) {
412+
// Consume SERVER
413+
p.nextToken()
414+
415+
// Expect ROLE
416+
if strings.ToUpper(p.curTok.Literal) != "ROLE" {
417+
return nil, fmt.Errorf("expected ROLE after SERVER, got %s", p.curTok.Literal)
418+
}
419+
p.nextToken()
420+
421+
stmt := &ast.DropServerRoleStatement{}
422+
stmt.Name = p.parseIdentifier()
423+
424+
// Skip optional semicolon
425+
if p.curTok.Type == TokenSemicolon {
426+
p.nextToken()
427+
}
428+
429+
return stmt, nil
430+
}
431+
432+
func (p *Parser) parseDropAvailabilityGroupStatement() (*ast.DropAvailabilityGroupStatement, error) {
433+
// Consume AVAILABILITY
434+
p.nextToken()
435+
436+
// Expect GROUP
437+
if strings.ToUpper(p.curTok.Literal) != "GROUP" {
438+
return nil, fmt.Errorf("expected GROUP after AVAILABILITY, got %s", p.curTok.Literal)
439+
}
440+
p.nextToken()
441+
442+
stmt := &ast.DropAvailabilityGroupStatement{}
443+
stmt.Name = p.parseIdentifier()
444+
445+
// Skip optional semicolon
446+
if p.curTok.Type == TokenSemicolon {
447+
p.nextToken()
448+
}
449+
450+
return stmt, nil
451+
}
452+
453+
func (p *Parser) parseDropFederationStatement() (*ast.DropFederationStatement, error) {
454+
// Consume FEDERATION
455+
p.nextToken()
456+
457+
stmt := &ast.DropFederationStatement{}
458+
stmt.Name = p.parseIdentifier()
459+
460+
// Skip optional semicolon
461+
if p.curTok.Type == TokenSemicolon {
462+
p.nextToken()
463+
}
464+
465+
return stmt, nil
466+
}
467+
341468
func (p *Parser) parseAlterStatement() (ast.Statement, error) {
342469
// Consume ALTER
343470
p.nextToken()
@@ -6619,6 +6746,16 @@ func statementToJSON(stmt ast.Statement) jsonNode {
66196746
return dropExternalLanguageStatementToJSON(s)
66206747
case *ast.DropExternalLibraryStatement:
66216748
return dropExternalLibraryStatementToJSON(s)
6749+
case *ast.DropSequenceStatement:
6750+
return dropSequenceStatementToJSON(s)
6751+
case *ast.DropSearchPropertyListStatement:
6752+
return dropSearchPropertyListStatementToJSON(s)
6753+
case *ast.DropServerRoleStatement:
6754+
return dropServerRoleStatementToJSON(s)
6755+
case *ast.DropAvailabilityGroupStatement:
6756+
return dropAvailabilityGroupStatementToJSON(s)
6757+
case *ast.DropFederationStatement:
6758+
return dropFederationStatementToJSON(s)
66226759
case *ast.CreateTableStatement:
66236760
return createTableStatementToJSON(s)
66246761
case *ast.GrantStatement:
@@ -6752,6 +6889,65 @@ func dropExternalLibraryStatementToJSON(s *ast.DropExternalLibraryStatement) jso
67526889
return node
67536890
}
67546891

6892+
func dropSequenceStatementToJSON(s *ast.DropSequenceStatement) jsonNode {
6893+
node := jsonNode{
6894+
"$type": "DropSequenceStatement",
6895+
}
6896+
if len(s.Objects) > 0 {
6897+
objects := make([]jsonNode, len(s.Objects))
6898+
for i, obj := range s.Objects {
6899+
objects[i] = schemaObjectNameToJSON(obj)
6900+
}
6901+
node["Objects"] = objects
6902+
}
6903+
node["IsIfExists"] = s.IsIfExists
6904+
return node
6905+
}
6906+
6907+
func dropSearchPropertyListStatementToJSON(s *ast.DropSearchPropertyListStatement) jsonNode {
6908+
node := jsonNode{
6909+
"$type": "DropSearchPropertyListStatement",
6910+
}
6911+
if s.Name != nil {
6912+
node["Name"] = identifierToJSON(s.Name)
6913+
}
6914+
node["IsIfExists"] = s.IsIfExists
6915+
return node
6916+
}
6917+
6918+
func dropServerRoleStatementToJSON(s *ast.DropServerRoleStatement) jsonNode {
6919+
node := jsonNode{
6920+
"$type": "DropServerRoleStatement",
6921+
}
6922+
if s.Name != nil {
6923+
node["Name"] = identifierToJSON(s.Name)
6924+
}
6925+
node["IsIfExists"] = s.IsIfExists
6926+
return node
6927+
}
6928+
6929+
func dropAvailabilityGroupStatementToJSON(s *ast.DropAvailabilityGroupStatement) jsonNode {
6930+
node := jsonNode{
6931+
"$type": "DropAvailabilityGroupStatement",
6932+
}
6933+
if s.Name != nil {
6934+
node["Name"] = identifierToJSON(s.Name)
6935+
}
6936+
node["IsIfExists"] = s.IsIfExists
6937+
return node
6938+
}
6939+
6940+
func dropFederationStatementToJSON(s *ast.DropFederationStatement) jsonNode {
6941+
node := jsonNode{
6942+
"$type": "DropFederationStatement",
6943+
}
6944+
if s.Name != nil {
6945+
node["Name"] = identifierToJSON(s.Name)
6946+
}
6947+
node["IsIfExists"] = s.IsIfExists
6948+
return node
6949+
}
6950+
67556951
func alterTableDropTableElementStatementToJSON(s *ast.AlterTableDropTableElementStatement) jsonNode {
67566952
node := jsonNode{
67576953
"$type": "AlterTableDropTableElementStatement",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"skip": true}
1+
{"skip": false}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"skip": true}
1+
{"skip": false}

0 commit comments

Comments
 (0)