Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add as of clause for SET and SELECT #1206

Merged
merged 11 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
52 changes: 47 additions & 5 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
_ Node = &FieldList{}
_ Node = &GroupByClause{}
_ Node = &HavingClause{}
_ Node = &AsOfClause{}
_ Node = &Join{}
_ Node = &Limit{}
_ Node = &OnCondition{}
Expand Down Expand Up @@ -1048,6 +1049,8 @@ type SelectStmt struct {
// Lists is filled only when Kind == SelectStmtKindValues
Lists []*RowExpr
With *WithClause
// AS OF is used to see the data as it was at a specific point in time.
AsOf *AsOfClause
}

func (n *WithClause) Restore(ctx *format.RestoreCtx) error {
Expand Down Expand Up @@ -3267,11 +3270,7 @@ func (m FulltextSearchModifier) WithQueryExpansion() bool {
return m&FulltextSearchModifierWithQueryExpansion == FulltextSearchModifierWithQueryExpansion
}

type TimestampBound struct {
Mode TimestampBoundMode
Timestamp ExprNode
}

// TODO: remove the TimestampBoundMode.
type TimestampBoundMode int

const (
Expand All @@ -3281,3 +3280,46 @@ const (
TimestampBoundReadTimestamp
TimestampBoundMinReadTimestamp
)

type TimestampReadModes int

const (
TimestampReadStrong TimestampReadModes = iota
TimestampReadBoundTimestamp
TimestampReadExactTimestamp
)

type TimestampBound struct {
Mode TimestampBoundMode
Timestamp ExprNode
}

type AsOfClause struct {
node
Mode TimestampReadModes
TsExpr ExprNode
}

// Restore implements Node interface.
func (n *AsOfClause) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("AS OF")
if err := n.TsExpr.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AsOfClause.Expr")
}
return nil
}

// Accept implements Node Accept interface.
func (n *AsOfClause) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*AsOfClause)
node, ok := n.TsExpr.Accept(v)
if !ok {
return n, false
}
n.TsExpr = node.(ExprNode)
return v.Leave(n)
}
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ var tokenMap = map[string]int{
"NULLS": nulls,
"NUMERIC": numericType,
"NVARCHAR": nvarcharType,
"OF": of,
"OFF": off,
"OFFSET": offset,
"ON_DUPLICATE": onDuplicate,
Expand Down
Loading