Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/with-expr
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Dec 18, 2024
2 parents 85c4ab3 + bbd31cf commit fafe375
Show file tree
Hide file tree
Showing 500 changed files with 2,623 additions and 6,864 deletions.
112 changes: 94 additions & 18 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (CountStarExpr) isExpr() {}
func (CastExpr) isExpr() {}
func (ExtractExpr) isExpr() {}
func (WithExpr) isExpr() {}
func (ReplaceFieldsExpr) isExpr() {}
func (CaseExpr) isExpr() {}
func (IfExpr) isExpr() {}
func (ParenExpr) isExpr() {}
Expand Down Expand Up @@ -218,6 +219,7 @@ type Arg interface {
func (ExprArg) isArg() {}
func (IntervalArg) isArg() {}
func (SequenceArg) isArg() {}
func (LambdaArg) isArg() {}

// NullHandlingModifier represents IGNORE/RESPECT NULLS of aggregate function calls
type NullHandlingModifier interface {
Expand Down Expand Up @@ -1193,6 +1195,21 @@ type SequenceArg struct {
Expr Expr
}

// LambdaArg is lambda expression argument of the generic function call.
//
// {{if .Lparen.Invalid}}{{.Args | sqlJoin ", "}}{{else}}({{.Args | sqlJoin ", "}}) -> {{.Expr | sql}}
//
// Note: Args won't be empty. If Lparen is not appeared, Args have exactly one element.
type LambdaArg struct {
// pos = Lparen || Args[0].pos
// end = Expr.end

Lparen token.Pos // optional

Args []*Ident // if Lparen.Invalid() then len(Args) = 1 else len(Args) > 0
Expr Expr
}

// NamedArg represents a name and value pair in named arguments
//
// {{.Name | sql}} => {{.Value | sql}}
Expand Down Expand Up @@ -1274,6 +1291,31 @@ type ExtractExpr struct {
AtTimeZone *AtTimeZone // optional
}

// ReplaceFieldsArg is value AS field_path node in ReplaceFieldsExpr.
//
// {{.Expr | sql}} AS {{.Field | sql}}
type ReplaceFieldsArg struct {
// pos = Expr.pos
// end = Field.end

Expr Expr
Field *Path
}

// ReplaceFieldsExpr is REPLACE_FIELDS call expression node.
//
// REPLACE_FIELDS({{.Expr.| sql}}, {{.Fields | sqlJoin ", "}})
type ReplaceFieldsExpr struct {
// pos = ReplaceFields
// end = Rparen + 1

ReplaceFields token.Pos // position of "REPLACE_FIELDS" keyword
Rparen token.Pos // position of ")"

Expr Expr
Fields []*ReplaceFieldsArg
}

// AtTimeZone is AT TIME ZONE clause in EXTRACT call.
//
// AT TIME ZONE {{.Expr | sql}}
Expand Down Expand Up @@ -3073,15 +3115,17 @@ type SizedSchemaType struct {

// ArraySchemaType is array type node in schema.
//
// ARRAY<{{.Item | sql}}>
// ARRAY<{{.Item | sql}}>{{if .NamedArgs}}({{.NamedArgs | sqlJoin ", "}}){{end}}
type ArraySchemaType struct {
// pos = Array
// end = Gt + 1
// end = Rparen + 1 || Gt + 1

Array token.Pos // position of "ARRAY" keyword
Gt token.Pos // position of ">"
Array token.Pos // position of "ARRAY" keyword
Gt token.Pos // position of ">"
Rparen token.Pos // position of ")" when len(NamedArgs) > 0

Item SchemaType // ScalarSchemaType or SizedSchemaType
Item SchemaType // ScalarSchemaType or SizedSchemaType
NamedArgs []*NamedArg
}

// ================================================================================
Expand Down Expand Up @@ -3149,20 +3193,48 @@ type AlterSearchIndex struct {
//
// ================================================================================

// WithAction is WITH ACTION clause in ThenReturn.
//
// WITH ACTION {{.Alias | sqlOpt}}
type WithAction struct {
// pos = With
// end = Alias.end || Action + 6

With token.Pos // position of "WITH" keyword
Action token.Pos // position of "ACTION" keyword

Alias *AsAlias // optional
}

// ThenReturn is THEN RETURN clause in DML.
//
// THEN RETURN {{.WithAction | sqlOpt}} {{.Items | sqlJoin ", "}}
type ThenReturn struct {
// pos = Then
// end = Items[$].end

Then token.Pos // position of "THEN" keyword

WithAction *WithAction // optional
Items []SelectItem
}

// Insert is INSERT statement node.
//
// INSERT {{if .InsertOrType}}OR .InsertOrType{{end}}INTO {{.TableName | sql}} ({{.Columns | sqlJoin ","}}) {{.Input | sql}}
// {{.ThenReturn | sqlOpt}}
type Insert struct {
// pos = Insert
// end = Input.end
// end = (ThenReturn ?? Input).end

Insert token.Pos // position of "INSERT" keyword

InsertOrType InsertOrType

TableName *Ident
Columns []*Ident
Input InsertInput
TableName *Ident
Columns []*Ident
Input InsertInput
ThenReturn *ThenReturn // optional
}

// ValuesInput is VALUES clause in INSERT.
Expand Down Expand Up @@ -3215,31 +3287,35 @@ type SubQueryInput struct {
// Delete is DELETE statement.
//
// DELETE FROM {{.TableName | sql}} {{.As | sqlOpt}} {{.Where | sql}}
// {{.ThenReturn | sqlOpt}}
type Delete struct {
// pos = Delete
// end = Where.end
// end = (ThenReturn ?? Where).end

Delete token.Pos // position of "DELETE" keyword

TableName *Ident
As *AsAlias // optional
Where *Where
TableName *Ident
As *AsAlias // optional
Where *Where
ThenReturn *ThenReturn // optional
}

// Update is UPDATE statement.
//
// UPDATE {{.TableName | sql}} {{.As | sqlOpt}}
// SET {{.Updates | sqlJoin ","}} {{.Where | sql}}
// {{.ThenReturn | sqlOpt}}
type Update struct {
// pos = Update
// end = Where.end
// end = (ThenReturn ?? Where).end

Update token.Pos // position of "UPDATE" keyword

TableName *Ident
As *AsAlias // optional
Updates []*UpdateItem // len(Updates) > 0
Where *Where
TableName *Ident
As *AsAlias // optional
Updates []*UpdateItem // len(Updates) > 0
Where *Where
ThenReturn *ThenReturn // optional
}

// UpdateItem is SET clause items in UPDATE.
Expand Down
6 changes: 3 additions & 3 deletions ast/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const (
JoinTypeJoinHint JoinHintKey = "JOIN_TYPE"
)

// JoinMethod is used for prefix of JOIN, not for hint.
type JoinMethod string

const (
HashJoinMethod JoinMethod = "HASH"
ApplyJoinMethod JoinMethod = "APPLY"
LoopJoinMethod JoinMethod = "LOOP" // Undocumented, but the Spanner accept this value at least.
HashJoinMethod JoinMethod = "HASH"
LookupJoinMethod JoinMethod = "LOOKUP" // Undocumented, but the GoogleSQL can parse this value.
)

type PositionKeyword string
Expand Down
48 changes: 44 additions & 4 deletions ast/pos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fafe375

Please sign in to comment.