Skip to content

Commit 0f3199e

Browse files
committed
Add COLUMNSTORE index parsing improvements
- Add OnFileGroupOrPartitionScheme field to CreateColumnStoreIndexStatement - Parse DROP_EXISTING and MAXDOP index options - Add IndexExpressionOption marshalling to columnStoreIndexOptionToJSON - Parse ON filegroup/partition scheme clause for COLUMNSTORE indexes Enables 2 tests: CreateIndexStatementTests110, Baselines110_CreateIndexStatementTests110
1 parent 070ed3e commit 0f3199e

4 files changed

Lines changed: 68 additions & 19 deletions

File tree

ast/create_columnstore_index_statement.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package ast
22

33
// CreateColumnStoreIndexStatement represents a CREATE COLUMNSTORE INDEX statement
44
type CreateColumnStoreIndexStatement struct {
5-
Name *Identifier
6-
Clustered bool
7-
ClusteredExplicit bool // true if CLUSTERED or NONCLUSTERED was explicitly specified
8-
OnName *SchemaObjectName
9-
Columns []*ColumnReferenceExpression
10-
OrderedColumns []*ColumnReferenceExpression
11-
IndexOptions []IndexOption
12-
FilterClause BooleanExpression
13-
OnPartition *PartitionSpecifier
5+
Name *Identifier
6+
Clustered bool
7+
ClusteredExplicit bool // true if CLUSTERED or NONCLUSTERED was explicitly specified
8+
OnName *SchemaObjectName
9+
Columns []*ColumnReferenceExpression
10+
OrderedColumns []*ColumnReferenceExpression
11+
IndexOptions []IndexOption
12+
FilterClause BooleanExpression
13+
OnPartition *PartitionSpecifier
14+
OnFileGroupOrPartitionScheme *FileGroupOrPartitionScheme
1415
}
1516

1617
func (s *CreateColumnStoreIndexStatement) statement() {}

parser/marshal.go

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7059,8 +7059,12 @@ func (p *Parser) parseCreateColumnStoreIndexStatement() (*ast.CreateColumnStoreI
70597059
}
70607060
stmt.IndexOptions = append(stmt.IndexOptions, opt)
70617061

7062-
case "SORT_IN_TEMPDB":
7063-
p.nextToken() // consume SORT_IN_TEMPDB
7062+
case "SORT_IN_TEMPDB", "DROP_EXISTING":
7063+
optKind := "SortInTempDB"
7064+
if optName == "DROP_EXISTING" {
7065+
optKind = "DropExisting"
7066+
}
7067+
p.nextToken() // consume option name
70647068
if p.curTok.Type == TokenEquals {
70657069
p.nextToken() // consume =
70667070
}
@@ -7073,10 +7077,24 @@ func (p *Parser) parseCreateColumnStoreIndexStatement() (*ast.CreateColumnStoreI
70737077
p.nextToken()
70747078
}
70757079
stmt.IndexOptions = append(stmt.IndexOptions, &ast.IndexStateOption{
7076-
OptionKind: "SortInTempDB",
7080+
OptionKind: optKind,
70777081
OptionState: state,
70787082
})
70797083

7084+
case "MAXDOP":
7085+
p.nextToken() // consume MAXDOP
7086+
if p.curTok.Type == TokenEquals {
7087+
p.nextToken() // consume =
7088+
}
7089+
expr, err := p.parseScalarExpression()
7090+
if err != nil {
7091+
return nil, err
7092+
}
7093+
stmt.IndexOptions = append(stmt.IndexOptions, &ast.IndexExpressionOption{
7094+
OptionKind: "MaxDop",
7095+
Expression: expr,
7096+
})
7097+
70807098
case "ORDER":
70817099
p.nextToken() // consume ORDER
70827100
if p.curTok.Type == TokenLParen {
@@ -7121,13 +7139,31 @@ func (p *Parser) parseCreateColumnStoreIndexStatement() (*ast.CreateColumnStoreI
71217139
}
71227140
}
71237141

7124-
// Skip optional ON partition clause
7142+
// Parse optional ON filegroup/partition scheme
71257143
if p.curTok.Type == TokenOn {
7126-
p.nextToken()
7127-
// Skip to semicolon
7128-
for p.curTok.Type != TokenSemicolon && p.curTok.Type != TokenEOF {
7129-
p.nextToken()
7144+
p.nextToken() // consume ON
7145+
fgps := &ast.FileGroupOrPartitionScheme{
7146+
Name: &ast.IdentifierOrValueExpression{
7147+
Identifier: p.parseIdentifier(),
7148+
},
7149+
}
7150+
fgps.Name.Value = fgps.Name.Identifier.Value
7151+
// Check for partition columns
7152+
if p.curTok.Type == TokenLParen {
7153+
p.nextToken() // consume (
7154+
for p.curTok.Type != TokenRParen && p.curTok.Type != TokenEOF {
7155+
fgps.PartitionSchemeColumns = append(fgps.PartitionSchemeColumns, p.parseIdentifier())
7156+
if p.curTok.Type == TokenComma {
7157+
p.nextToken()
7158+
} else {
7159+
break
7160+
}
7161+
}
7162+
if p.curTok.Type == TokenRParen {
7163+
p.nextToken()
7164+
}
71307165
}
7166+
stmt.OnFileGroupOrPartitionScheme = fgps
71317167
}
71327168

71337169
// Skip optional semicolon
@@ -8893,6 +8929,9 @@ func createColumnStoreIndexStatementToJSON(s *ast.CreateColumnStoreIndexStatemen
88938929
}
88948930
node["OrderedColumns"] = cols
88958931
}
8932+
if s.OnFileGroupOrPartitionScheme != nil {
8933+
node["OnFileGroupOrPartitionScheme"] = fileGroupOrPartitionSchemeToJSON(s.OnFileGroupOrPartitionScheme)
8934+
}
88968935
return node
88978936
}
88988937

@@ -8927,6 +8966,15 @@ func columnStoreIndexOptionToJSON(opt ast.IndexOption) jsonNode {
89278966
"OptionKind": o.OptionKind,
89288967
"OptionState": o.OptionState,
89298968
}
8969+
case *ast.IndexExpressionOption:
8970+
node := jsonNode{
8971+
"$type": "IndexExpressionOption",
8972+
"OptionKind": o.OptionKind,
8973+
}
8974+
if o.Expression != nil {
8975+
node["Expression"] = scalarExpressionToJSON(o.Expression)
8976+
}
8977+
return node
89308978
default:
89318979
return jsonNode{"$type": "UnknownIndexOption"}
89328980
}
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)