Documentation ¶
Index ¶
- func Add(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func Cast(v sqltypes.Value, typ querypb.Type) (sqltypes.Value, error)
- func Divide(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func Max(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func Min(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func Multiply(v1, v2 sqltypes.Value) (sqltypes.Value, error)
- func NullsafeAdd(v1, v2 sqltypes.Value, resultType querypb.Type) sqltypes.Value
- func NullsafeCompare(v1, v2 sqltypes.Value) (int, error)
- func NullsafeHashcode(v sqltypes.Value) (int64, 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) (interface{}, error)
- func ToUint64(v sqltypes.Value) (uint64, error)
- type Addition
- type BinaryExpr
- type BinaryOp
- type BindVariable
- type Column
- type Division
- type EvalResult
- type Expr
- type ExpressionEnv
- type Literal
- type Multiplication
- type Subtraction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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
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
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
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
type Division ¶
type Division struct{}
func (*Division) Evaluate ¶
func (d *Division) Evaluate(left, right EvalResult) (EvalResult, error)
Evaluate implements the BinaryOp 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 NewLiteralFloat ¶
NewLiteralFloat returns a literal expression
func NewLiteralIntFromBytes ¶
NewLiteralIntFromBytes returns a literal expression
func NewLiteralString ¶
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
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
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