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
15 changes: 15 additions & 0 deletions ast/create_json_index_statement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ast

// CreateJsonIndexStatement represents CREATE JSON INDEX name ON table (column)
// [FOR ('path', ...)] [WITH (options)].
type CreateJsonIndexStatement struct {
Fragment
Name *Identifier `json:"Name,omitempty"`
OnName *SchemaObjectName `json:"OnName,omitempty"`
JsonColumn *Identifier `json:"JsonColumn,omitempty"`
ForJsonPaths []*StringLiteral `json:"ForJsonPaths,omitempty"`
IndexOptions []IndexOption `json:"IndexOptions,omitempty"`
}

func (*CreateJsonIndexStatement) node() {}
func (*CreateJsonIndexStatement) statement() {}
26 changes: 14 additions & 12 deletions ast/function_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,20 @@ func (*JsonKeyValue) node() {}
// FunctionCall represents a function call.
type FunctionCall struct {
Fragment
CallTarget CallTarget `json:"CallTarget,omitempty"`
FunctionName *Identifier `json:"FunctionName,omitempty"`
Parameters []ScalarExpression `json:"Parameters,omitempty"`
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
OverClause *OverClause `json:"OverClause,omitempty"`
IgnoreRespectNulls []*Identifier `json:"IgnoreRespectNulls,omitempty"`
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
TrimOptions *Identifier `json:"TrimOptions,omitempty"` // For TRIM(LEADING/TRAILING/BOTH chars FROM string)
Collation *Identifier `json:"Collation,omitempty"`
JsonParameters []*JsonKeyValue `json:"JsonParameters,omitempty"` // For JSON_OBJECT function key:value pairs
AbsentOrNullOnNull []*Identifier `json:"AbsentOrNullOnNull,omitempty"` // For JSON_OBJECT/JSON_ARRAY NULL ON NULL or ABSENT ON NULL
CallTarget CallTarget `json:"CallTarget,omitempty"`
FunctionName *Identifier `json:"FunctionName,omitempty"`
Parameters []ScalarExpression `json:"Parameters,omitempty"`
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
OverClause *OverClause `json:"OverClause,omitempty"`
IgnoreRespectNulls []*Identifier `json:"IgnoreRespectNulls,omitempty"`
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
TrimOptions *Identifier `json:"TrimOptions,omitempty"` // For TRIM(LEADING/TRAILING/BOTH chars FROM string)
Collation *Identifier `json:"Collation,omitempty"`
JsonParameters []*JsonKeyValue `json:"JsonParameters,omitempty"` // For JSON_OBJECT function key:value pairs
AbsentOrNullOnNull []*Identifier `json:"AbsentOrNullOnNull,omitempty"` // For JSON_OBJECT/JSON_ARRAY NULL ON NULL or ABSENT ON NULL
ReturnType []DataTypeReference `json:"ReturnType,omitempty"` // For JSON_* RETURNING data_type
JsonOrderByClause *OrderByClause `json:"JsonOrderByClause,omitempty"` // For JSON_ARRAYAGG(... ORDER BY ...)
}

func (*FunctionCall) node() {}
Expand Down
42 changes: 42 additions & 0 deletions parser/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ func statementToJSON(stmt ast.Statement) jsonNode {
return addSpan(dropLoginStatementToJSON(s), frag(stmt))
case *ast.CreateIndexStatement:
return addSpan(createIndexStatementToJSON(s), frag(stmt))
case *ast.CreateJsonIndexStatement:
return addSpan(createJsonIndexStatementToJSON(s), frag(stmt))
case *ast.CreateSpatialIndexStatement:
return addSpan(createSpatialIndexStatementToJSON(s), frag(stmt))
case *ast.CreateAsymmetricKeyStatement:
Expand Down Expand Up @@ -2186,6 +2188,16 @@ func scalarExpressionToJSON(expr ast.ScalarExpression) jsonNode {
}
node["AbsentOrNullOnNull"] = idents
}
if len(e.ReturnType) > 0 {
types := make([]jsonNode, len(e.ReturnType))
for i, dt := range e.ReturnType {
types[i] = dataTypeReferenceToJSON(dt)
}
node["ReturnType"] = types
}
if e.JsonOrderByClause != nil {
node["JsonOrderByClause"] = orderByClauseToJSON(e.JsonOrderByClause)
}
return addSpan(node, frag(expr))
case *ast.PartitionFunctionCall:
node := jsonNode{
Expand Down Expand Up @@ -22785,3 +22797,33 @@ func securityPredicateActionToJSON(action *ast.SecurityPredicateAction) jsonNode
}
return addSpan(node, frag(action))
}

func createJsonIndexStatementToJSON(s *ast.CreateJsonIndexStatement) jsonNode {
node := jsonNode{
"$type": "CreateJsonIndexStatement",
}
if s.JsonColumn != nil {
node["JsonColumn"] = identifierToJSON(s.JsonColumn)
}
if len(s.ForJsonPaths) > 0 {
paths := make([]jsonNode, len(s.ForJsonPaths))
for i, path := range s.ForJsonPaths {
paths[i] = stringLiteralToJSON(path)
}
node["ForJsonPaths"] = paths
}
if s.Name != nil {
node["Name"] = identifierToJSON(s.Name)
}
if s.OnName != nil {
node["OnName"] = schemaObjectNameToJSON(s.OnName)
}
if len(s.IndexOptions) > 0 {
opts := make([]jsonNode, len(s.IndexOptions))
for i, opt := range s.IndexOptions {
opts[i] = indexOptionToJSON(opt)
}
node["IndexOptions"] = opts
}
return addSpan(node, frag(s))
}
Loading
Loading