evalengine

package
v0.18.6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 44 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAmbiguousType = errors.New("the type of this expression cannot be statically computed")
View Source
var ErrEvaluatedExprNotSupported = "expr cannot be evaluated, not supported"
View Source
var ErrHashCoercionIsNotExact = vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "cannot coerce into target type without losing precision")
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 SystemTime = time.Now
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 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 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. opArithAdd 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 NullsafeHashcode128 added in v0.17.0

func NullsafeHashcode128(hash *vthash.Hasher, v sqltypes.Value, collation collations.ID, coerceTo sqltypes.Type) error

NullsafeHashcode128 returns a 128-bit hashcode that is guaranteed to be the same for two values that are considered equal by `NullsafeCompare`. This can be used to avoid having to do comparison checks after a hash, since we consider the 128 bits of entropy enough to guarantee uniqueness.

func Subtract

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

Subtract takes two values and subtracts them

func WeightString added in v0.18.0

func WeightString(dst []byte, v sqltypes.Value, coerceTo sqltypes.Type, col collations.ID, length, precision int) ([]byte, bool, error)

WeightString returns the weight string for a value. It appends to dst if an existing slice is given, otherwise it returns a new one. The returned boolean indicates whether the weight string is a fixed-width weight string, such as for fixed size integer values. Our WeightString implementation supports more types that MySQL externally communicates with the `WEIGHT_STRING` function, so that we can also use this to order / sort other types like Float and Decimal as well.

Types

type Arena added in v0.17.0

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

Arena is an arena memory allocator for eval types. It allocates the types from reusable slices to prevent heap allocations. After each evaluation execution, (*Arena).reset() should be called to reset the arena.

type ArithmeticExpr added in v0.13.0

type ArithmeticExpr struct {
	BinaryExpr
	Op opArith
}

func (*ArithmeticExpr) CachedSize added in v0.13.0

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

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
	Type      sqltypes.Type
	Collation collations.TypedCollation
}

func NewBindVar added in v0.8.0

func NewBindVar(key string, typ sqltypes.Type, col collations.ID) *BindVariable

NewBindVar returns a bind variable

func NewBindVarTuple added in v0.17.0

func NewBindVarTuple(key string, col collations.ID) *BindVariable

NewBindVarTuple returns a bind variable containing a tuple

func (*BindVariable) CachedSize added in v0.10.0

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

type BitwiseExpr added in v0.14.0

type BitwiseExpr struct {
	BinaryExpr
	Op opBit
}

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

type CallExpr struct {
	Arguments TupleExpr
	Method    string
}

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
	Type      sqltypes.Type
	Collation collations.TypedCollation
}

func NewColumn added in v0.8.0

func NewColumn(offset int, typ sqltypes.Type, col collations.ID) *Column

NewColumn returns a column expression

func (*Column) CachedSize added in v0.10.0

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

type ColumnResolver added in v0.17.0

type ColumnResolver func(name *sqlparser.ColName) (int, error)

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 CompiledExpr added in v0.17.0

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

func (*CompiledExpr) CachedSize added in v0.17.0

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

type CompilerLog added in v0.17.0

type CompilerLog interface {
	Instruction(ins string, args ...any)
	Stack(old, new int)
}

type Config added in v0.17.0

type Config struct {
	ResolveColumn ColumnResolver
	ResolveType   TypeResolver

	Collation    collations.ID
	Optimization OptimizationLevel
	CompilerErr  error
}

type ConvertExpr added in v0.14.0

type ConvertExpr struct {
	UnaryExpr
	Type          string
	Length, Scale *int
	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
}

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) ToBoolean added in v0.15.5

func (er EvalResult) ToBoolean() bool

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(id collations.ID) sqltypes.Value

Value allows for retrieval of the value we expose for public consumption. It will be converted to the passed in collation which is the connection collation and what the client expects the result to be in.

type Expr

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

Expr is the interface that all evaluating expressions must implement

func Deoptimize added in v0.17.0

func Deoptimize(expr Expr) Expr

