MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Eval

Method Eval

pkg/sql/sem/tree/eval.go:4011–4049  ·  view source on GitHub ↗

Eval implements the TypedExpr interface.

(ctx *EvalContext)

Source from the content-addressed store, hash-verified

4009
4010// Eval implements the TypedExpr interface.
4011func (expr *ComparisonExpr) Eval(ctx *EvalContext) (Datum, error) {
4012 left, err := expr.Left.(TypedExpr).Eval(ctx)
4013 if err != nil {
4014 return nil, err
4015 }
4016 right, err := expr.Right.(TypedExpr).Eval(ctx)
4017 if err != nil {
4018 return nil, err
4019 }
4020
4021 op := expr.Operator
4022 if op.hasSubOperator() {
4023 var datums Datums
4024 // Right is either a tuple or an array of Datums.
4025 if !expr.fn.NullableArgs && right == DNull {
4026 return DNull, nil
4027 } else if tuple, ok := AsDTuple(right); ok {
4028 datums = tuple.D
4029 } else if array, ok := AsDArray(right); ok {
4030 datums = array.Array
4031 } else {
4032 return nil, errors.AssertionFailedf("unhandled right expression %s", right)
4033 }
4034 return evalDatumsCmp(ctx, op, expr.SubOperator, expr.fn, left, datums)
4035 }
4036
4037 _, newLeft, newRight, _, not := foldComparisonExpr(op, left, right)
4038 if !expr.fn.NullableArgs && (newLeft == DNull || newRight == DNull) {
4039 return DNull, nil
4040 }
4041 d, err := expr.fn.Fn(ctx, newLeft.(Datum), newRight.(Datum))
4042 if err != nil {
4043 return nil, err
4044 }
4045 if b, ok := d.(*DBool); ok {
4046 return MakeDBool(*b != DBool(not)), nil
4047 }
4048 return d, nil
4049}
4050
4051//// EvalArgsAndGetGenerator evaluates the arguments and instanciates a
4052//// ValueGenerator for use by set projections.

Callers

nothing calls this directly

Calls 8

AsDTupleFunction · 0.85
AsDArrayFunction · 0.85
evalDatumsCmpFunction · 0.85
foldComparisonExprFunction · 0.85
MakeDBoolFunction · 0.85
DBoolTypeAlias · 0.85
hasSubOperatorMethod · 0.80
EvalMethod · 0.65

Tested by

no test coverage detected