Skip to content

Commit 7074428

Browse files
committed
Add WAIT_AT_LOW_PRIORITY parsing for ALTER TABLE SWITCH
Support MAX_DURATION and ABORT_AFTER_WAIT options within WAIT_AT_LOW_PRIORITY clause for table switch operations.
1 parent 5c221d5 commit 7074428

6 files changed

Lines changed: 92 additions & 4 deletions

File tree

ast/alter_table_switch_statement.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ type TruncateTargetTableSwitchOption struct {
2828
func (o *TruncateTargetTableSwitchOption) tableSwitchOption() {}
2929
func (o *TruncateTargetTableSwitchOption) node() {}
3030

31-
// LowPriorityLockWait represents LOW_PRIORITY_LOCK_WAIT option
31+
// LowPriorityLockWaitTableSwitchOption represents WAIT_AT_LOW_PRIORITY option
32+
type LowPriorityLockWaitTableSwitchOption struct {
33+
OptionKind string
34+
Options []LowPriorityLockWaitOption
35+
}
36+
37+
func (o *LowPriorityLockWaitTableSwitchOption) tableSwitchOption() {}
38+
func (o *LowPriorityLockWaitTableSwitchOption) node() {}
39+
40+
// LowPriorityLockWait represents LOW_PRIORITY_LOCK_WAIT option (legacy)
3241
type LowPriorityLockWait struct {
3342
MaxDuration ScalarExpression
3443
MaxDurationUnit string // "MINUTES", "SECONDS"

ast/drop_statements.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type LowPriorityLockWaitOption interface {
123123

124124
// LowPriorityLockWaitMaxDurationOption represents MAX_DURATION option
125125
type LowPriorityLockWaitMaxDurationOption struct {
126-
MaxDuration *IntegerLiteral
126+
MaxDuration ScalarExpression
127127
Unit string // Minutes or Seconds
128128
OptionKind string // MaxDuration
129129
}

parser/marshal.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11653,6 +11653,19 @@ func tableSwitchOptionToJSON(opt ast.TableSwitchOption) jsonNode {
1165311653
"TruncateTarget": o.TruncateTarget,
1165411654
"OptionKind": o.OptionKind,
1165511655
}
11656+
case *ast.LowPriorityLockWaitTableSwitchOption:
11657+
node := jsonNode{
11658+
"$type": "LowPriorityLockWaitTableSwitchOption",
11659+
"OptionKind": o.OptionKind,
11660+
}
11661+
if len(o.Options) > 0 {
11662+
opts := make([]jsonNode, len(o.Options))
11663+
for i, subOpt := range o.Options {
11664+
opts[i] = lowPriorityLockWaitOptionToJSON(subOpt)
11665+
}
11666+
node["Options"] = opts
11667+
}
11668+
return node
1165611669
default:
1165711670
return jsonNode{"$type": "UnknownSwitchOption"}
1165811671
}

parser/parse_ddl.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,6 +3594,72 @@ func (p *Parser) parseAlterTableSwitchStatement(tableName *ast.SchemaObjectName)
35943594
}
35953595
stmt.Options = append(stmt.Options, opt)
35963596
}
3597+
} else if optionName == "WAIT_AT_LOW_PRIORITY" {
3598+
opt := &ast.LowPriorityLockWaitTableSwitchOption{
3599+
OptionKind: "LowPriorityLockWait",
3600+
}
3601+
3602+
// Expect (
3603+
if p.curTok.Type == TokenLParen {
3604+
p.nextToken()
3605+
3606+
for p.curTok.Type != TokenRParen && p.curTok.Type != TokenEOF {
3607+
subOptName := strings.ToUpper(p.curTok.Literal)
3608+
p.nextToken()
3609+
3610+
if subOptName == "MAX_DURATION" {
3611+
if p.curTok.Type == TokenEquals {
3612+
p.nextToken()
3613+
}
3614+
// Parse the duration value
3615+
durExpr, err := p.parseScalarExpression()
3616+
if err != nil {
3617+
return nil, err
3618+
}
3619+
subOpt := &ast.LowPriorityLockWaitMaxDurationOption{
3620+
OptionKind: "MaxDuration",
3621+
MaxDuration: durExpr,
3622+
}
3623+
// Check for MINUTES
3624+
if strings.ToUpper(p.curTok.Literal) == "MINUTES" {
3625+
subOpt.Unit = "Minutes"
3626+
p.nextToken()
3627+
}
3628+
opt.Options = append(opt.Options, subOpt)
3629+
} else if subOptName == "ABORT_AFTER_WAIT" {
3630+
if p.curTok.Type == TokenEquals {
3631+
p.nextToken()
3632+
}
3633+
value := p.curTok.Literal
3634+
p.nextToken()
3635+
// Convert to proper case
3636+
abortValue := "None"
3637+
switch strings.ToUpper(value) {
3638+
case "NONE":
3639+
abortValue = "None"
3640+
case "SELF":
3641+
abortValue = "Self"
3642+
case "BLOCKERS":
3643+
abortValue = "Blockers"
3644+
}
3645+
subOpt := &ast.LowPriorityLockWaitAbortAfterWaitOption{
3646+
OptionKind: "AbortAfterWait",
3647+
AbortAfterWait: abortValue,
3648+
}
3649+
opt.Options = append(opt.Options, subOpt)
3650+
}
3651+
3652+
if p.curTok.Type == TokenComma {
3653+
p.nextToken()
3654+
}
3655+
}
3656+
3657+
if p.curTok.Type == TokenRParen {
3658+
p.nextToken()
3659+
}
3660+
}
3661+
3662+
stmt.Options = append(stmt.Options, opt)
35973663
}
35983664

35993665
if p.curTok.Type == TokenComma {
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)