Skip to content

Commit 099fe84

Browse files
committed
Add TOP and OUTPUT clause parsing to DELETE statement
- Add TopRowFilter, OutputClause, OutputIntoClause fields to DeleteSpecification - Parse TOP (expression) [PERCENT] clause in DELETE statement - Parse OUTPUT and OUTPUT INTO clauses in DELETE statement - Update deleteSpecificationToJSON to marshal new fields Enables 2 tests: DeleteStatementTests90, Baselines90_DeleteStatementTests90
1 parent 66f9ed5 commit 099fe84

5 files changed

Lines changed: 40 additions & 5 deletions

File tree

ast/delete_statement.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ func (d *DeleteStatement) statement() {}
1212

1313
// DeleteSpecification contains the details of a DELETE.
1414
type DeleteSpecification struct {
15-
Target TableReference `json:"Target,omitempty"`
16-
FromClause *FromClause `json:"FromClause,omitempty"`
17-
WhereClause *WhereClause `json:"WhereClause,omitempty"`
15+
Target TableReference `json:"Target,omitempty"`
16+
FromClause *FromClause `json:"FromClause,omitempty"`
17+
WhereClause *WhereClause `json:"WhereClause,omitempty"`
18+
TopRowFilter *TopRowFilter `json:"TopRowFilter,omitempty"`
19+
OutputClause *OutputClause `json:"OutputClause,omitempty"`
20+
OutputIntoClause *OutputIntoClause `json:"OutputIntoClause,omitempty"`
1821
}

parser/marshal.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,15 @@ func deleteSpecificationToJSON(spec *ast.DeleteSpecification) jsonNode {
25982598
if spec.Target != nil {
25992599
node["Target"] = tableReferenceToJSON(spec.Target)
26002600
}
2601+
if spec.TopRowFilter != nil {
2602+
node["TopRowFilter"] = topRowFilterToJSON(spec.TopRowFilter)
2603+
}
2604+
if spec.OutputClause != nil {
2605+
node["OutputClause"] = outputClauseToJSON(spec.OutputClause)
2606+
}
2607+
if spec.OutputIntoClause != nil {
2608+
node["OutputIntoClause"] = outputIntoClauseToJSON(spec.OutputIntoClause)
2609+
}
26012610
return node
26022611
}
26032612

parser/parse_dml.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,15 @@ func (p *Parser) parseDeleteStatement() (*ast.DeleteStatement, error) {
13691369
DeleteSpecification: &ast.DeleteSpecification{},
13701370
}
13711371

1372+
// Parse optional TOP clause
1373+
if p.curTok.Type == TokenTop {
1374+
topRowFilter, err := p.parseTopRowFilter()
1375+
if err != nil {
1376+
return nil, err
1377+
}
1378+
stmt.DeleteSpecification.TopRowFilter = topRowFilter
1379+
}
1380+
13721381
// Skip optional FROM
13731382
if p.curTok.Type == TokenFrom {
13741383
p.nextToken()
@@ -1381,6 +1390,20 @@ func (p *Parser) parseDeleteStatement() (*ast.DeleteStatement, error) {
13811390
}
13821391
stmt.DeleteSpecification.Target = target
13831392

1393+
// Parse OUTPUT clauses (can have OUTPUT INTO followed by OUTPUT)
1394+
for p.curTok.Type == TokenIdent && strings.ToUpper(p.curTok.Literal) == "OUTPUT" {
1395+
outputClause, outputIntoClause, err := p.parseOutputClause()
1396+
if err != nil {
1397+
return nil, err
1398+
}
1399+
if outputIntoClause != nil {
1400+
stmt.DeleteSpecification.OutputIntoClause = outputIntoClause
1401+
}
1402+
if outputClause != nil {
1403+
stmt.DeleteSpecification.OutputClause = outputClause
1404+
}
1405+
}
1406+
13841407
// Parse optional FROM clause
13851408
if p.curTok.Type == TokenFrom {
13861409
fromClause, err := p.parseFromClause()
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)