(sctx *super.Context, vec, indexVec vector.Any, base1 bool)
| 41 | } |
| 42 | |
| 43 | func indexArrayOrSet(sctx *super.Context, vec, indexVec vector.Any, base1 bool) vector.Any { |
| 44 | if _, ok := indexVec.(*vector.Error); ok { |
| 45 | return indexVec |
| 46 | } |
| 47 | if id := indexVec.Type().ID(); super.IsUnsigned(id) { |
| 48 | return vector.Apply(true, func(args ...vector.Any) vector.Any { |
| 49 | return indexArrayOrSet(sctx, args[0], args[1], base1) |
| 50 | }, vec, cast.To(sctx, indexVec, super.TypeInt64)) |
| 51 | } else if !super.IsInteger(id) { |
| 52 | return vector.NewWrappedError(sctx, "index is not an integer", indexVec) |
| 53 | } |
| 54 | var index []uint32 |
| 55 | if view, ok := vec.(*vector.View); ok { |
| 56 | vec, index = view.Any, view.Index |
| 57 | } |
| 58 | offsets, vals := arrayOrSetContents(vec) |
| 59 | var errs []uint32 |
| 60 | var viewIndexes []uint32 |
| 61 | for i := range indexVec.Len() { |
| 62 | idx := i |
| 63 | if index != nil { |
| 64 | idx = index[i] |
| 65 | } |
| 66 | idxVal := vector.IntValue(indexVec, uint32(i)) |
| 67 | start := offsets[idx] |
| 68 | len := int64(offsets[idx+1]) - int64(start) |
| 69 | if idxVal < 0 { |
| 70 | idxVal = len + idxVal |
| 71 | } else if base1 { |
| 72 | idxVal-- |
| 73 | } |
| 74 | if idxVal >= 0 && idxVal < len { |
| 75 | viewIndexes = append(viewIndexes, start+uint32(idxVal)) |
| 76 | continue |
| 77 | } |
| 78 | errs = append(errs, i) |
| 79 | } |
| 80 | out := vector.Pick(vector.Deunion(vals), viewIndexes) |
| 81 | if len(errs) > 0 { |
| 82 | return vector.Combine(out, errs, vector.NewMissing(sctx, uint32(len(errs)))) |
| 83 | } |
| 84 | return out |
| 85 | } |
| 86 | |
| 87 | func indexRecord(sctx *super.Context, vec, indexVec vector.Any, base1 bool) vector.Any { |
| 88 | var isint bool |
no test coverage detected