MCPcopy Create free account
hub / github.com/brimdata/super / indexArrayOrSet

Function indexArrayOrSet

runtime/vam/expr/index.go:43–85  ·  view source on GitHub ↗
(sctx *super.Context, vec, indexVec vector.Any, base1 bool)

Source from the content-addressed store, hash-verified

41}
42
43func 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
87func indexRecord(sctx *super.Context, vec, indexVec vector.Any, base1 bool) vector.Any {
88 var isint bool

Callers 1

evalMethod · 0.70

Calls 14

IsUnsignedFunction · 0.92
ApplyFunction · 0.92
ToFunction · 0.92
IsIntegerFunction · 0.92
NewWrappedErrorFunction · 0.92
IntValueFunction · 0.92
PickFunction · 0.92
DeunionFunction · 0.92
CombineFunction · 0.92
NewMissingFunction · 0.92
arrayOrSetContentsFunction · 0.85
IDMethod · 0.65

Tested by

no test coverage detected