evalengine

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Add adds two values together if v1 or v2 is null, then it returns null

func Cast

func Cast(v sqltypes.Value, typ querypb.Type) (sqltypes.Value, error)

Cast converts a Value to the target type.

func Divide

func Divide(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Divide (Float) for MySQL. Replicates behavior of "/" operator

func Max

func Max(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Max returns the maximum of v1 and v2. If one of the values is NULL, it returns the other value. If both are NULL, it returns NULL.

func Min

func Min(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Min returns the minimum of v1 and v2. If one of the values is NULL, it returns the other value. If both are NULL, it returns NULL.

func Multiply

func Multiply(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Multiply takes two values and multiplies it together

func NullsafeAdd

func NullsafeAdd(v1, v2 sqltypes.Value, resultType querypb.Type) sqltypes.Value

NullsafeAdd adds two Values in a null-safe manner. A null value is treated as 0. If both values are null, then a null is returned. If both values are not null, a numeric value is built from each input: Signed->int64, Unsigned->uint64, Float->float64. Otherwise the 'best type fit' is chosen for the number: int64 or float64. Addition is performed by upgrading types as needed, or in case of overflow: int64->uint64, int64->float64, uint64->float64. Unsigned ints can only be added to positive ints. After the addition, if one of the input types was Decimal, then a Decimal is built. Otherwise, the final type of the result is preserved.

func NullsafeCompare

func NullsafeCompare(v1, v2 sqltypes.Value) (int, error)

NullsafeCompare returns 0 if v1==v2, -1 if v1<v2, and 1 if v1>v2. NULL is the lowest value. If any value is numeric, then a numeric comparison is performed after necessary conversions. If none are numeric, then it's a simple binary comparison. Uncomparable values return an error.

func NullsafeHashcode

func NullsafeHashcode(v sqltypes.Value) (int64, error)

NullsafeHashcode returns an int64 hashcode that is guaranteed to be the same for two values that are considered equal by `NullsafeCompare`. TODO: should be extended to support all possible types

func Subtract

func Subtract(v1, v2 sqltypes.Value) (sqltypes.Value, error)

Subtract takes two values and subtracts them

func ToFloat64

func ToFloat64(v sqltypes.Value) (float64, error)

ToFloat64 converts Value to float64.

func ToInt64

func ToInt64(v sqltypes.Value) (int64, error)

ToInt64 converts Value to int64.

func ToNative

func ToNative(v sqltypes.Value) (interface{}, error)

ToNative converts Value to a native go type. Decimal is returned as []byte.

func ToUint64

func ToUint64(v sqltypes.Value) (uint64, error)

ToUint64 converts Value to uint64.

Types

type Addition

type Addition struct{}

Binary ops

func (*Addition) Evaluate

func (a *Addition) Evaluate(left, right EvalResult) (EvalResult, error)

Evaluate implements the BinaryOp interface

func (*Addition) String

func (a *Addition) String() string

String implements the BinaryExpr interface

func (*Addition) Type

func (a *Addition) Type(left querypb.Type) querypb.Type

Type implements the BinaryExpr interface

type BinaryExpr

type BinaryExpr interface {
	Evaluate(left, right EvalResult) (EvalResult, error)
	Type(left querypb.Type) querypb.Type
	String() string
}

BinaryExpr allows binary expressions to not have to evaluate child expressions - this is done by the BinaryOp

type BinaryOp

type BinaryOp struct {
	Expr        BinaryExpr
	Left, Right Expr
}

func (*BinaryOp) Evaluate

func (b *BinaryOp) Evaluate(env ExpressionEnv) (EvalResult, error)

Evaluate implements the Expr interface

func (*BinaryOp) String

func (b *BinaryOp) String() string

String implements the Expr interface

func (*BinaryOp) Type

func (b *BinaryOp) Type(env ExpressionEnv) (querypb.Type, error)

Type implements the Expr interface

type BindVariable

type BindVariable struct{ Key string }

func (*BindVariable) Evaluate

func (b *BindVariable) Evaluate(env ExpressionEnv) (EvalResult, error)

Evaluate implements the Expr interface

func (*BindVariable) String

func (b *BindVariable) String() string

String implements the Expr interface

func (*BindVariable) Type

func (b *BindVariable) Type(env ExpressionEnv) (querypb.Type, error)

Type implements the Expr interface

type Column

type Column struct{ Offset int }

func (*Column) Evaluate

func (c *Column) Evaluate(env ExpressionEnv) (EvalResult, error)

Evaluate implements the Expr interface

func (*Column) String

func (c *Column) String() string

String implements the Expr interface

func (*Column) Type

func (c *Column) Type(ExpressionEnv) (querypb.Type, error)

Type implements the Expr interface

type Division

type Division struct{}

func (*Division) Evaluate

func (d *Division) Evaluate(left, right EvalResult) (EvalResult, error)

Evaluate implements the BinaryOp interface

func (*Division) String

func (d *Division) String() string

String implements the BinaryExpr interface

func (*Division) Type

func (d *Division) Type(querypb.Type) querypb.Type

Type implements the BinaryExpr interface

type EvalResult

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

func (*EvalResult) ToBooleanStrict

func (e *EvalResult) ToBooleanStrict() (bool, error)

ToBooleanStrict is used when the casting to a boolean has to be minimally forgiving, such as when assigning to a system variable that is expected to be a boolean

func (EvalResult) Value

func (e EvalResult) Value() sqltypes.Value

Value allows for retrieval of the value we expose for public consumption

type Expr

type Expr interface {
	Evaluate(env ExpressionEnv) (EvalResult, error)
	Type(env ExpressionEnv) (querypb.Type, error)
	String() string
}

Expr is the interface that all evaluating expressions must implement

func NewBindVar

func NewBindVar(key string) Expr

NewBindVar returns a bind variable

func NewColumn

func NewColumn(offset int) Expr

NewColumn returns a bind variable

func NewLiteralFloat

func NewLiteralFloat(val []byte) (Expr, error)

NewLiteralFloat returns a literal expression

func NewLiteralInt

func NewLiteralInt(i int64) Expr

NewLiteralInt returns a literal expression

func NewLiteralIntFromBytes

func NewLiteralIntFromBytes(val []byte) (Expr, error)

NewLiteralIntFromBytes returns a literal expression

func NewLiteralString

func NewLiteralString(val []byte) Expr

NewLiteralFloat returns a literal expression

type ExpressionEnv

type ExpressionEnv struct {
	BindVars map[string]*querypb.BindVariable
	Row      []sqltypes.Value
}

ExpressionEnv contains the environment that the expression evaluates in, such as the current row and bindvars

type Literal

type Literal struct{ Val EvalResult }

Expressions

func (*Literal) Evaluate

func (l *Literal) Evaluate(ExpressionEnv) (EvalResult, error)

Evaluate implements the Expr interface

func (*Literal) String

func (l *Literal) String() string

String implements the Expr interface

func (*Literal) Type

func (l *Literal) Type(ExpressionEnv) (querypb.Type, error)

Type implements the Expr interface

type Multiplication

type Multiplication struct{}

func (*Multiplication) Evaluate

func (m *Multiplication) Evaluate(left, right EvalResult) (EvalResult, error)

Evaluate implements the BinaryOp interface

func (*Multiplication) String

func (m *Multiplication) String() string

String implements the BinaryExpr interface

func (*Multiplication) Type

func (m *Multiplication) Type(left querypb.Type) querypb.Type

Type implements the BinaryExpr interface

type Subtraction

type Subtraction struct{}

func (*Subtraction) Evaluate

func (s *Subtraction) Evaluate(left, right EvalResult) (EvalResult, error)

Evaluate implements the BinaryOp interface

func (*Subtraction) String

func (s *Subtraction) String() string

String implements the BinaryExpr interface

func (*Subtraction) Type

func (s *Subtraction) Type(left querypb.Type) querypb.Type

Type implements the BinaryExpr interface

Jump to

Keyboard shortcuts

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