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

Method ArrayIndex

value.go:183–198  ·  view source on GitHub ↗

If the passed-in element is an array, attempt to get the idx'th element, and return its type and raw representation. Returns an error if the passed-in element is not an array or if idx is outside the array bounds.

(idx int64)

Source from the content-addressed store, hash-verified

181// error if the passed-in element is not an array or if idx is
182// outside the array bounds.
183func (v Value) ArrayIndex(idx int64) (Value, error) {
184 vec, ok := v.Type().(*TypeArray)
185 if !ok {
186 return Null, ErrNotArray
187 }
188 if idx < 0 {
189 return Null, ErrIndex
190 }
191 for i, it := 0, v.ContainerIter(); !it.Done(); i++ {
192 bytes := it.Next()
193 if i == int(idx) {
194 return NewValue(vec.Type, bytes), nil
195 }
196 }
197 return Null, ErrIndex
198}
199
200// Elements returns an array of Values for the given container type.
201// Returns an error if the element is not an array or set.

Callers

nothing calls this directly

Calls 5

TypeMethod · 0.95
ContainerIterMethod · 0.95
NewValueFunction · 0.85
DoneMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected