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

// AI built-in function calls (SQL Server 2025 / Fabric DW).

type AIAnalyzeSentimentFunctionCall struct {
Fragment
Input ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AIAnalyzeSentimentFunctionCall) node() {}
func (*AIAnalyzeSentimentFunctionCall) scalarExpression() {}

type AIFixGrammarFunctionCall struct {
Fragment
Input ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AIFixGrammarFunctionCall) node() {}
func (*AIFixGrammarFunctionCall) scalarExpression() {}

type AISummarizeFunctionCall struct {
Fragment
Input ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AISummarizeFunctionCall) node() {}
func (*AISummarizeFunctionCall) scalarExpression() {}

type AIClassifyFunctionCall struct {
Fragment
Input ScalarExpression
Labels []ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AIClassifyFunctionCall) node() {}
func (*AIClassifyFunctionCall) scalarExpression() {}

type AIExtractFunctionCall struct {
Fragment
Input ScalarExpression
Labels []ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AIExtractFunctionCall) node() {}
func (*AIExtractFunctionCall) scalarExpression() {}

type AITranslateFunctionCall struct {
Fragment
Input ScalarExpression
Language ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AITranslateFunctionCall) node() {}
func (*AITranslateFunctionCall) scalarExpression() {}

type AIGenerateResponseFunctionCall struct {
Fragment
PromptPart1 ScalarExpression
PromptPart2 ScalarExpression
OnErrorClause AIOnErrorClause
}

func (*AIGenerateResponseFunctionCall) node() {}
func (*AIGenerateResponseFunctionCall) scalarExpression() {}

type AIGenerateEmbeddingsFunctionCall struct {
Fragment
Input ScalarExpression
ModelName *SchemaObjectName
OptionalParameters ScalarExpression
}

func (*AIGenerateEmbeddingsFunctionCall) node() {}
func (*AIGenerateEmbeddingsFunctionCall) scalarExpression() {}

type InvokeExternalApiFunctionCall struct {
Fragment
FunctionSetName *StringLiteral
FunctionName *StringLiteral
Arguments []ScalarExpression
}

func (*InvokeExternalApiFunctionCall) node() {}
func (*InvokeExternalApiFunctionCall) scalarExpression() {}

// AIOnErrorClause is the ON ERROR clause of an AI function call.
type AIOnErrorClause interface {
Node
aiOnErrorClause()
}

// AIErrorOnErrorClause represents ERROR ON ERROR.
type AIErrorOnErrorClause struct{ Fragment }

// AINullOnErrorClause represents NULL ON ERROR.
type AINullOnErrorClause struct{ Fragment }

// AIDefaultOnErrorClause represents DEFAULT 'value' ON ERROR.
type AIDefaultOnErrorClause struct {
Fragment
Value *StringLiteral
}

func (*AIErrorOnErrorClause) node() {}
func (*AIErrorOnErrorClause) aiOnErrorClause() {}
func (*AINullOnErrorClause) node() {}
func (*AINullOnErrorClause) aiOnErrorClause() {}
func (*AIDefaultOnErrorClause) node() {}
func (*AIDefaultOnErrorClause) aiOnErrorClause() {}

// AIGenerateFixedChunksTableReference represents
// AI_GENERATE_CHUNKS(SOURCE = ..., CHUNK_TYPE = FIXED, CHUNK_SIZE = ...
// [, OVERLAP = ...] [, ENABLE_CHUNK_SET_ID = ...]).
type AIGenerateFixedChunksTableReference struct {
Fragment
Source ScalarExpression
ChunkType *Identifier
ChunkSize ScalarExpression
Overlap ScalarExpression
EnableChunkSetId ScalarExpression
Alias *Identifier
}

func (*AIGenerateFixedChunksTableReference) node() {}
func (*AIGenerateFixedChunksTableReference) tableReference() {}
2 changes: 1 addition & 1 deletion ast/drop_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (s *DropExternalResourcePoolStatement) node() {}
type DropExternalModelStatement struct {
Fragment
IsIfExists bool
Name *SchemaObjectName
Name *Identifier
}

func (s *DropExternalModelStatement) statement() {}
Expand Down
42 changes: 42 additions & 0 deletions ast/external_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ast

// ExternalModelStatement holds the members shared by CREATE and ALTER
// EXTERNAL MODEL.
type ExternalModelStatement struct {
Name *Identifier
Location ScalarExpression
ApiFormat ScalarExpression
ModelType string // e.g. "EMBEDDINGS"; empty when not specified
ModelTypeSpecification *ExternalModelTypeSpecification
ModelName ScalarExpression
Credential *Identifier
Parameters ScalarExpression
LocalRuntimePath ScalarExpression
}

// CreateExternalModelStatement represents CREATE EXTERNAL MODEL.
type CreateExternalModelStatement struct {
Fragment
ExternalModelStatement
Owner *Identifier
}

func (*CreateExternalModelStatement) node() {}
func (*CreateExternalModelStatement) statement() {}

// AlterExternalModelStatement represents ALTER EXTERNAL MODEL ... SET (...).
type AlterExternalModelStatement struct {
Fragment
ExternalModelStatement
}

