Skip to content

Commit 5184819

Browse files
committed
Add MAX_DURATION option support for CREATE INDEX
- Add MaxDurationOption AST type for resumable index operations - Parse MAX_DURATION = value [MINUTES] in index options - Add JSON marshaling for MaxDurationOption
1 parent 52c0a7f commit 5184819

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

ast/alter_table_alter_index_statement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ type OrderIndexOption struct {
5353

5454
func (o *OrderIndexOption) indexOption() {}
5555
func (o *OrderIndexOption) node() {}
56+
57+
// MaxDurationOption represents MAX_DURATION option for resumable index operations
58+
type MaxDurationOption struct {
59+
MaxDuration ScalarExpression
60+
Unit string // "", "Minutes"
61+
OptionKind string // "MaxDuration"
62+
}
63+
64+
func (m *MaxDurationOption) indexOption() {}
65+
func (m *MaxDurationOption) node() {}

parser/marshal.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10809,6 +10809,18 @@ func indexOptionToJSON(opt ast.IndexOption) jsonNode {
1080910809
node["Expression"] = scalarExpressionToJSON(o.Expression)
1081010810
}
1081110811
return node
10812+
case *ast.MaxDurationOption:
10813+
node := jsonNode{
10814+
"$type": "MaxDurationOption",
10815+
"OptionKind": o.OptionKind,
10816+
}
10817+
if o.MaxDuration != nil {
10818+
node["MaxDuration"] = scalarExpressionToJSON(o.MaxDuration)
10819+
}
10820+
if o.Unit != "" {
10821+
node["Unit"] = o.Unit
10822+
}
10823+
return node
1081210824
default:
1081310825
return jsonNode{"$type": "UnknownIndexOption"}
1081410826
}

parser/parse_statements.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8348,6 +8348,18 @@ func (p *Parser) parseCreateIndexOptions() []ast.IndexOption {
83488348
OptionKind: "MaxDop",
83498349
Expression: &ast.IntegerLiteral{LiteralType: "Integer", Value: valueToken.Literal},
83508350
})
8351+
case "MAX_DURATION":
8352+
// Parse MAX_DURATION = value [MINUTES]
8353+
opt := &ast.MaxDurationOption{
8354+
OptionKind: "MaxDuration",
8355+
MaxDuration: &ast.IntegerLiteral{LiteralType: "Integer", Value: valueToken.Literal},
8356+
}
8357+
// Check for optional MINUTES unit
8358+
if strings.ToUpper(p.curTok.Literal) == "MINUTES" {
8359+
opt.Unit = "Minutes"
8360+
p.nextToken() // consume MINUTES
8361+
}
8362+
options = append(options, opt)
83518363
default:
83528364
// Generic handling for other options
83538365
if valueStr == "ON" || valueStr == "OFF" {
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)