Skip to content

Commit

Permalink
ast, mysql: add window function flag and error message (pingcap#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx committed Jan 3, 2019
1 parent 71b7107 commit c251d5a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
FlagHasVariable
FlagHasDefault
FlagPreEvaluated
FlagHasWindowFunc
)

// ExprNode is a node that can be evaluated.
Expand Down
14 changes: 14 additions & 0 deletions ast/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func HasAggFlag(expr ExprNode) bool {
return expr.GetFlag()&FlagHasAggregateFunc > 0
}

func HasWindowFlag(expr ExprNode) bool {
return expr.GetFlag()&FlagHasWindowFunc > 0
}

// SetFlag sets flag for expression.
func SetFlag(n Node) {
var setter flagSetter
Expand All @@ -38,6 +42,8 @@ func (f *flagSetter) Leave(in Node) (Node, bool) {
switch x := in.(type) {
case *AggregateFuncExpr:
f.aggregateFunc(x)
case *WindowFuncExpr:
f.windowFunc(x)
case *BetweenExpr:
x.SetFlag(x.Expr.GetFlag() | x.Left.GetFlag() | x.Right.GetFlag())
case *BinaryOperationExpr:
Expand Down Expand Up @@ -154,3 +160,11 @@ func (f *flagSetter) aggregateFunc(x *AggregateFuncExpr) {
}
x.SetFlag(flag)
}

func (f *flagSetter) windowFunc(x *WindowFuncExpr) {
flag := FlagHasWindowFunc
for _, val := range x.Args {
flag |= val.GetFlag()
}
x.SetFlag(flag)
}
21 changes: 21 additions & 0 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,27 @@ const (
ErrInvalidJSONPathWildcard = 3149
ErrInvalidJSONContainsPathType = 3150
ErrJSONUsedAsKey = 3152
ErrWindowNoSuchWindow = 3579
ErrWindowCircularityInWindowGraph = 3580
ErrWindowNoChildPartitioning = 3581
ErrWindowNoInherentFrame = 3582
ErrWindowNoRedefineOrderBy = 3583
ErrWindowFrameStartIllegal = 3584
ErrWindowFrameEndIllegal = 3585
ErrWindowFrameIllegal = 3586
ErrWindowRangeFrameOrderType = 3587
ErrWindowRangeFrameTEMPORALType = 3588
ErrWindowRangeFrameNumericType = 3589
ErrWindowRangeBoundNotConstant = 3590
ErrWindowDuplicateName = 3591
ErrWindowIllegalOrderBy = 3592
ErrWindowInvalidWindowFuncUse = 3593
ErrWindowInvalidWindowFuncAliasUse = 3594
ErrWindowNestedWindowFuncUseInWindowSpec = 3595
ErrWindowRowsIntervalUse = 3596
ErrWindowNoGroupOrderUnused = 3597
ErrWindowExplainJson = 3598
ErrWindowFunctionIgnoresFrame = 3599

// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
Expand Down
21 changes: 21 additions & 0 deletions mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,27 @@ var MySQLErrName = map[uint16]string{
ErrInvalidJSONPathWildcard: "In this situation, path expressions may not contain the * and ** tokens.",
ErrInvalidJSONContainsPathType: "The second argument can only be either 'one' or 'all'.",
ErrJSONUsedAsKey: "JSON column '%-.192s' cannot be used in key specification.",
ErrWindowNoSuchWindow: "Window name '%s' is not defined.",
ErrWindowCircularityInWindowGraph: "There is a circularity in the window dependency graph.",
ErrWindowNoChildPartitioning: "A window which depends on another cannot define partitioning.",
ErrWindowNoInherentFrame: "Window '%s' has a frame definition, so cannot be referenced by another window.",
ErrWindowNoRedefineOrderBy: "Window '%s' cannot inherit '%s' since both contain an ORDER BY clause.",
ErrWindowFrameStartIllegal: "Window '%s': frame start cannot be UNBOUNDED FOLLOWING.",
ErrWindowFrameEndIllegal: "Window '%s': frame end cannot be UNBOUNDED PRECEDING.",
ErrWindowFrameIllegal: "Window '%s': frame start or end is negative, NULL or of non-integral type",
ErrWindowRangeFrameOrderType: "Window '%s' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type",
ErrWindowRangeFrameTEMPORALType: "Window '%s' with RANGE frame has ORDER BY expression of datetime type. Only INTERVAL bound value allowed.",
ErrWindowRangeFrameNumericType: "Window '%s' with RANGE frame has ORDER BY expression of numeric type, INTERVAL bound value not allowed.",
ErrWindowRangeBoundNotConstant: "Window '%s' has a non-constant frame bound.",
ErrWindowDuplicateName: "Window '%s' is defined twice.",
ErrWindowIllegalOrderBy: "Window '%s': ORDER BY or PARTITION BY uses legacy position indication which is not supported, use expression.",
ErrWindowInvalidWindowFuncUse: "You cannot use the window function '%s' in this context.'",
ErrWindowInvalidWindowFuncAliasUse: "You cannot use the alias '%s' of an expression containing a window function in this context.'",
ErrWindowNestedWindowFuncUseInWindowSpec: "You cannot nest a window function in the specification of window '%s'.",
ErrWindowRowsIntervalUse: "Window '%s': INTERVAL can only be used with RANGE frames.",
ErrWindowNoGroupOrderUnused: "ASC or DESC with GROUP BY isn't allowed with window functions; put ASC or DESC in ORDER BY",
ErrWindowExplainJson: "To get information about window functions use EXPLAIN FORMAT=JSON",
ErrWindowFunctionIgnoresFrame: "Window function '%s' ignores the frame clause of window '%s' and aggregates over the whole partition",

// TiDB errors.
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
Expand Down

0 comments on commit c251d5a

Please sign in to comment.