evaluator

package
v0.0.0-...-887f819 Latest Latest
Warning

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

Go to latest
Published: May 4, 2016 License: Apache-2.0 Imports: 19 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 (
	ErrInvalidOperation = terror.ClassEvaluator.New(CodeInvalidOperation, "invalid operation")
)

Error instances.

View Source
var Funcs = map[string]Func{

	"coalesce": {builtinCoalesce, 1, -1},
	"isnull":   {builtinIsNull, 1, 1},

	"abs":   {builtinAbs, 1, 1},
	"pow":   {builtinPow, 2, 2},
	"power": {builtinPow, 2, 2},
	"rand":  {builtinRand, 0, 1},

	"curdate":           {builtinCurrentDate, 0, 0},
	"current_date":      {builtinCurrentDate, 0, 0},
	"current_time":      {builtinCurrentTime, 0, 1},
	"current_timestamp": {builtinNow, 0, 1},
	"curtime":           {builtinCurrentTime, 0, 1},
	"date":              {builtinDate, 1, 1},
	"day":               {builtinDay, 1, 1},
	"dayname":           {builtinDayName, 1, 1},
	"dayofmonth":        {builtinDayOfMonth, 1, 1},
	"dayofweek":         {builtinDayOfWeek, 1, 1},
	"dayofyear":         {builtinDayOfYear, 1, 1},
	"hour":              {builtinHour, 1, 1},
	"microsecond":       {builtinMicroSecond, 1, 1},
	"minute":            {builtinMinute, 1, 1},
	"month":             {builtinMonth, 1, 1},
	"now":               {builtinNow, 0, 1},
	"second":            {builtinSecond, 1, 1},
	"sysdate":           {builtinSysDate, 0, 1},
	"utc_date":          {builtinUTCDate, 0, 0},
	"week":              {builtinWeek, 1, 2},
	"weekday":           {builtinWeekDay, 1, 1},
	"weekofyear":        {builtinWeekOfYear, 1, 1},
	"year":              {builtinYear, 1, 1},
	"yearweek":          {builtinYearWeek, 1, 2},
	"extract":           {builtinExtract, 2, 2},
	"date_arith":        {builtinDateArith, 3, 3},

	"ascii":           {builtinASCII, 1, 1},
	"concat":          {builtinConcat, 1, -1},
	"concat_ws":       {builtinConcatWS, 2, -1},
	"left":            {builtinLeft, 2, 2},
	"length":          {builtinLength, 1, 1},
	"lower":           {builtinLower, 1, 1},
	"lcase":           {builtinLower, 1, 1},
	"ltrim":           {trimFn(strings.TrimLeft, spaceChars), 1, 1},
	"repeat":          {builtinRepeat, 2, 2},
	"upper":           {builtinUpper, 1, 1},
	"ucase":           {builtinUpper, 1, 1},
	"replace":         {builtinReplace, 3, 3},
	"rtrim":           {trimFn(strings.TrimRight, spaceChars), 1, 1},
	"strcmp":          {builtinStrcmp, 2, 2},
	"convert":         {builtinConvert, 2, 2},
	"substring":       {builtinSubstring, 2, 3},
	"substring_index": {builtinSubstringIndex, 3, 3},
	"locate":          {builtinLocate, 2, 3},
	"trim":            {builtinTrim, 1, 3},

	"current_user":  {builtinCurrentUser, 0, 0},
	"database":      {builtinDatabase, 0, 0},
	"found_rows":    {builtinFoundRows, 0, 0},
	"user":          {builtinUser, 0, 0},
	"connection_id": {builtinConnectionID, 0, 0},
	"version":       {builtinVersion, 0, 0},

	"if":     {builtinIf, 3, 3},
	"ifnull": {builtinIfNull, 2, 2},
	"nullif": {builtinNullIf, 2, 2},
}

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

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