MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Eval

Method Eval

server/expression/array.go:66–104  ·  view source on GitHub ↗

Eval implements the sql.Expression interface.

(ctx *sql.Context, row sql.Row)

Source from the content-addressed store, hash-verified

64
65// Eval implements the sql.Expression interface.
66func (array *Array) Eval(ctx *sql.Context, row sql.Row) (any, error) {
67 resultTyp := array.coercedType.ArrayBaseType()
68 values := make([]any, len(array.children))
69 castsColl, err := core.GetCastsCollectionFromContext(ctx, "")
70 if err != nil {
71 return nil, err
72 }
73 for i, expr := range array.children {
74 val, err := expr.Eval(ctx, row)
75 if err != nil {
76 return nil, err
77 }
78
79 if val == nil {
80 values[i] = val
81 continue
82 }
83
84 doltgresType, ok := expr.Type(ctx).(*pgtypes.DoltgresType)
85 if !ok {
86 return nil, errors.Errorf("expected DoltgresType, but got %s", expr.Type(ctx).String())
87 }
88
89 // We always cast the element, as there may be parameter restrictions in place
90 cast, err := castsColl.GetImplicitCast(ctx, doltgresType, resultTyp)
91 if err != nil {
92 return nil, err
93 }
94 if !cast.ID.IsValid() {
95 return nil, errors.Errorf("cannot find cast function from %s to %s", doltgresType.String(), resultTyp.String())
96 }
97
98 values[i], err = cast.Eval(ctx, val, doltgresType, resultTyp)
99 if err != nil {
100 return nil, err
101 }
102 }
103 return values, nil
104}
105
106// IsNullable implements the sql.Expression interface.
107func (array *Array) IsNullable(ctx *sql.Context) bool {

Callers

nothing calls this directly

Calls 8

ArrayBaseTypeMethod · 0.80
EvalMethod · 0.65
TypeMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
GetImplicitCastMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected