Documentation ¶
Index ¶
- Variables
- func Add(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func AppendFloat(buf []byte, typ sqltypes.Type, f float64) []byte
- func Cast(v sqltypes.Value, typ sqltypes.Type) (sqltypes.Value, error)
- func CoerceTo(v1, v2 sqltypes.Type) (sqltypes.Type, error)
- func Divide(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func FormatExpr(expr Expr) string
- func FormatFloat(typ sqltypes.Type, f float64) []byte
- func LiteralToValue(literal *sqlparser.Literal) (sqltypes.Value, error)
- func Max(v1, v2 sqltypes.Value, collation collations.ID) (sqltypes.Value, error)
- func Min(v1, v2 sqltypes.Value, collation collations.ID) (sqltypes.Value, error)
- func Multiply(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func NullSafeAdd(v1, v2 sqltypes.Value, resultType sqltypes.Type) (sqltypes.Value, error)
- func NullsafeCompare(v1, v2 sqltypes.Value, collationID collations.ID) (int, error)
- func Subtract(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func ToFloat64(v sqltypes.Value) (float64, error)
- func ToInt64(v sqltypes.Value) (int64, error)
- func ToNative(v sqltypes.Value) (any, error)
- func ToUint64(v sqltypes.Value) (uint64, error)
- type ArithmeticExpr
- type ArithmeticOp
- type BinaryExpr
- type BindVariable
- type BitwiseBinaryOp
- type BitwiseExpr
- type BitwiseNotExpr
- type BitwiseOp
- type BitwiseShiftOp
- type CallExpr
- type CaseExpr
- type CollateExpr
- type Column
- type ComparisonExpr
- type ComparisonOp
- type ConvertExpr
- type ConvertUsingExpr
- type EvalResult
- func (cached *EvalResult) CachedSize(alloc bool) int64
- func (er *EvalResult) Collation() collations.ID
- func (er *EvalResult) MustBoolean() bool
- func (er *EvalResult) String() string
- func (er *EvalResult) ToBooleanStrict() (bool, error)
- func (er *EvalResult) TupleValues() []sqltypes.Value
- func (er *EvalResult) Value() sqltypes.Value
- type Expr
- func NewBindVar(key string, collation collations.TypedCollation) Expr
- func NewColumn(offset int, collation collations.TypedCollation) Expr
- func Translate(e sqlparser.Expr, lookup TranslationLookup) (Expr, error)
- func TranslateEx(e sqlparser.Expr, lookup TranslationLookup, simplify bool) (Expr, error)
- type ExpressionEnv
- type Filter
- type HashCode
- type InExpr
- type IsExpr
- type LikeExpr
- type Literal
- func NewLiteralBinary(val []byte) *Literal
- func NewLiteralBinaryFromHex(val []byte) (*Literal, error)
- func NewLiteralBinaryFromHexNum(val []byte) (*Literal, error)
- func NewLiteralDateFromBytes(val []byte) (*Literal, error)
- func NewLiteralDatetimeFromBytes(val []byte) (*Literal, error)
- func NewLiteralDecimalFromBytes(val []byte) (*Literal, error)
- func NewLiteralFloat(val float64) *Literal
- func NewLiteralFloatFromBytes(val []byte) (*Literal, error)
- func NewLiteralInt(i int64) *Literal
- func NewLiteralIntegralFromBytes(val []byte) (*Literal, error)
- func NewLiteralString(val []byte, collation collations.TypedCollation) *Literal
- func NewLiteralTimeFromBytes(val []byte) (*Literal, error)
- func NewLiteralUint(i uint64) *Literal
- type LogicalExpr
- type LogicalOp
- type LookupDefaultCollation
- type NegateExpr
- type NotExpr
- type OpAddition
- type OpBitAnd
- type OpBitOr
- type OpBitShiftLeft
- type OpBitShiftRight
- type OpBitXor
- type OpDivision
- type OpLogicalAnd
- type OpMultiplication
- type OpSubstraction
- type TranslationLookup
- type TupleExpr
- type UnaryExpr
- type UnsupportedCollationError
- type UnsupportedComparisonError
- type WeightStringCallExpr
- type WhenThen
Constants ¶
This section is empty.
Variables ¶
var ErrEvaluatedExprNotSupported = "expr cannot be evaluated, not supported"
var ErrTranslateExprNotSupported = "expr cannot be translated, not supported"
var NullExpr = &Literal{}
NullExpr is just what you are lead to believe
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 AppendFloat ¶ added in v0.15.0
func CoerceTo ¶ added in v0.13.0
CoerceTo takes two input types, and decides how they should be coerced before compared
func FormatExpr ¶ added in v0.13.0
func FormatFloat ¶ added in v0.13.0
FormatFloat formats a float64 as a byte string in a similar way to what MySQL does
func LiteralToValue ¶ added in v0.15.0
func Max ¶
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 ¶
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 NullSafeAdd ¶ added in v0.13.0
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 ¶
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.
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 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
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
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
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
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)
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
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
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
type Literal ¶
type Literal struct {
Val EvalResult
}
func NewLiteralBinary ¶ added in v0.14.0
func NewLiteralBinaryFromHex ¶ added in v0.13.0
func NewLiteralBinaryFromHexNum ¶ added in v0.13.0
func NewLiteralDateFromBytes ¶ added in v0.15.0
NewLiteralDateFromBytes returns a literal expression.
func NewLiteralDatetimeFromBytes ¶ added in v0.15.0
NewLiteralDatetimeFromBytes returns a literal expression. it validates the datetime by parsing it and checking the error.
func NewLiteralDecimalFromBytes ¶ added in v0.13.0
func NewLiteralFloat ¶
NewLiteralFloat returns a literal expression
func NewLiteralFloatFromBytes ¶ added in v0.13.0
NewLiteralFloatFromBytes returns a float literal expression from a slice of bytes
func NewLiteralInt ¶
NewLiteralInt returns a literal expression
func NewLiteralIntegralFromBytes ¶ added in v0.13.0
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
NewLiteralTimeFromBytes returns a literal expression. it validates the time by parsing it and checking the error.
func NewLiteralUint ¶ added in v0.13.0
NewLiteralUint returns a literal expression
func (*Literal) CachedSize ¶ added in v0.10.0
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
type OpAddition ¶ added in v0.13.0
type OpAddition struct{}
func (*OpAddition) String ¶ added in v0.13.0
func (a *OpAddition) String() 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 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
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
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
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
func (*WeightStringCallExpr) CachedSize ¶ added in v0.14.0
func (cached *WeightStringCallExpr) CachedSize(alloc bool) int64