Eval implements the TypedExpr interface.
(ctx *EvalContext)
| 4496 | |
| 4497 | // Eval implements the TypedExpr interface. |
| 4498 | func (t *Placeholder) Eval(ctx *EvalContext) (Datum, error) { |
| 4499 | if !ctx.HasPlaceholders() { |
| 4500 | // While preparing a query, there will be no available placeholders. A |
| 4501 | // placeholder evaluates to itself at this point. |
| 4502 | return t, nil |
| 4503 | } |
| 4504 | e, ok := ctx.Placeholders.Value(t.Idx) |
| 4505 | if !ok { |
| 4506 | return nil, makeNoValueProvidedForPlaceholderErr(t.Idx) |
| 4507 | } |
| 4508 | // Placeholder expressions cannot contain other placeholders, so we do |
| 4509 | // not need to recurse. |
| 4510 | typ := ctx.Placeholders.Types[t.Idx] |
| 4511 | if typ == nil { |
| 4512 | // All placeholders should be typed at this point. |
| 4513 | return nil, errors.AssertionFailedf("missing type for placeholder %s", t) |
| 4514 | } |
| 4515 | if !e.ResolvedType().Equivalent(typ) { |
| 4516 | // This happens when we overrode the placeholder's type during type |
| 4517 | // checking, since the placeholder's type hint didn't match the desired |
| 4518 | // type for the placeholder. In this case, we cast the expression to |
| 4519 | // the desired type. |
| 4520 | // TODO(jordan): introduce a restriction on what casts are allowed here. |
| 4521 | cast := &CastExpr{Expr: e, Type: typ} |
| 4522 | return cast.Eval(ctx) |
| 4523 | } |
| 4524 | return e.Eval(ctx) |
| 4525 | } |
| 4526 | |
| 4527 | func evalComparison(ctx *EvalContext, op ComparisonOperator, left, right Datum) (Datum, error) { |
| 4528 | if left == DNull || right == DNull { |
nothing calls this directly
no test coverage detected