Documentation ¶
Index ¶
- Constants
- Variables
- func ContainAggregateFunc(e expression.Expression) bool
- func Eval(v expression.Expression, ctx context.Context, env map[interface{}]interface{}) (y interface{})
- func EvalBoolExpr(ctx context.Context, expr expression.Expression, m map[interface{}]interface{}) (bool, error)
- func Expr(v interface{}) expression.Expression
- func FastEval(v interface{}) interface{}
- func GetTimeValue(ctx context.Context, v interface{}, tp byte, fsp int) (interface{}, error)
- func IsCurrentTimeExpr(e expression.Expression) bool
- func IsQualified(name string) bool
- func MentionedAggregateFuncs(e expression.Expression) []expression.Expression
- func MentionedColumns(e expression.Expression) []string
- func NewBetween(expr, lo, hi expression.Expression, not bool) (expression.Expression, error)
- func NewBinaryOperation(op opcode.Op, x, y expression.Expression) expression.Expression
- func NewCall(f string, args []expression.Expression, distinct bool) (v expression.Expression, err error)
- func NewUnaryOperation(op opcode.Op, l expression.Expression) expression.Expression
- type Assignment
- type Between
- type BinaryOperation
- func (o *BinaryOperation) Clone() (expression.Expression, error)
- func (o *BinaryOperation) Eval(ctx context.Context, args map[interface{}]interface{}) (r interface{}, err error)
- func (o *BinaryOperation) IsIdentRelOpVal() (bool, string, interface{}, error)
- func (o *BinaryOperation) IsStatic() bool
- func (o *BinaryOperation) String() string
- type Call
- type Conversion
- type Default
- type FunctionCase
- type FunctionCast
- type FunctionConvert
- type FunctionSubstring
- type Ident
- type IsNull
- type IsTruth
- type PExpr
- type ParamMarker
- type PatternIn
- type PatternLike
- type PatternRegexp
- type Position
- type SubQuery
- type TypeStar
- type UnaryOperation
- type Value
- type Values
- type Variable
- type WhenClause
Constants ¶
const ( // BuiltinFuncDatabase is the keyword for Database function. BuiltinFuncDatabase = "database" // BuiltinFuncIf is the keyword for If function. BuiltinFuncIf = "if" BuiltinFuncLeft = "left" )
Builin functions entry key with name conflict with keywords.
const ( // ExprEvalFn is the key saving Call expression. ExprEvalFn = "$fn" // ExprEvalArgCtx is the key saving Context for a Call expression. ExprEvalArgCtx = "$ctx" // ExprAggDone is the key indicating that aggregate function is done. ExprAggDone = "$aggDone" // ExprEvalArgAggEmpty is the key to evaluate the aggregate function for empty table. ExprEvalArgAggEmpty = "$agg0" // ExprEvalDefaultName is the key saving default column name for Default expression. ExprEvalDefaultName = "$defaultName" // ExprEvalIdentFunc is the key saving a function to retrieve value for identifier name. ExprEvalIdentFunc = "$identFunc" // ExprEvalPositionFunc is the key saving a Position expresion. ExprEvalPositionFunc = "$positionFunc" // ExprAggDistinct is the key saving a distinct aggregate. ExprAggDistinct = "$aggDistinct" // ExprEvalValuesFunc is the key saving a function to retrieve value for column name. ExprEvalValuesFunc = "$valuesFunc" )
Variables ¶
var ( // CurrentTimestamp is the keyword getting default value for datetime and timestamp type. CurrentTimestamp = "CURRENT_TIMESTAMP" // CurrentTimeExpr is the expression retireving default value for datetime and timestamp type. CurrentTimeExpr = &Ident{model.NewCIStr(CurrentTimestamp)} // ZeroTimestamp shows the zero datetime and timestamp. ZeroTimestamp = "0000-00-00 00:00:00" )
Functions ¶
func ContainAggregateFunc ¶
func ContainAggregateFunc(e expression.Expression) bool
ContainAggregateFunc checks whether expression e contains an aggregate function, like count(*) or other.
func Eval ¶
func Eval(v expression.Expression, ctx context.Context, env map[interface{}]interface{}) (y interface{})
Eval is a helper function evaluates expression v and do a panic if evaluating error.
func EvalBoolExpr ¶
func EvalBoolExpr(ctx context.Context, expr expression.Expression, m map[interface{}]interface{}) (bool, error)
EvalBoolExpr evaluates an expression and convert its return value to bool.
func Expr ¶
func Expr(v interface{}) expression.Expression
Expr removes parenthese expression, e.g, (expr) -> expr.
func FastEval ¶
func FastEval(v interface{}) interface{}
FastEval evaluates Value and static +/- Unary expression and returns its value.
func GetTimeValue ¶
GetTimeValue gets the time value with type tp.
func IsCurrentTimeExpr ¶
func IsCurrentTimeExpr(e expression.Expression) bool
IsCurrentTimeExpr returns whether e is CurrentTimeExpr.
func IsQualified ¶
IsQualified returns whether name contains ".".
func MentionedAggregateFuncs ¶
func MentionedAggregateFuncs(e expression.Expression) []expression.Expression
MentionedAggregateFuncs returns a list of the Call expression which is aggregate function.
func MentionedColumns ¶
func MentionedColumns(e expression.Expression) []string
MentionedColumns returns a list of names for Ident expression.
func NewBetween ¶
func NewBetween(expr, lo, hi expression.Expression, not bool) (expression.Expression, error)
NewBetween creates a Between expression for "a between c and d" or "a not between c and d". If a doesn't contain any aggregate function, we can split it with logic and comparison expressions. For example:
a between 10 and 15 -> a >= 10 && a <= 15 a not between 10 and 15 -> a < 10 || b > 15
func NewBinaryOperation ¶
func NewBinaryOperation(op opcode.Op, x, y expression.Expression) expression.Expression
NewBinaryOperation creates a binary expression with op as the operator code and x, y as the left and right operator expression.
func NewCall ¶
func NewCall(f string, args []expression.Expression, distinct bool) (v expression.Expression, err error)
NewCall creates a Call expression with function name f, function args arg and a distinct flag whether this function supports distinct or not.
func NewUnaryOperation ¶
func NewUnaryOperation(op opcode.Op, l expression.Expression) expression.Expression
NewUnaryOperation creates an unary expression.
Types ¶
type Assignment ¶
type Assignment struct { // ColName is the variable name we want to set. ColName string // Expr is the expression assigning to ColName. Expr expression.Expression }
Assignment is the expression for assignment, like a = 1.
func (*Assignment) String ¶
func (a *Assignment) String() string
String returns Assignment representation.
type Between ¶
type Between struct { // Expr is the expression to be checked. Expr expression.Expression // Left is the expression for minimal value in the range. Left expression.Expression // Right is the expression for maximum value in the range. Right expression.Expression // Not is true, the expression is "not between and". Not bool }
Between is for "between and" or "not between and" expression.
func (*Between) Clone ¶
func (b *Between) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
type BinaryOperation ¶
type BinaryOperation struct { // Op is the operator code for BinaryOperation. Op opcode.Op // L is the left expression in BinaryOperation. L expression.Expression // R is the right expression in BinaryOperation. R expression.Expression }
BinaryOperation is for binary operation like 1 + 1, 1 - 1, etc.
func (*BinaryOperation) Clone ¶
func (o *BinaryOperation) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*BinaryOperation) Eval ¶
func (o *BinaryOperation) Eval(ctx context.Context, args map[interface{}]interface{}) (r interface{}, err error)
Eval implements the Expression Eval interface.
func (*BinaryOperation) IsIdentRelOpVal ¶
func (o *BinaryOperation) IsIdentRelOpVal() (bool, string, interface{}, error)
IsIdentRelOpVal checks left expression is Ident expression and right is Value expression for relational comparison, then returns left identifier name and right value.
func (*BinaryOperation) IsStatic ¶
func (o *BinaryOperation) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*BinaryOperation) String ¶
func (o *BinaryOperation) String() string
String implements the Expression String interface.
type Call ¶
type Call struct { // F is the function name. F string // Args is the function args. Args []expression.Expression // Distinct only affetcts sum, avg, count, group_concat, // so we can ignore it in other functions Distinct bool }
Call is for function expression.
func (*Call) Clone ¶
func (c *Call) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*Call) Eval ¶
func (c *Call) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type Conversion ¶
type Conversion struct { // Tp is the conversion type. Tp byte // Val is the expression to be converted. Val expression.Expression }
Conversion is the conversion expression like "type ()".
func (*Conversion) Clone ¶
func (c *Conversion) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*Conversion) Eval ¶
func (c *Conversion) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
func (*Conversion) IsStatic ¶
func (c *Conversion) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*Conversion) String ¶
func (c *Conversion) String() string
String implements the Expression String interface.
type Default ¶
type Default struct { // Name is the column name Name string }
Default is the default expression using default value for a column.
func (*Default) Clone ¶
func (v *Default) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
type FunctionCase ¶
type FunctionCase struct { // Value is the compare value expression. Value expression.Expression // WhenClauses is the condition check expression. WhenClauses []*WhenClause // ElseClause is the else result expression. ElseClause expression.Expression }
FunctionCase is the case expression.
func (*FunctionCase) Clone ¶
func (f *FunctionCase) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*FunctionCase) Eval ¶
func (f *FunctionCase) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error)
Eval implements the Expression Eval interface.
func (*FunctionCase) IsStatic ¶
func (f *FunctionCase) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*FunctionCase) String ¶
func (f *FunctionCase) String() string
String implements the Expression String interface.
type FunctionCast ¶
type FunctionCast struct { // Expr is the expression to be converted. Expr expression.Expression // Tp is the conversion type. Tp *types.FieldType }
FunctionCast is the cast function converting value to another type, e.g, cast(expr AS signed). See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast
func (*FunctionCast) Clone ¶
func (f *FunctionCast) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*FunctionCast) Eval ¶
func (f *FunctionCast) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error)
Eval implements the Expression Eval interface.
func (*FunctionCast) IsStatic ¶
func (f *FunctionCast) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*FunctionCast) String ¶
func (f *FunctionCast) String() string
String implements the Expression String interface.
type FunctionConvert ¶
type FunctionConvert struct { Expr expression.Expression Charset string }
FunctionConvert provides a way to convert data between different character sets. See: https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
func (*FunctionConvert) Clone ¶
func (f *FunctionConvert) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*FunctionConvert) Eval ¶
func (f *FunctionConvert) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error)
Eval implements the Expression Eval interface.
func (*FunctionConvert) IsStatic ¶
func (f *FunctionConvert) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*FunctionConvert) String ¶
func (f *FunctionConvert) String() string
String implements the Expression String interface.
type FunctionSubstring ¶
type FunctionSubstring struct { StrExpr expression.Expression Pos expression.Expression Len expression.Expression }
FunctionSubstring returns the substring as specified. See: https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring
func (*FunctionSubstring) Clone ¶
func (f *FunctionSubstring) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*FunctionSubstring) Eval ¶
func (f *FunctionSubstring) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error)
Eval implements the Expression Eval interface.
func (*FunctionSubstring) IsStatic ¶
func (f *FunctionSubstring) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*FunctionSubstring) String ¶
func (f *FunctionSubstring) String() string
String implements the Expression String interface.
type Ident ¶
type Ident struct { // model.CIStr contains origin identifier name and its lowercase name. model.CIStr }
Ident is the identifier expression.
func (*Ident) Clone ¶
func (i *Ident) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*Ident) Equal ¶
Equal checks equation with another Ident expression using lowercase identifier name.
func (*Ident) Eval ¶
func (i *Ident) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type IsNull ¶
type IsNull struct { // Expr is the expression to be checked. Expr expression.Expression // Not is true, the expression is "is not null". Not bool }
IsNull is the expression for null check.
func (*IsNull) Clone ¶
func (is *IsNull) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*IsNull) Eval ¶
func (is *IsNull) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type IsTruth ¶
type IsTruth struct { // Expr is the expression to be checked. Expr expression.Expression // Not is true, the expression is "is not true/false". Not bool // True indicates checking true or false. True int8 }
IsTruth is the expression for true/false check.
func (*IsTruth) Clone ¶
func (is *IsTruth) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*IsTruth) Eval ¶
func (is *IsTruth) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type PExpr ¶
type PExpr struct { // Expr is the expression in parenthese. Expr expression.Expression }
PExpr is the parenthese expression.
func (*PExpr) Clone ¶
func (p *PExpr) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*PExpr) Eval ¶
func (p *PExpr) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type ParamMarker ¶
type ParamMarker struct { // Expr is the expression to be evaluated in this place holder. Expr expression.Expression }
ParamMarker expresion holds a place for another expression. Used in parsing prepare statement.
func (*ParamMarker) Clone ¶
func (pm *ParamMarker) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*ParamMarker) Eval ¶
func (pm *ParamMarker) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
func (*ParamMarker) IsStatic ¶
func (pm *ParamMarker) IsStatic() bool
IsStatic implements the Expression IsStatic interface, always returns false.
func (*ParamMarker) String ¶
func (pm *ParamMarker) String() string
String implements the Expression String interface.
type PatternIn ¶
type PatternIn struct { // Expr is the value expression to be compared. Expr expression.Expression // List is the list expression in compare list. List []expression.Expression // Not is true, the expression is "not in". Not bool // Sel is the select statement. Sel plan.Planner }
PatternIn is the expression for in operator, like "expr in (1, 2, 3)" or "expr in (select c from t)".
func (*PatternIn) Clone ¶
func (n *PatternIn) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*PatternIn) Eval ¶
func (n *PatternIn) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type PatternLike ¶
type PatternLike struct { // Expr is the expression to be checked. Expr expression.Expression // Pattern is the like expression. Pattern expression.Expression // Not is true, the expression is "not like". Not bool // contains filtered or unexported fields }
PatternLike is the expression for like operator, e.g, expr like "%123%"
func (*PatternLike) Clone ¶
func (p *PatternLike) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*PatternLike) Eval ¶
func (p *PatternLike) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
func (*PatternLike) IsStatic ¶
func (p *PatternLike) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*PatternLike) String ¶
func (p *PatternLike) String() string
String implements the Expression String interface.
type PatternRegexp ¶
type PatternRegexp struct { // Expr is the expression to be checked. Expr expression.Expression // Pattern is the expression for pattern. Pattern expression.Expression // Re is the compiled regexp. Re *regexp.Regexp // Sexpr is the string for Expr expression. Sexpr *string // Not is true, the expression is "not rlike", Not bool }
PatternRegexp is the pattern expression for pattern match. TODO: refactor later.
func (*PatternRegexp) Clone ¶
func (p *PatternRegexp) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*PatternRegexp) Eval ¶
func (p *PatternRegexp) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
func (*PatternRegexp) IsStatic ¶
func (p *PatternRegexp) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*PatternRegexp) String ¶
func (p *PatternRegexp) String() string
String implements the Expression String interface.
type Position ¶
type Position struct { // N is the position, started from 1 now. N int // Name is the corresponding field name if we want better format and explain instead of position. Name string }
Position is the expression for order by and group by position. MySQL use position expression started from 1, it looks a little confused inner. maybe later we will use 0 at first.
func (*Position) Clone ¶
func (p *Position) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*Position) Eval ¶
func (p *Position) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type SubQuery ¶
type SubQuery struct { // Stmt is the sub select statement. Stmt stmt.Statement // Value holds the sub select result. Value interface{} }
SubQuery expresion holds a select statement. TODO: complete according to https://dev.mysql.com/doc/refman/5.7/en/subquery-restrictions.html
func (*SubQuery) Clone ¶
func (sq *SubQuery) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*SubQuery) Eval ¶
func (sq *SubQuery) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface.
type UnaryOperation ¶
type UnaryOperation struct { // Op is the operator opcode. Op opcode.Op // V is the unary expression. V expression.Expression }
UnaryOperation is the expression for unary operator.
func (*UnaryOperation) Clone ¶
func (u *UnaryOperation) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*UnaryOperation) Eval ¶
func (u *UnaryOperation) Eval(ctx context.Context, args map[interface{}]interface{}) (r interface{}, err error)
Eval implements the Expression Eval interface.
func (*UnaryOperation) IsStatic ¶
func (u *UnaryOperation) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*UnaryOperation) String ¶
func (u *UnaryOperation) String() string
String implements the Expression String interface.
type Value ¶
type Value struct {
// Val holds simple value.
Val interface{}
}
Value is the expression holding simple value.
func (Value) Clone ¶
func (l Value) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
type Values ¶
Values is the expression used in INSERT VALUES
func (*Values) Clone ¶
func (i *Values) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*Values) Eval ¶
func (i *Values) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error)
Eval implements the Expression Eval interface. See: https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
type Variable ¶
type Variable struct { // Name is the variable name. Name string // IsGlobal indicates whether this variable is global. IsGlobal bool // IsSystem indicates whether this variable is a global variable in current session. IsSystem bool }
Variable is the expression for variable.
func (*Variable) Clone ¶
func (v *Variable) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
type WhenClause ¶
type WhenClause struct { // Expr is the condition expression in WhenClause. Expr expression.Expression // Result is the result expression in WhenClause. Result expression.Expression }
WhenClause is the expression in Case expression for "when condition then result".
func (*WhenClause) Clone ¶
func (w *WhenClause) Clone() (expression.Expression, error)
Clone implements the Expression Clone interface.
func (*WhenClause) Eval ¶
func (w *WhenClause) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error)
Eval implements the Expression Eval interface.
func (*WhenClause) IsStatic ¶
func (w *WhenClause) IsStatic() bool
IsStatic implements the Expression IsStatic interface.
func (*WhenClause) String ¶
func (w *WhenClause) String() string
String implements the Expression String interface.
Source Files ¶
- assign.go
- between.go
- binop.go
- builtin.go
- builtin_control.go
- builtin_groupby.go
- builtin_math.go
- builtin_string.go
- builtin_time.go
- call.go
- case.go
- cast.go
- conversion.go
- convert.go
- default.go
- helper.go
- ident.go
- in.go
- isnull.go
- istruth.go
- like.go
- param_marker.go
- pexpr.go
- position.go
- regexp.go
- subquery.go
- substring.go
- unary.go
- value.go
- values.go
- variable.go