Skip to content

Commit 7828673

Browse files
committed
Add ChildObjectName and BackwardsCompatibleDropIndexClause support
- Add childObjectNameToJSON for DROP STATISTICS and other statements - Use BackwardsCompatibleDropIndexClause type for legacy DROP INDEX syntax - Add Count and Identifiers to LegacyIndex for proper serialization Enables: BaselinesCommon_DropStatementsTests, Baselines100_DropIndexStatementTests100, BaselinesCommon_TSqlParserTestScript1
1 parent f8f6c5e commit 7828673

5 files changed

Lines changed: 54 additions & 7 deletions

File tree

parser/marshal.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8240,19 +8240,64 @@ func dropIndexClauseToJSON(c *ast.DropIndexClause) jsonNode {
82408240
return node
82418241
}
82428242

8243-
// Otherwise use DropIndexClauseBase for backwards-compatible syntax
8243+
// Otherwise use BackwardsCompatibleDropIndexClause for backwards-compatible syntax
82448244
node := jsonNode{
8245-
"$type": "DropIndexClauseBase",
8245+
"$type": "BackwardsCompatibleDropIndexClause",
82468246
}
82478247
if c.LegacyIndex != nil {
8248-
node["Index"] = schemaObjectNameToJSON(c.LegacyIndex)
8248+
node["Index"] = childObjectNameToJSON(c.LegacyIndex)
82498249
} else if c.Index != nil {
82508250
// Just index name without object - use identifier
82518251
node["Index"] = identifierToJSON(c.Index)
82528252
}
82538253
return node
82548254
}
82558255

8256+
// childObjectNameToJSON converts a SchemaObjectName to a ChildObjectName JSON format
8257+
// where the BaseIdentifier is the parent and the last identifier becomes ChildIdentifier
8258+
func childObjectNameToJSON(s *ast.SchemaObjectName) jsonNode {
8259+
node := jsonNode{
8260+
"$type": "ChildObjectName",
8261+
"Count": s.Count,
8262+
}
8263+
8264+
// For ChildObjectName: BaseIdentifier is the parent, ChildIdentifier is the actual child
8265+
if s.Count >= 2 {
8266+
// For 2-part: BaseIdentifier.ChildIdentifier
8267+
if s.SchemaIdentifier != nil {
8268+
node["BaseIdentifier"] = identifierToJSON(s.SchemaIdentifier)
8269+
}
8270+
if s.BaseIdentifier != nil {
8271+
node["ChildIdentifier"] = identifierToJSON(s.BaseIdentifier)
8272+
}
8273+
}
8274+
8275+
// For 3+ parts: add DatabaseIdentifier/SchemaIdentifier
8276+
if s.Count >= 3 {
8277+
if s.DatabaseIdentifier != nil {
8278+
node["SchemaIdentifier"] = identifierToJSON(s.DatabaseIdentifier)
8279+
}
8280+
}
8281+
8282+
if s.Count >= 4 {
8283+
if s.ServerIdentifier != nil {
8284+
node["DatabaseIdentifier"] = identifierToJSON(s.ServerIdentifier)
8285+
}
8286+
}
8287+
8288+
// Add identifiers array
8289+
if len(s.Identifiers) > 0 {
8290+
idents := make([]jsonNode, len(s.Identifiers))
8291+
for i, id := range s.Identifiers {
8292+
idents[i] = jsonNode{"$ref": "Identifier"}
8293+
_ = id
8294+
}
8295+
node["Identifiers"] = idents
8296+
}
8297+
8298+
return node
8299+
}
8300+
82568301
func dropIndexOptionToJSON(opt ast.DropIndexOption) jsonNode {
82578302
switch o := opt.(type) {
82588303
case *ast.OnlineIndexOption:
@@ -8296,7 +8341,7 @@ func dropStatisticsStatementToJSON(s *ast.DropStatisticsStatement) jsonNode {
82968341
if len(s.Objects) > 0 {
82978342
objects := make([]jsonNode, len(s.Objects))
82988343
for i, obj := range s.Objects {
8299-
objects[i] = schemaObjectNameToJSON(obj)
8344+
objects[i] = childObjectNameToJSON(obj)
83008345
}
83018346
node["Objects"] = objects
83028347
}

parser/parse_ddl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,8 @@ func (p *Parser) parseDropIndexStatement() (*ast.DropIndexStatement, error) {
11721172
clause.LegacyIndex = &ast.SchemaObjectName{
11731173
SchemaIdentifier: indexName,
11741174
BaseIdentifier: childName,
1175+
Count: 2,
1176+
Identifiers: []*ast.Identifier{indexName, childName},
11751177
}
11761178
} else {
11771179
// Just index name without ON or dot
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+
{}
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)