Skip to content

Commit 0b52803

Browse files
authored
Add comprehensive optimizer hint parsing for OPTION clause (#53)
1 parent 136ea2b commit 0b52803

78 files changed

Lines changed: 3712 additions & 278 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ast/alter_function_statement.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ func (s *AlterFunctionStatement) node() {}
1414

1515
// CreateFunctionStatement represents a CREATE FUNCTION statement
1616
type CreateFunctionStatement struct {
17-
Name *SchemaObjectName
18-
Parameters []*ProcedureParameter
19-
ReturnType FunctionReturnType
20-
Options []FunctionOptionBase
21-
StatementList *StatementList
17+
Name *SchemaObjectName
18+
Parameters []*ProcedureParameter
19+
ReturnType FunctionReturnType
20+
Options []FunctionOptionBase
21+
StatementList *StatementList
22+
OrderHint *OrderBulkInsertOption // For CLR table-valued functions
23+
MethodSpecifier *MethodSpecifier // For CLR functions (AS EXTERNAL NAME)
2224
}
2325

2426
func (s *CreateFunctionStatement) statement() {}
@@ -38,7 +40,7 @@ func (r *ScalarFunctionReturnType) functionReturnTypeNode() {}
3840

3941
// TableValuedFunctionReturnType represents a table-valued function return type
4042
type TableValuedFunctionReturnType struct {
41-
// Simplified - will be expanded later
43+
DeclareTableVariableBody *DeclareTableVariableBody
4244
}
4345

4446
func (r *TableValuedFunctionReturnType) functionReturnTypeNode() {}
@@ -73,6 +75,15 @@ type InlineFunctionOption struct {
7375
func (o *InlineFunctionOption) node() {}
7476
func (o *InlineFunctionOption) functionOption() {}
7577

78+
// ExecuteAsFunctionOption represents an EXECUTE AS function option
79+
type ExecuteAsFunctionOption struct {
80+
OptionKind string // "ExecuteAs"
81+
ExecuteAs *ExecuteAsClause // The EXECUTE AS clause
82+
}
83+
84+
func (o *ExecuteAsFunctionOption) node() {}
85+
func (o *ExecuteAsFunctionOption) functionOption() {}
86+
7687
// CreateOrAlterFunctionStatement represents a CREATE OR ALTER FUNCTION statement
7788
type CreateOrAlterFunctionStatement struct {
7889
Name *SchemaObjectName

ast/alter_simple_statements.go

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,91 @@ func (s *AlterRouteStatement) statement() {}
1111

1212
// AlterAssemblyStatement represents an ALTER ASSEMBLY statement.
1313
type AlterAssemblyStatement struct {
14-
Name *Identifier `json:"Name,omitempty"`
14+
Name *Identifier `json:"Name,omitempty"`
15+
Parameters []ScalarExpression `json:"Parameters,omitempty"` // FROM 'path' parameters
16+
Options []AssemblyOptionBase `json:"Options,omitempty"`
17+
AddFiles []*AddFileSpec `json:"AddFiles,omitempty"`
18+
DropFiles []*StringLiteral `json:"DropFiles,omitempty"`
19+
IsDropAll bool `json:"IsDropAll"`
1520
}
1621

1722
func (s *AlterAssemblyStatement) node() {}
1823
func (s *AlterAssemblyStatement) statement() {}
1924

25+
// AddFileSpec represents an ADD FILE specification.
26+
type AddFileSpec struct {
27+
File ScalarExpression `json:"File,omitempty"` // The file path or binary literal
28+
FileName *StringLiteral `json:"FileName,omitempty"` // Optional AS 'filename'
29+
}
30+
31+
func (a *AddFileSpec) node() {}
32+
33+
// AssemblyOptionBase is an interface for assembly options.
34+
type AssemblyOptionBase interface {
35+
Node
36+
assemblyOption()
37+
}
38+
39+
// AssemblyOption represents a basic assembly option.
40+
type AssemblyOption struct {
41+
OptionKind string `json:"OptionKind,omitempty"` // "UncheckedData"
42+
}
43+
44+
func (o *AssemblyOption) node() {}
45+
func (o *AssemblyOption) assemblyOption() {}
46+
47+
// OnOffAssemblyOption represents a VISIBILITY = ON|OFF option.
48+
type OnOffAssemblyOption struct {
49+
OptionKind string `json:"OptionKind,omitempty"` // "Visibility"
50+
OptionState string `json:"OptionState,omitempty"` // "On", "Off"
51+
}
52+
53+
func (o *OnOffAssemblyOption) node() {}
54+
func (o *OnOffAssemblyOption) assemblyOption() {}
55+
56+
// PermissionSetAssemblyOption represents a PERMISSION_SET option.
57+
type PermissionSetAssemblyOption struct {
58+
OptionKind string `json:"OptionKind,omitempty"` // "PermissionSet"
59+
PermissionSetOption string `json:"PermissionSetOption,omitempty"` // "Safe", "ExternalAccess", "Unsafe"
60+
}
61+
62+
func (o *PermissionSetAssemblyOption) node() {}
63+
func (o *PermissionSetAssemblyOption) assemblyOption() {}
64+
65+
// AlterSearchPropertyListStatement represents an ALTER SEARCH PROPERTY LIST statement.
66+
type AlterSearchPropertyListStatement struct {
67+
Name *Identifier `json:"Name,omitempty"`
68+
Action SearchPropertyListAction `json:"Action,omitempty"`
69+
}
70+
71+
func (s *AlterSearchPropertyListStatement) node() {}
72+
func (s *AlterSearchPropertyListStatement) statement() {}
73+
74+
// SearchPropertyListAction is the interface for search property list actions.
75+
type SearchPropertyListAction interface {
76+
Node
77+
searchPropertyListAction()
78+
}
79+
80+
// AddSearchPropertyListAction represents an ADD action in ALTER SEARCH PROPERTY LIST.
81+
type AddSearchPropertyListAction struct {
82+
PropertyName *StringLiteral `json:"PropertyName,omitempty"`
83+
Guid *StringLiteral `json:"Guid,omitempty"`
84+
Id *IntegerLiteral `json:"Id,omitempty"`
85+
Description *StringLiteral `json:"Description,omitempty"`
86+
}
87+
88+
func (a *AddSearchPropertyListAction) node() {}
89+
func (a *AddSearchPropertyListAction) searchPropertyListAction() {}
90+
91+
// DropSearchPropertyListAction represents a DROP action in ALTER SEARCH PROPERTY LIST.
92+
type DropSearchPropertyListAction struct {
93+
PropertyName *StringLiteral `json:"PropertyName,omitempty"`
94+
}
95+
96+
func (a *DropSearchPropertyListAction) node() {}
97+
func (a *DropSearchPropertyListAction) searchPropertyListAction() {}
98+
2099
// AlterEndpointStatement represents an ALTER ENDPOINT statement.
21100
type AlterEndpointStatement struct {
22101
Name *Identifier `json:"Name,omitempty"`
@@ -186,7 +265,9 @@ func (s *AlterFulltextIndexStatement) statement() {}
186265

187266
// AlterSymmetricKeyStatement represents an ALTER SYMMETRIC KEY statement.
188267
type AlterSymmetricKeyStatement struct {
189-
Name *Identifier `json:"Name,omitempty"`
268+
Name *Identifier `json:"Name,omitempty"`
269+
IsAdd bool `json:"IsAdd"`
270+
EncryptingMechanisms []*CryptoMechanism `json:"EncryptingMechanisms,omitempty"`
190271
}
191272

192273
func (s *AlterSymmetricKeyStatement) node() {}
@@ -212,3 +293,13 @@ type RenameEntityStatement struct {
212293

213294
func (s *RenameEntityStatement) node() {}
214295
func (s *RenameEntityStatement) statement() {}
296+
297+
// AlterDatabaseEncryptionKeyStatement represents an ALTER DATABASE ENCRYPTION KEY statement.
298+
type AlterDatabaseEncryptionKeyStatement struct {
299+
Regenerate bool `json:"Regenerate"`
300+
Algorithm string `json:"Algorithm,omitempty"`
301+
Encryptor *CryptoMechanism `json:"Encryptor,omitempty"`
302+
}
303+
304+
func (s *AlterDatabaseEncryptionKeyStatement) node() {}
305+
func (s *AlterDatabaseEncryptionKeyStatement) statement() {}

ast/alter_table_alter_column_statement.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package ast
22

33
// AlterTableAlterColumnStatement represents ALTER TABLE ... ALTER COLUMN statement
44
type AlterTableAlterColumnStatement struct {
5-
SchemaObjectName *SchemaObjectName
6-
ColumnIdentifier *Identifier
7-
DataType DataTypeReference
8-
AlterTableAlterColumnOption string // "NoOptionDefined", "Add", "Drop", etc.
9-
IsHidden bool
10-
IsMasked bool
5+
SchemaObjectName *SchemaObjectName
6+
ColumnIdentifier *Identifier
7+
DataType DataTypeReference
8+
AlterTableAlterColumnOption string // "NoOptionDefined", "AddRowGuidCol", "DropRowGuidCol", "Null", "NotNull", etc.
9+
IsHidden bool
10+
Collation *Identifier
11+
IsMasked bool
1112
}
1213

1314
func (a *AlterTableAlterColumnStatement) node() {}

ast/alter_table_set_statement.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ type RetentionPeriodDefinition struct {
3535
}
3636

3737
func (r *RetentionPeriodDefinition) node() {}
38+
39+
// MemoryOptimizedTableOption represents MEMORY_OPTIMIZED option
40+
type MemoryOptimizedTableOption struct {
41+
OptionKind string // "MemoryOptimized"
42+
OptionState string // "On", "Off"
43+
}
44+
45+
func (o *MemoryOptimizedTableOption) tableOption() {}
46+
func (o *MemoryOptimizedTableOption) node() {}

ast/backup_statement.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ type BackupServiceMasterKeyStatement struct {
5050
func (s *BackupServiceMasterKeyStatement) statement() {}
5151
func (s *BackupServiceMasterKeyStatement) node() {}
5252

53+
// BackupMasterKeyStatement represents a BACKUP MASTER KEY statement
54+
type BackupMasterKeyStatement struct {
55+
File ScalarExpression
56+
Password ScalarExpression
57+
}
58+
59+
func (s *BackupMasterKeyStatement) statement() {}
60+
func (s *BackupMasterKeyStatement) node() {}
61+
5362
// RestoreServiceMasterKeyStatement represents a RESTORE SERVICE MASTER KEY statement
5463
type RestoreServiceMasterKeyStatement struct {
5564
File ScalarExpression

ast/create_simple_statements.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ func (s *CreateEndpointStatement) statement() {}
111111

112112
// CreateAssemblyStatement represents a CREATE ASSEMBLY statement.
113113
type CreateAssemblyStatement struct {
114-
Name *Identifier `json:"Name,omitempty"`
114+
Name *Identifier `json:"Name,omitempty"`
115+
Owner *Identifier `json:"Owner,omitempty"`
116+
Parameters []ScalarExpression `json:"Parameters,omitempty"`
117+
Options []AssemblyOptionBase `json:"Options,omitempty"`
115118
}
116119

117120
func (s *CreateAssemblyStatement) node() {}
@@ -184,6 +187,24 @@ type CreationDispositionKeyOption struct {
184187
func (c *CreationDispositionKeyOption) node() {}
185188
func (c *CreationDispositionKeyOption) keyOption() {}
186189

190+
// KeySourceKeyOption represents a KEY_SOURCE key option.
191+
type KeySourceKeyOption struct {
192+
PassPhrase ScalarExpression `json:"PassPhrase,omitempty"`
193+
OptionKind string `json:"OptionKind,omitempty"`
194+
}
195+
196+
func (k *KeySourceKeyOption) node() {}
197+
func (k *KeySourceKeyOption) keyOption() {}
198+
199+
// IdentityValueKeyOption represents an IDENTITY_VALUE key option.
200+
type IdentityValueKeyOption struct {
201+
IdentityPhrase ScalarExpression `json:"IdentityPhrase,omitempty"`
202+
OptionKind string `json:"OptionKind,omitempty"`
203+
}
204+
205+
func (i *IdentityValueKeyOption) node() {}
206+
func (i *IdentityValueKeyOption) keyOption() {}
207+
187208
// CryptoMechanism represents an encryption mechanism (CERTIFICATE, KEY, PASSWORD, etc.)
188209
type CryptoMechanism struct {
189210
CryptoMechanismType string `json:"CryptoMechanismType,omitempty"` // "Certificate", "SymmetricKey", "AsymmetricKey", "Password"
@@ -195,9 +216,10 @@ func (c *CryptoMechanism) node() {}
195216

196217
// CreateSymmetricKeyStatement represents a CREATE SYMMETRIC KEY statement.
197218
type CreateSymmetricKeyStatement struct {
198-
KeyOptions []KeyOption `json:"KeyOptions,omitempty"`
199-
Provider *Identifier `json:"Provider,omitempty"`
200-
Name *Identifier `json:"Name,omitempty"`
219+
KeyOptions []KeyOption `json:"KeyOptions,omitempty"`
220+
Owner *Identifier `json:"Owner,omitempty"`
221+
Provider *Identifier `json:"Provider,omitempty"`
222+
Name *Identifier `json:"Name,omitempty"`
201223
EncryptingMechanisms []*CryptoMechanism `json:"EncryptingMechanisms,omitempty"`
202224
}
203225

@@ -289,8 +311,15 @@ func (s *CreatePartitionFunctionStatement) statement() {}
289311

290312
// CreateIndexStatement represents a CREATE INDEX statement.
291313
type CreateIndexStatement struct {
292-
Name *Identifier `json:"Name,omitempty"`
293-
OnName *SchemaObjectName `json:"OnName,omitempty"`
314+
Name *Identifier `json:"Name,omitempty"`
315+
OnName *SchemaObjectName `json:"OnName,omitempty"`
316+
Translated80SyntaxTo90 bool `json:"Translated80SyntaxTo90,omitempty"`
317+
Unique bool `json:"Unique,omitempty"`
318+
Clustered *bool `json:"Clustered,omitempty"` // nil = not specified, true = CLUSTERED, false = NONCLUSTERED
319+
Columns []*ColumnWithSortOrder `json:"Columns,omitempty"`
320+
IncludeColumns []*ColumnReferenceExpression `json:"IncludeColumns,omitempty"`
321+
IndexOptions []IndexOption `json:"IndexOptions,omitempty"`
322+
OnFileGroupOrPartitionScheme *FileGroupOrPartitionScheme `json:"OnFileGroupOrPartitionScheme,omitempty"`
294323
}
295324

296325
func (s *CreateIndexStatement) node() {}
@@ -339,6 +368,7 @@ func (s *CreateTypeUdtStatement) statement() {}
339368
type CreateTypeTableStatement struct {
340369
Name *SchemaObjectName `json:"Name,omitempty"`
341370
Definition *TableDefinition `json:"Definition,omitempty"`
371+
Options []TableOption `json:"Options,omitempty"`
342372
}
343373

344374
func (s *CreateTypeTableStatement) node() {}
@@ -387,3 +417,18 @@ type CreateEventNotificationStatement struct {
387417

388418
func (s *CreateEventNotificationStatement) node() {}
389419
func (s *CreateEventNotificationStatement) statement() {}
420+
421+
// CreateDatabaseEncryptionKeyStatement represents a CREATE DATABASE ENCRYPTION KEY statement.
422+
type CreateDatabaseEncryptionKeyStatement struct {
423+
Algorithm string `json:"Algorithm,omitempty"`
424+
Encryptor *CryptoMechanism `json:"Encryptor,omitempty"`
425+
}
426+
427+
func (s *CreateDatabaseEncryptionKeyStatement) node() {}
428+
func (s *CreateDatabaseEncryptionKeyStatement) statement() {}
429+
430+
// DropDatabaseEncryptionKeyStatement represents a DROP DATABASE ENCRYPTION KEY statement.
431+
type DropDatabaseEncryptionKeyStatement struct{}
432+
433+
func (s *DropDatabaseEncryptionKeyStatement) node() {}
434+
func (s *DropDatabaseEncryptionKeyStatement) statement() {}

ast/create_table_statement.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type ColumnDefinition struct {
4343
DefaultConstraint *DefaultConstraintDefinition
4444
IdentityOptions *IdentityOptions
4545
Constraints []ConstraintDefinition
46+
Index *IndexDefinition
4647
IsPersisted bool
4748
IsRowGuidCol bool
4849
IsHidden bool
@@ -137,12 +138,14 @@ func (c *CheckConstraintDefinition) constraintDefinition() {}
137138

138139
// UniqueConstraintDefinition represents a UNIQUE or PRIMARY KEY constraint
139140
type UniqueConstraintDefinition struct {
140-
ConstraintIdentifier *Identifier
141-
Clustered bool
142-
IsPrimaryKey bool
143-
IsEnforced *bool // nil = not specified (default enforced), true = ENFORCED, false = NOT ENFORCED
144-
Columns []*ColumnWithSortOrder
145-
IndexType *IndexType
141+
ConstraintIdentifier *Identifier
142+
Clustered bool
143+
IsPrimaryKey bool
144+
IsEnforced *bool // nil = not specified (default enforced), true = ENFORCED, false = NOT ENFORCED
145+
Columns []*ColumnWithSortOrder
146+
IndexType *IndexType
147+
IndexOptions []IndexOption
148+
OnFileGroupOrPartitionScheme *FileGroupOrPartitionScheme
146149
}
147150

148151
func (u *UniqueConstraintDefinition) node() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ast
2+
3+
// AddSensitivityClassificationStatement represents ADD SENSITIVITY CLASSIFICATION statement
4+
type AddSensitivityClassificationStatement struct {
5+
Columns []*ColumnReferenceExpression
6+
Options []*SensitivityClassificationOption
7+
}
8+
9+
func (s *AddSensitivityClassificationStatement) node() {}
10+
func (s *AddSensitivityClassificationStatement) statement() {}
11+
12+
// DropSensitivityClassificationStatement represents DROP SENSITIVITY CLASSIFICATION statement
13+
type DropSensitivityClassificationStatement struct {
14+
Columns []*ColumnReferenceExpression
15+
}
16+
17+
func (s *DropSensitivityClassificationStatement) node() {}
18+
func (s *DropSensitivityClassificationStatement) statement() {}
19+
20+
// SensitivityClassificationOption represents an option in ADD SENSITIVITY CLASSIFICATION
21+
type SensitivityClassificationOption struct {
22+
Type string // "Label", "LabelId", "InformationType", "InformationTypeId", "Rank"
23+
Value ScalarExpression // StringLiteral or IdentifierLiteral
24+
}
25+
26+
func (o *SensitivityClassificationOption) node() {}

ast/drop_statements.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type OnlineIndexOption struct {
8787

8888
func (o *OnlineIndexOption) node() {}
8989
func (o *OnlineIndexOption) dropIndexOption() {}
90+
func (o *OnlineIndexOption) indexOption() {}
9091

9192
// MoveToDropIndexOption represents the MOVE TO option
9293
type MoveToDropIndexOption struct {

ast/function_call.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ func (*WithinGroupClause) node() {}
4141

4242
// FunctionCall represents a function call.
4343
type FunctionCall struct {
44-
CallTarget CallTarget `json:"CallTarget,omitempty"`
45-
FunctionName *Identifier `json:"FunctionName,omitempty"`
46-
Parameters []ScalarExpression `json:"Parameters,omitempty"`
47-
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
48-
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
49-
OverClause *OverClause `json:"OverClause,omitempty"`
50-
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
44+
CallTarget CallTarget `json:"CallTarget,omitempty"`
45+
FunctionName *Identifier `json:"FunctionName,omitempty"`
46+
Parameters []ScalarExpression `json:"Parameters,omitempty"`
47+
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
48+
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
49+
OverClause *OverClause `json:"OverClause,omitempty"`
50+
IgnoreRespectNulls []*Identifier `json:"IgnoreRespectNulls,omitempty"`
51+
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
5152
}
5253

5354
func (*FunctionCall) node() {}

0 commit comments

Comments
 (0)