Skip to content

Commit

Permalink
Fix statment end position
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Sep 25, 2023
1 parent 1ad6389 commit 3806633
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions parser/parse_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,21 @@ func (p *Parser) parseOptimizeExpr(pos Pos) (*OptimizeExpr, error) {
if err := p.consumeKeyword(KeywordTable); err != nil {
return nil, err
}

table, err := p.parseTableIdentifier(p.Pos())
if err != nil {
return nil, err
}
statmentEnd := table.End()

onCluster, err := p.tryParseOnCluster(p.Pos())
if err != nil {
return nil, err
}
if onCluster != nil {
statmentEnd = onCluster.End()
}

partitionExpr, err := p.tryParsePartitionExpr(p.Pos())
if err != nil {
return nil, err
Expand All @@ -266,10 +269,14 @@ func (p *Parser) parseOptimizeExpr(pos Pos) (*OptimizeExpr, error) {
hasFinal = true
statmentEnd = lastPos
}

deduplicate, err := p.tryParseDeduplicateExpr(p.Pos())
if err != nil {
return nil, err
}
if deduplicate != nil {
statmentEnd = deduplicate.End()
}

return &OptimizeExpr{
OptimizePos: pos,
Expand Down
16 changes: 8 additions & 8 deletions parser/testdata/ddl/output/optimize.sql.golden.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"OptimizePos": 0,
"StatementEnd": 20,
"StatementEnd": 32,
"Table": {
"Database": null,
"Table": {
Expand All @@ -22,7 +22,7 @@
},
{
"OptimizePos": 49,
"StatementEnd": 69,
"StatementEnd": 85,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -54,7 +54,7 @@
},
{
"OptimizePos": 131,
"StatementEnd": 151,
"StatementEnd": 181,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -98,7 +98,7 @@
},
{
"OptimizePos": 183,
"StatementEnd": 203,
"StatementEnd": 219,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -141,7 +141,7 @@
},
{
"OptimizePos": 234,
"StatementEnd": 254,
"StatementEnd": 270,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -201,7 +201,7 @@
},
{
"OptimizePos": 293,
"StatementEnd": 313,
"StatementEnd": 362,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -251,7 +251,7 @@
},
{
"OptimizePos": 365,
"StatementEnd": 385,
"StatementEnd": 434,
"Table": {
"Database": null,
"Table": {
Expand Down Expand Up @@ -312,7 +312,7 @@
},
{
"OptimizePos": 449,
"StatementEnd": 469,
"StatementEnd": 518,
"Table": {
"Database": null,
"Table": {
Expand Down

0 comments on commit 3806633

Please sign in to comment.