func (*AlterExternalModelStatement) node() {}
func (*AlterExternalModelStatement) statement() {}

// ExternalModelTypeSpecification represents the MODEL_TYPE option.
type ExternalModelTypeSpecification struct {
Fragment
OptionKind string
}

func (*ExternalModelTypeSpecification) node() {}
51 changes: 50 additions & 1 deletion parser/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func statementToJSON(stmt ast.Statement) jsonNode {
return addSpan(dropExternalResourcePoolStatementToJSON(s), frag(stmt))
case *ast.DropExternalModelStatement:
return addSpan(dropExternalModelStatementToJSON(s), frag(stmt))
case *ast.CreateExternalModelStatement:
return addSpan(externalModelStatementToJSON("CreateExternalModelStatement", s.Owner, &s.ExternalModelStatement), frag(stmt))
case *ast.AlterExternalModelStatement:
return addSpan(externalModelStatementToJSON("AlterExternalModelStatement", nil, &s.ExternalModelStatement), frag(stmt))
case *ast.DropWorkloadGroupStatement:
return addSpan(dropWorkloadGroupStatementToJSON(s), frag(stmt))
case *ast.DropWorkloadClassifierStatement:
Expand Down Expand Up @@ -2045,6 +2049,9 @@ func selectElementToJSON(elem ast.SelectElement) jsonNode {
}

func scalarExpressionToJSON(expr ast.ScalarExpression) jsonNode {
if node, ok := aiFunctionCallToJSON(expr); ok {
return node
}
switch e := expr.(type) {
case *ast.ColumnReferenceExpression:
node := jsonNode{
Expand Down Expand Up @@ -3264,6 +3271,30 @@ func tableReferenceToJSON(ref ast.TableReference) jsonNode {
}
node["ForPath"] = r.ForPath
return addSpan(node, frag(ref))
case *ast.AIGenerateFixedChunksTableReference:
node := jsonNode{
"$type": "AIGenerateFixedChunksTableReference",
}
if r.ChunkSize != nil {
node["ChunkSize"] = scalarExpressionToJSON(r.ChunkSize)
}
if r.Overlap != nil {
node["Overlap"] = scalarExpressionToJSON(r.Overlap)
}
if r.EnableChunkSetId != nil {
node["EnableChunkSetId"] = scalarExpressionToJSON(r.EnableChunkSetId)
}
if r.Source != nil {
node["Source"] = scalarExpressionToJSON(r.Source)
}
if r.ChunkType != nil {
node["ChunkType"] = identifierToJSON(r.ChunkType)
}
if r.Alias != nil {
node["Alias"] = identifierToJSON(r.Alias)
}
node["ForPath"] = false
return addSpan(node, frag(ref))
case *ast.VectorSearchTableReference:
node := jsonNode{
"$type": "VectorSearchTableReference",
Expand Down Expand Up @@ -9369,6 +9400,12 @@ func (p *Parser) parseGrantStatement() (*ast.GrantStatement, error) {
p.nextToken() // consume ROLE
}
stmt.SecurityTargetObject.ObjectKind = "ApplicationRole"
case "EXTERNAL":
p.nextToken() // consume EXTERNAL
if strings.ToUpper(p.curTok.Literal) == "MODEL" {
p.nextToken() // consume MODEL
}
stmt.SecurityTargetObject.ObjectKind = "ExternalModel"
case "ASYMMETRIC":
p.nextToken() // consume ASYMMETRIC
if strings.ToUpper(p.curTok.Literal) == "KEY" {
Expand Down Expand Up @@ -9669,6 +9706,12 @@ func (p *Parser) parseRevokeStatement() (*ast.RevokeStatement, error) {
p.nextToken()
}
stmt.SecurityTargetObject.ObjectKind = "ApplicationRole"
case "EXTERNAL":
p.nextToken() // consume EXTERNAL
if strings.ToUpper(p.curTok.Literal) == "MODEL" {
p.nextToken() // consume MODEL
}
stmt.SecurityTargetObject.ObjectKind = "ExternalModel"
case "ASYMMETRIC":
p.nextToken()
if strings.ToUpper(p.curTok.Literal) == "KEY" {
Expand Down Expand Up @@ -9951,6 +9994,12 @@ func (p *Parser) parseDenyStatement() (*ast.DenyStatement, error) {
p.nextToken()
}
stmt.SecurityTargetObject.ObjectKind = "ApplicationRole"
case "EXTERNAL":
p.nextToken() // consume EXTERNAL
if strings.ToUpper(p.curTok.Literal) == "MODEL" {
p.nextToken() // consume MODEL
}
stmt.SecurityTargetObject.ObjectKind = "ExternalModel"
case "ASYMMETRIC":
p.nextToken()
if strings.ToUpper(p.curTok.Literal) == "KEY" {
Expand Down Expand Up @@ -17968,7 +18017,7 @@ func dropExternalModelStatementToJSON(s *ast.DropExternalModelStatement) jsonNod
"IsIfExists": s.IsIfExists,
}
if s.Name != nil {
node["Name"] = schemaObjectNameToJSON(s.Name)
node["Name"] = identifierToJSON(s.Name)
}
return addSpan(node, frag(s))
}
Expand Down
Loading
Loading