evalengine

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConvertExprNotSupported = "expr cannot be converted, not supported"
View Source
var NullExpr = &Literal{}

NullExpr is just what you are lead to believe

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 CoerceTo added in v0.13.0

func CoerceTo(v1, v2 querypb.Type) (querypb.Type, error)

CoerceTo takes two input types, and decides how they should be coerced before compared

func Divide

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

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

func FormatExpr added in v0.13.0

func FormatExpr(expr Expr) string

func FormatFloat added in v0.13.0

func FormatFloat(typ querypb.Type, f float64) []byte

FormatFloat formats a float64 as a byte string in a similar way to what MySQL does

func Max

func Max(v1, v2 sqltypes.Value, collation collations.ID) (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, collation collations.ID) (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 added in v0.13.0

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

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. OpAddition 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, collationID collations.ID) (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 PrettyPrint added in v0.13.0

func PrettyPrint(expr Expr) string

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 ArithmeticExpr added in v0.13.0

type ArithmeticExpr struct {
	BinaryExpr
	Op ArithmeticOp
}

func (*ArithmeticExpr) CachedSize added in v0.13.0

func (cached *ArithmeticExpr) CachedSize(alloc bool) int64

type ArithmeticOp added in v0.13.0

type ArithmeticOp interface {
	String() string
	// contains filtered or unexported methods
}

ArithmeticOp allows arithmetic expressions to not have to evaluate child expressions - this is done by the BinaryExpr

type BinaryExpr

type BinaryExpr struct {
	Left, Right Expr
}

func (*BinaryExpr) CachedSize added in v0.13.0

func (cached *BinaryExpr) CachedSize(alloc bool) int64

type BindVariable

type BindVariable struct {
	Key string
	// contains filtered or unexported fields
}

func (*BindVariable) CachedSize added in v0.10.0

func (cached *BindVariable) CachedSize(alloc bool) int64

type CallExpr added in v0.13.0

type CallExpr struct {
	Arguments TupleExpr
	Aliases   []sqlparser.ColIdent
	Method    string
	Call      func(*ExpressionEnv, []EvalResult, *EvalResult)
}

func (*CallExpr) CachedSize added in v0.13.0

func (cached *CallExpr) CachedSize(alloc bool) int64

type CollateExpr added in v0.13.0

type CollateExpr struct {
	UnaryExpr
	TypedCollation collations.TypedCollation
}

func (*CollateExpr) CachedSize added in v0.13.0

func (cached *CollateExpr) CachedSize(alloc bool) int64

type Column

type Column struct {
	Offset int
	// contains filtered or unexported fields
}

func (*Column) CachedSize added in v0.10.0

func (cached *Column) CachedSize(alloc bool) int64

type ComparisonExpr added in v0.13.0

type ComparisonExpr struct {
	BinaryExpr
	Op ComparisonOp
}

func (*ComparisonExpr) CachedSize added in v0.13.0

func (cached *ComparisonExpr) CachedSize(alloc bool) int64

type ComparisonOp added in v0.13.0

type ComparisonOp interface {
	String() string
	// contains filtered or unexported methods
}

type ConverterLookup added in v0.13.0

type ConverterLookup interface {
	ColumnLookup(col *sqlparser.ColName) (int, error)
	CollationForExpr(expr sqlparser.Expr) collations.ID
	DefaultCollation() collations.ID
}

type EvalResult

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

EvalResult is a lazily computed result of an evaluation

func (*EvalResult) CachedSize added in v0.10.0

func (cached *EvalResult) CachedSize(alloc bool) int64

func (*EvalResult) ToBooleanStrict added in v0.8.0

func (er *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) TupleValues added in v0.13.0

func (er *EvalResult) TupleValues() []sqltypes.Value

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

func (*EvalResult) Value

func (er *EvalResult) Value() sqltypes.Value

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

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr is the interface that all evaluating expressions must implement

func Convert added in v0.13.0

func Convert(e sqlparser.Expr, lookup ConverterLookup) (Expr, error)

Convert converts between AST expressions and executable expressions

func ConvertEx added in v0.13.0

func ConvertEx(e sqlparser.Expr, lookup ConverterLookup, simplify bool) (Expr, error)

func NewBindVar added in v0.8.0

func NewBindVar(key string, collation collations.TypedCollation) Expr

NewBindVar returns a bind variable

func NewColumn added in v0.8.0

func NewColumn(offset int, collation collations.TypedCollation) Expr

NewColumn returns a column expression

func NewLiteralBinaryFromHex added in v0.13.0

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

func NewLiteralBinaryFromHexNum added in v0.13.0

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

func NewLiteralDecimalFromBytes added in v0.13.0

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

func NewLiteralFloat

func NewLiteralFloat(val float64) Expr

NewLiteralFloat returns a literal expression

func NewLiteralFloatFromBytes added in v0.13.0

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

NewLiteralFloatFromBytes returns a float literal expression from a slice of bytes

func NewLiteralInt

func NewLiteralInt(i int64) Expr

NewLiteralInt returns a literal expression

func NewLiteralIntegralFromBytes added in v0.13.0

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

NewLiteralIntegralFromBytes returns a literal expression. It tries to return an int64, but if the value is too large, it tries with an uint64

func NewLiteralString

func NewLiteralString(val []byte, collation collations.TypedCollation) Expr

NewLiteralString returns a literal expression

func NewLiteralUint added in v0.13.0

func NewLiteralUint(i uint64) Expr

NewLiteralUint returns a literal expression

type ExpressionEnv

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

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

func EmptyExpressionEnv added in v0.13.0

func EmptyExpressionEnv() *ExpressionEnv

EmptyExpressionEnv returns a new ExpressionEnv with no bind vars or row

func EnvWithBindVars added in v0.13.0

func EnvWithBindVars(bindVars map[string]*querypb.BindVariable, coll collations.ID) *ExpressionEnv

EnvWithBindVars returns an expression environment with no current row, but with bindvars

func (*ExpressionEnv) CachedSize added in v0.13.0

func (cached *ExpressionEnv) CachedSize(alloc bool) int64

func (*ExpressionEnv) Evaluate added in v0.13.0

func (env *ExpressionEnv) Evaluate(expr Expr) (er EvalResult, err error)

func (*ExpressionEnv) TypeOf added in v0.13.0

func (env *ExpressionEnv) TypeOf(expr Expr) (ty querypb.Type, err error)

type HashCode added in v0.13.0

type HashCode = uintptr

HashCode is a type alias to the code easier to read

func NullsafeHashcode added in v0.9.0

func NullsafeHashcode(v sqltypes.Value, collation collations.ID, coerceType querypb.Type) (HashCode, error)

NullsafeHashcode returns an int64 hashcode that is guaranteed to be the same for two values that are considered equal by `NullsafeCompare`.

type InExpr added in v0.13.0

type InExpr struct {
	BinaryExpr
	Negate bool
	Hashed map[uintptr]int
}

func (*InExpr) CachedSize added in v0.13.0

func (cached *InExpr) CachedSize(alloc bool) int64

type IsExpr added in v0.13.0

type IsExpr struct {
	UnaryExpr
	Op    sqlparser.IsExprOperator
	Check func(*EvalResult) bool
}

IsExpr represents the IS expression in MySQL. boolean_primary IS [NOT] {TRUE | FALSE | NULL}

func (*IsExpr) CachedSize added in v0.13.0

func (cached *IsExpr) CachedSize(alloc bool) int64

type LikeExpr added in v0.13.0

type LikeExpr struct {
	BinaryExpr
	Negate         bool
	Match          collations.WildcardPattern
	MatchCollation collations.ID
}

func (*LikeExpr) CachedSize added in v0.13.0

func (cached *LikeExpr) CachedSize(alloc bool) int64

type Literal

type Literal struct {
	Val EvalResult
}

func (*Literal) CachedSize added in v0.10.0

func (cached *Literal) CachedSize(alloc bool) int64

type LogicalExpr added in v0.13.0

type LogicalExpr struct {
	BinaryExpr
	// contains filtered or unexported fields
}

func (*LogicalExpr) CachedSize added in v0.13.0

func (cached *LogicalExpr) CachedSize(alloc bool) int64

type LogicalOp added in v0.13.0

type LogicalOp interface {
	String()
	// contains filtered or unexported methods
}

type LookupDefaultCollation added in v0.13.0

type LookupDefaultCollation collations.ID

func (LookupDefaultCollation) CollationForExpr added in v0.13.0

func (d LookupDefaultCollation) CollationForExpr(_ sqlparser.Expr) collations.ID

func (LookupDefaultCollation) ColumnLookup added in v0.13.0

func (d LookupDefaultCollation) ColumnLookup(_ *sqlparser.ColName) (int, error)

func (LookupDefaultCollation) DefaultCollation added in v0.13.0

func (d LookupDefaultCollation) DefaultCollation() collations.ID

type NegateExpr added in v0.13.0

type NegateExpr struct {
	UnaryExpr
}

func (*NegateExpr) CachedSize added in v0.13.1

func (cached *NegateExpr) CachedSize(alloc bool) int64

type NotExpr added in v0.13.0

type NotExpr struct {
	UnaryExpr
}

func (*NotExpr) CachedSize added in v0.13.0

func (cached *NotExpr) CachedSize(alloc bool) int64

type OpAddition added in v0.13.0

type OpAddition struct{}

func (*OpAddition) String added in v0.13.0

func (a *OpAddition) String() string

type OpDivision added in v0.13.0

type OpDivision struct{}

func (*OpDivision) String added in v0.13.0

func (d *OpDivision) String() string

type OpLogicalAnd added in v0.13.0

type OpLogicalAnd struct{}

type OpMultiplication added in v0.13.0

type OpMultiplication struct{}

func (*OpMultiplication) String added in v0.13.0

func (m *OpMultiplication) String() string

type OpSubstraction added in v0.13.0

type OpSubstraction struct{}

func (*OpSubstraction) String added in v0.13.0

func (s *OpSubstraction) String() string

type TupleExpr added in v0.13.0

type TupleExpr []Expr

func NewTupleExpr added in v0.13.0

func NewTupleExpr(exprs ...Expr) TupleExpr

NewTupleExpr returns a tuple expression

type UnaryExpr added in v0.13.0

type UnaryExpr struct {
	Inner Expr
}

func (*UnaryExpr) CachedSize added in v0.13.0

func (cached *UnaryExpr) CachedSize(alloc bool) int64

type UnsupportedCollationError added in v0.13.0

type UnsupportedCollationError struct {
	ID collations.ID
}

UnsupportedCollationError represents the error where the comparison using provided collation is unsupported on vitess

func (UnsupportedCollationError) Error added in v0.13.0

func (err UnsupportedCollationError) Error() string

Error function implements the error interface

type UnsupportedComparisonError added in v0.10.0

type UnsupportedComparisonError struct {
	Type1 querypb.Type
	Type2 querypb.Type
}

UnsupportedComparisonError represents the error where the comparison between the two types is unsupported on vitess

func (UnsupportedComparisonError) Error added in v0.10.0

func (err UnsupportedComparisonError) Error() string

Error function implements the error interface

Directories

Path Synopsis
Package decimal provides a high-performance, arbitrary precision, floating-point decimal library.
Package decimal provides a high-performance, arbitrary precision, floating-point decimal library.
internal/arith
Package arith provides performance-sensitive arithmetic operations.
Package arith provides performance-sensitive arithmetic operations.
internal/c
Package c provides internal constants.
Package c provides internal constants.

Jump to

Keyboard shortcuts

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