evaluator

package
v0.0.0-...-40faf7d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2016 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInvalidOperation terror.ErrCode = 1
)

Error codes.

Variables

View Source
var (
	// CurrentTimestamp is the keyword getting default value for datetime and timestamp type.
	CurrentTimestamp = "CURRENT_TIMESTAMP"

	// ZeroTimestamp shows the zero datetime and timestamp.
	ZeroTimestamp = "0000-00-00 00:00:00"
)
View Source
var DynamicFuncs = map[string]int{
	"rand":           0,
	"connection_id":  0,
	"current_user":   0,
	"database":       0,
	"found_rows":     0,
	"last_insert_id": 0,
	"user":           0,
	"version":        0,
	"sleep":          0,
	ast.GetVar:       0,
	ast.SetVar:       0,
}

DynamicFuncs are those functions that use input parameter ctx or return an uncertain result would not be constant folded the value 0 means nothing

View Source
var (
	ErrInvalidOperation = terror.ClassEvaluator.New(CodeInvalidOperation, "invalid operation")
)

Error instances.

View Source
var Funcs = map[string]Func{}/* 110 elements not displayed */

Funcs holds all registered builtin functions.

Functions

func Eval

func Eval(ctx context.Context, expr ast.ExprNode) (d types.Datum, err error)

Eval evaluates an expression to a datum.

func EvalBool

func EvalBool(ctx context.Context, expr ast.ExprNode) (bool, error)

EvalBool evalueates an expression to a boolean value.

func EvalSubquery

func EvalSubquery(ctx context.Context, v *ast.SubqueryExpr) error

EvalSubquery evaluates a subquery.

func GetTimeValue

func GetTimeValue(ctx context.Context, v interface{}, tp byte, fsp int) (types.Datum, error)

GetTimeValue gets the time value with type tp.

func IsCurrentTimeExpr

func IsCurrentTimeExpr(e ast.ExprNode) bool

IsCurrentTimeExpr returns whether e is CurrentTimeExpr.

Types

type BuiltinFunc

type BuiltinFunc func([]types.Datum, context.Context) (types.Datum, error)

BuiltinFunc is the function signature for builtin functions

func CastFuncFactory

func CastFuncFactory(tp *types.FieldType) (BuiltinFunc, error)

CastFuncFactory produces builtin function according to field types. See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator is an ast Visitor that evaluates an expression.

func (*Evaluator) Enter

func (e *Evaluator) Enter(in ast.Node) (out ast.Node, skipChildren bool)

Enter implements ast.Visitor interface.

func (*Evaluator) Leave

func (e *Evaluator) Leave(in ast.Node) (out ast.Node, ok bool)

Leave implements ast.Visitor interface.

type Func

type Func struct {
	// F is the specific calling function.
	F BuiltinFunc
	// MinArgs is the minimal arguments needed,
	MinArgs int
	// MaxArgs is the maximal arguments needed, -1 for infinity.
	MaxArgs int
}

Func is for a builtin function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL