Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions ast/create_spatial_index_statement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package ast

// CreateSpatialIndexStatement represents a CREATE SPATIAL INDEX statement
type CreateSpatialIndexStatement struct {
Name *Identifier
Object *SchemaObjectName
SpatialColumnName *Identifier
SpatialIndexingScheme string // "None", "GeometryGrid", "GeographyGrid", "GeometryAutoGrid", "GeographyAutoGrid"
OnFileGroup *IdentifierOrValueExpression
SpatialIndexOptions []SpatialIndexOption
}

func (s *CreateSpatialIndexStatement) node() {}
func (s *CreateSpatialIndexStatement) statement() {}

// SpatialIndexOption is an interface for spatial index options
type SpatialIndexOption interface {
Node
spatialIndexOption()
}

// SpatialIndexRegularOption wraps a regular IndexOption for spatial indexes
type SpatialIndexRegularOption struct {
Option IndexOption
}

func (s *SpatialIndexRegularOption) node() {}
func (s *SpatialIndexRegularOption) spatialIndexOption() {}

// BoundingBoxSpatialIndexOption represents a BOUNDING_BOX option
type BoundingBoxSpatialIndexOption struct {
BoundingBoxParameters []*BoundingBoxParameter
}

func (b *BoundingBoxSpatialIndexOption) node() {}
func (b *BoundingBoxSpatialIndexOption) spatialIndexOption() {}

// BoundingBoxParameter represents a bounding box parameter (XMIN, YMIN, XMAX, YMAX)
type BoundingBoxParameter struct {
Parameter string // "None", "XMin", "YMin", "XMax", "YMax"
Value ScalarExpression
}

func (b *BoundingBoxParameter) node() {}

// GridsSpatialIndexOption represents a GRIDS option
type GridsSpatialIndexOption struct {
GridParameters []*GridParameter
}

func (g *GridsSpatialIndexOption) node() {}
func (g *GridsSpatialIndexOption) spatialIndexOption() {}

// GridParameter represents a grid parameter
type GridParameter struct {
Parameter string // "None", "Level1", "Level2", "Level3", "Level4"
Value string // "Low", "Medium", "High"
}

func (g *GridParameter) node() {}

// CellsPerObjectSpatialIndexOption represents a CELLS_PER_OBJECT option
type CellsPerObjectSpatialIndexOption struct {
Value ScalarExpression
}

func (c *CellsPerObjectSpatialIndexOption) node() {}
func (c *CellsPerObjectSpatialIndexOption) spatialIndexOption() {}

// DataCompressionOption represents a DATA_COMPRESSION option for indexes
type DataCompressionOption struct {
CompressionLevel string // "None", "Row", "Page", "ColumnStore", "ColumnStoreArchive"
OptionKind string // "DataCompression"
PartitionRanges []*CompressionPartitionRange
}

func (d *DataCompressionOption) node() {}
func (d *DataCompressionOption) indexOption() {}

// IgnoreDupKeyIndexOption represents the IGNORE_DUP_KEY option
type IgnoreDupKeyIndexOption struct {
OptionState string // "On", "Off"
OptionKind string // "IgnoreDupKey"
}

func (i *IgnoreDupKeyIndexOption) node() {}
func (i *IgnoreDupKeyIndexOption) indexOption() {}
124 changes: 124 additions & 0 deletions parser/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ func statementToJSON(stmt ast.Statement) jsonNode {
return createLoginStatementToJSON(s)
case *ast.CreateIndexStatement:
return createIndexStatementToJSON(s)
case *ast.CreateSpatialIndexStatement:
return createSpatialIndexStatementToJSON(s)
case *ast.CreateAsymmetricKeyStatement:
return createAsymmetricKeyStatementToJSON(s)
case *ast.CreateSymmetricKeyStatement:
Expand Down Expand Up @@ -5185,6 +5187,108 @@ func createColumnStoreIndexStatementToJSON(s *ast.CreateColumnStoreIndexStatemen
return node
}

func createSpatialIndexStatementToJSON(s *ast.CreateSpatialIndexStatement) jsonNode {
node := jsonNode{
"$type": "CreateSpatialIndexStatement",
}
if s.Name != nil {
node["Name"] = identifierToJSON(s.Name)
}
if s.Object != nil {
node["Object"] = schemaObjectNameToJSON(s.Object)
}
if s.SpatialColumnName != nil {
node["SpatialColumnName"] = identifierToJSON(s.SpatialColumnName)
}
if s.SpatialIndexingScheme != "" {
node["SpatialIndexingScheme"] = s.SpatialIndexingScheme
}
if s.OnFileGroup != nil {
node["OnFileGroup"] = identifierOrValueExpressionToJSON(s.OnFileGroup)
}
if len(s.SpatialIndexOptions) > 0 {
opts := make([]jsonNode, len(s.SpatialIndexOptions))
for i, opt := range s.SpatialIndexOptions {
opts[i] = spatialIndexOptionToJSON(opt)
}
node["SpatialIndexOptions"] = opts
}
return node
}

func spatialIndexOptionToJSON(opt ast.SpatialIndexOption) jsonNode {
switch o := opt.(type) {
case *ast.SpatialIndexRegularOption:
node := jsonNode{
"$type": "SpatialIndexRegularOption",
}
if o.Option != nil {
node["Option"] = indexOptionToJSON(o.Option)
}
return node
case *ast.BoundingBoxSpatialIndexOption:
node := jsonNode{
"$type": "BoundingBoxSpatialIndexOption",
}
if len(o.BoundingBoxParameters) > 0 {
params := make([]jsonNode, len(o.BoundingBoxParameters))
for i, p := range o.BoundingBoxParameters {
params[i] = boundingBoxParameterToJSON(p)
}
node["BoundingBoxParameters"] = params
}
return node
case *ast.GridsSpatialIndexOption:
node := jsonNode{
"$type": "GridsSpatialIndexOption",
}
if len(o.GridParameters) > 0 {
params := make([]jsonNode, len(o.GridParameters))
for i, p := range o.GridParameters {
params[i] = gridParameterToJSON(p)
}
node["GridParameters"] = params
}
return node
case *ast.CellsPerObjectSpatialIndexOption:
node := jsonNode{
"$type": "CellsPerObjectSpatialIndexOption",
}
if o.Value != nil {
node["Value"] = scalarExpressionToJSON(o.Value)
}
return node
default:
return jsonNode{"$type": "UnknownSpatialIndexOption"}
}
}

func boundingBoxParameterToJSON(p *ast.BoundingBoxParameter) jsonNode {
node := jsonNode{
"$type": "BoundingBoxParameter",
}
if p.Parameter != "" {
node["Parameter"] = p.Parameter
}
if p.Value != nil {
node["Value"] = scalarExpressionToJSON(p.Value)
}
return node
}

func gridParameterToJSON(p *ast.GridParameter) jsonNode {
node := jsonNode{
"$type": "GridParameter",
}
if p.Parameter != "" {
node["Parameter"] = p.Parameter
}
if p.Value != "" {
node["Value"] = p.Value
}
return node
}

func alterFunctionStatementToJSON(s *ast.AlterFunctionStatement) jsonNode {
node := jsonNode{
"$type": "AlterFunctionStatement",
Expand Down Expand Up @@ -5378,6 +5482,26 @@ func indexOptionToJSON(opt ast.IndexOption) jsonNode {
"OptionKind": o.OptionKind,
"Expression": scalarExpressionToJSON(o.Expression),
}
case *ast.DataCompressionOption:
node := jsonNode{
"$type": "DataCompressionOption",
"CompressionLevel": o.CompressionLevel,
"OptionKind": o.OptionKind,
}
if len(o.PartitionRanges) > 0 {
ranges := make([]jsonNode, len(o.PartitionRanges))
for i, r := range o.PartitionRanges {
ranges[i] = compressionPartitionRangeToJSON(r)
}
node["PartitionRanges"] = ranges
}
return node
case *ast.IgnoreDupKeyIndexOption:
return jsonNode{
"$type": "IgnoreDupKeyIndexOption",
"OptionState": o.OptionState,
"OptionKind": o.OptionKind,
}
default:
return jsonNode{"$type": "UnknownIndexOption"}
}
Expand Down
Loading
Loading