func Translate added in v0.14.0

func Translate(e sqlparser.Expr, cfg *Config) (Expr, error)

type ExpressionEnv

type ExpressionEnv struct {
	BindVars map[string]*querypb.BindVariable
	Row      []sqltypes.Value
	// contains filtered or unexported fields
}

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 NewExpressionEnv added in v0.17.0

func NewExpressionEnv(ctx context.Context, bindVars map[string]*querypb.BindVariable, vc VCursor) *ExpressionEnv

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

func (*ExpressionEnv) Evaluate added in v0.13.0

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

func (*ExpressionEnv) EvaluateVM added in v0.17.0

func (env *ExpressionEnv) EvaluateVM(p *CompiledExpr) (EvalResult, error)

func (*ExpressionEnv) TypeOf added in v0.13.0

func (env *ExpressionEnv) TypeOf(expr Expr, fields []*querypb.Field) (sqltypes.Type, typeFlag, error)

type FieldResolver added in v0.17.0

type FieldResolver []*querypb.Field

func (FieldResolver) Column added in v0.17.0

func (fields FieldResolver) Column(col *sqlparser.ColName) (int, error)

func (FieldResolver) Type added in v0.17.0

func (fields FieldResolver) Type(expr sqlparser.Expr) (sqltypes.Type, collations.ID, bool)

type FilterExpr added in v0.17.0

type FilterExpr interface {
	BinaryExpr
	// contains filtered or unexported methods
}

type HashCode added in v0.13.0

type HashCode = uint64

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 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
}

func (*InExpr) CachedSize added in v0.13.0

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

type IntervalExpr added in v0.17.0

type IntervalExpr struct {
	CallExpr
}

func (*IntervalExpr) CachedSize added in v0.17.0

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

type IntroducerExpr added in v0.17.2

type IntroducerExpr struct {
	UnaryExpr
	TypedCollation collations.TypedCollation
}

func (*IntroducerExpr) CachedSize added in v0.17.2

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

type IsExpr added in v0.13.0

type IsExpr struct {
	UnaryExpr
	Op    sqlparser.IsExprOperator
	Check func(eval) 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          colldata.WildcardPattern
	MatchCollation collations.ID
}

func (*LikeExpr) CachedSize added in v0.13.0

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

type Literal

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

func NewLiteralBinary added in v0.14.0

func NewLiteralBinary(val []byte) *Literal

func NewLiteralBinaryFromBit added in v0.17.0

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

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 NewLiteralBool added in v0.17.0

func NewLiteralBool(b bool) *Literal

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 MinMax added in v0.18.0

type MinMax interface {
	Min(value sqltypes.Value) error
	Max(value sqltypes.Value) error
	Result() sqltypes.Value
	Reset()
}

MinMax implements a MIN() or MAX() aggregation

func NewAggregationMinMax added in v0.18.0

func NewAggregationMinMax(type_ sqltypes.Type, collation collations.ID) MinMax

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 OptimizationLevel added in v0.17.0

type OptimizationLevel int8
const (
	OptimizationLevelDefault OptimizationLevel = iota
	OptimizationLevelSimplify
	OptimizationLevelCompile
	OptimizationLevelCompilerDebug
	OptimizationLevelMax
	OptimizationLevelNone OptimizationLevel = -1
)

type Sum added in v0.18.0

type Sum interface {
	Add(value sqltypes.Value) error
	Result() sqltypes.Value
	Reset()
}

Sum implements a SUM() aggregation

func NewAggregationSum added in v0.18.0

func NewAggregationSum(type_ sqltypes.Type) Sum

func NewSumOfCounts added in v0.18.0

func NewSumOfCounts() Sum

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 TypeResolver added in v0.17.0

type TypeResolver func(expr sqlparser.Expr) (sqltypes.Type, collations.ID, bool)

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 VCursor added in v0.17.0

type VCursor interface {
	TimeZone() *time.Location
	GetKeyspace() string
}

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

Jump to

Keyboard shortcuts

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