// Eval implements the Expression Eval interface. func (f *FunctionCast) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error) { value, err := f.Expr.Eval(ctx, args) if err != nil { return nil, errors.Trace(err) } v, ok := value.(*types.DataItem) if ok { value = v.Data } d := &types.DataItem{Type: f.Tp} // Casting nil to any type returns null if value == nil { d.Data = nil return d, nil } d.Data, err = types.Cast(value, f.Tp) if err != nil { return nil, errors.Trace(err) } return d, nil }
// Eval implements the Expression Eval interface. func (f *FunctionCast) Eval(ctx context.Context, args map[interface{}]interface{}) (interface{}, error) { value, err := f.Expr.Eval(ctx, args) if err != nil { return nil, err } // Casting nil to any type returns null if value == nil { return nil, nil } return types.Cast(value, f.Tp), nil }
func (e *Evaluator) funcCast(v *ast.FuncCastExpr) bool { value := v.Expr.GetValue() // Casting nil to any type returns null if value == nil { v.SetValue(nil) return true } var err error value, err = types.Cast(value, v.Tp) if err != nil { e.err = errors.Trace(err) return false } v.SetValue(value) return true }