Eval implements the sql.Expression interface.
(ctx *sql.Context, row sql.Row)
| 64 | |
| 65 | // Eval implements the sql.Expression interface. |
| 66 | func (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. |
| 107 | func (array *Array) IsNullable(ctx *sql.Context) bool { |
nothing calls this directly
no test coverage detected