evalengine

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEvaluatedExprNotSupported = "expr cannot be evaluated, not supported"
View Source
var ErrTranslateExprNotSupported = "expr cannot be translated, not supported"
View Source
var NullExpr = &Literal{}

NullExpr is just what you are lead to believe

View Source
var UnsupportedCollationHashError = vterrors.Errorf(vtrpcpb.Code_INTERNAL, "text type with an unknown/unsupported collation cannot be hashed")

UnsupportedCollationHashError is returned when we try to get the hash value and are missing the collation to use

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 AppendFloat added in v0.15.0

func AppendFloat(buf []byte, typ sqltypes.Type, f float64) []byte

func Cast

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

Cast converts a Value to the target type.

func CoerceTo added in v0.13.0

func CoerceTo(v1, v2 sqltypes.Type) (sqltypes.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 sqltypes.Type, f float64) []byte

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

func LiteralToValue added in v0.15.0

func LiteralToValue(literal *sqlparser.Literal) (sqltypes.Value, error)

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 sqltypes.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 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) (any, 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
}

type BinaryExpr

type BinaryExpr struct {
	Left, Right Expr
}

func (*BinaryExpr) CachedSize added in v0.13.0

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

func (*BinaryExpr) LeftExpr added in v0.15.0

func (expr *BinaryExpr) LeftExpr() Expr

func (*BinaryExpr) RightExpr added in v0.15.0

func (expr *BinaryExpr) RightExpr() Expr

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 BitwiseBinaryOp added in v0.14.0

type BitwiseBinaryOp interface {
	BitwiseOp
	// contains filtered or unexported methods
}

type BitwiseExpr added in v0.14.0

type BitwiseExpr struct {
	BinaryExpr
	Op BitwiseOp
}

func (*BitwiseExpr) CachedSize added in v0.14.0

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

type BitwiseNotExpr added in v0.14.0

type BitwiseNotExpr struct {
	UnaryExpr
}

func (*BitwiseNotExpr) CachedSize added in v0.14.0

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

type BitwiseOp added in v0.14.0

type BitwiseOp interface {
	BitwiseOp() string
}

type BitwiseShiftOp added in v0.14.0

type BitwiseShiftOp interface {
	BitwiseOp
	// contains filtered or unexported methods
}

type CallExpr added in v0.13.0

type CallExpr struct {
	Arguments TupleExpr
	Aliases   []sqlparser.IdentifierCI
	Method    string
	F         builtin
}

func (*CallExpr) CachedSize added in v0.13.0

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

type CaseExpr added in v0.14.0

type CaseExpr struct {
	Else Expr
	// contains filtered or unexported fields
}

func (*CaseExpr) CachedSize added in v0.14.0

func (cached *CaseExpr) 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 ConvertExpr added in v0.14.0

type ConvertExpr struct {
	UnaryExpr
	Type                string
	Length, Scale       int
	HasLength, HasScale bool
	Collation           collations.ID
}

func (*ConvertExpr) CachedSize added in v0.14.0

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

type ConvertUsingExpr added in v0.14.0

type ConvertUsingExpr struct {
	UnaryExpr
	Collation collations.ID
}

func (*ConvertUsingExpr) CachedSize added in v0.14.0

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

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) Collation added in v0.14.0

func (er *EvalResult) Collation() collations.ID

func (*EvalResult) MustBoolean added in v0.15.0

func (er *EvalResult) MustBoolean() bool

func (*EvalResult) String added in v0.14.0

func (er *EvalResult) String() string

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 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 Translate added in v0.14.0

func Translate(e sqlparser.Expr, lookup TranslationLookup) (Expr, error)

Translate translates between AST expressions and executable expressions

func TranslateEx added in v0.14.0

func TranslateEx(e sqlparser.Expr, lookup TranslationLookup, simplify bool) (Expr, error)

type ExpressionEnv

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

	// Row and Fields should line up
	Row    []sqltypes.Value
	Fields []*querypb.Field
}

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 sqltypes.Type, err error)

type Filter added in v0.15.0

type Filter interface {
	Expr
	LeftExpr() Expr
	RightExpr() Expr
	// contains filtered or unexported methods
}

type HashCode added in v0.13.0

type HashCode = uintptr

HashCode is a type alias to the code easier to read

func NullsafeHashCodeInPlace added in v0.15.0

func NullsafeHashCodeInPlace(v sqltypes.Value, collation collations.ID, typ sqltypes.Type) (HashCode, error)

NullsafeHashCodeInPlace behaves like NullsafeHashCode but the type coercion is performed in-place for performance reasons. Eventually this method will replace the old implementation.

func NullsafeHashcode added in v0.9.0

func NullsafeHashcode(v sqltypes.Value, collation collations.ID, coerceType sqltypes.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 NewLiteralBinary added in v0.14.0

func NewLiteralBinary(val []byte) *Literal

func NewLiteralBinaryFromHex added in v0.13.0

func NewLiteralBinaryFromHex(val []byte) (*Literal, error)

func NewLiteralBinaryFromHexNum added in v0.13.0

func NewLiteralBinaryFromHexNum(val []byte) (*Literal, error)

func NewLiteralDateFromBytes added in v0.15.0

func NewLiteralDateFromBytes(val []byte) (*Literal, error)

NewLiteralDateFromBytes returns a literal expression.

func NewLiteralDatetimeFromBytes added in v0.15.0

func NewLiteralDatetimeFromBytes(val []byte) (*Literal, error)

NewLiteralDatetimeFromBytes returns a literal expression. it validates the datetime by parsing it and checking the error.

func NewLiteralDecimalFromBytes added in v0.13.0

func NewLiteralDecimalFromBytes(val []byte) (*Literal, error)

func NewLiteralFloat

func NewLiteralFloat(val float64) *Literal

NewLiteralFloat returns a literal expression

func NewLiteralFloatFromBytes added in v0.13.0

func NewLiteralFloatFromBytes(val []byte) (*Literal, error)

NewLiteralFloatFromBytes returns a float literal expression from a slice of bytes

func NewLiteralInt

func NewLiteralInt(i int64) *Literal

NewLiteralInt returns a literal expression

func NewLiteralIntegralFromBytes added in v0.13.0

func NewLiteralIntegralFromBytes(val []byte) (*Literal, 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) *Literal

NewLiteralString returns a literal expression

func NewLiteralTimeFromBytes added in v0.15.0

func NewLiteralTimeFromBytes(val []byte) (*Literal, error)

NewLiteralTimeFromBytes returns a literal expression. it validates the time by parsing it and checking the error.

func NewLiteralUint added in v0.13.0

func NewLiteralUint(i uint64) *Literal

NewLiteralUint returns a literal expression

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 OpBitAnd added in v0.14.0

type OpBitAnd struct{}

func (OpBitAnd) BitwiseOp added in v0.14.0

func (o OpBitAnd) BitwiseOp() string

type OpBitOr added in v0.14.0

type OpBitOr struct{}

func (OpBitOr) BitwiseOp added in v0.14.0

func (o OpBitOr) BitwiseOp() string

type OpBitShiftLeft added in v0.14.0

type OpBitShiftLeft struct{}

func (OpBitShiftLeft) BitwiseOp added in v0.14.0

func (o OpBitShiftLeft) BitwiseOp() string

type OpBitShiftRight added in v0.14.0

type OpBitShiftRight struct{}

func (OpBitShiftRight) BitwiseOp added in v0.14.0

func (o OpBitShiftRight) BitwiseOp() string

type OpBitXor added in v0.14.0

type OpBitXor struct{}

func (OpBitXor) BitwiseOp added in v0.14.0

func (o OpBitXor) BitwiseOp() 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 TranslationLookup added in v0.14.0

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

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 sqltypes.Type
	Type2 sqltypes.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

type WeightStringCallExpr added in v0.14.0

type WeightStringCallExpr struct {
	String Expr
	Cast   string
	Len    int
	HasLen bool
}

func (*WeightStringCallExpr) CachedSize added in v0.14.0

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

type WhenThen added in v0.14.0

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

func (*WhenThen) CachedSize added in v0.14.0

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

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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