MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / FetchValIdx

Method FetchValIdx

pkg/util/json/encoded.go:381–411  ·  view source on GitHub ↗
(idx int)

Source from the content-addressed store, hash-verified

379}
380
381func (j *jsonEncoded) FetchValIdx(idx int) (JSON, error) {
382 if dec := j.alreadyDecoded(); dec != nil {
383 return dec.FetchValIdx(idx)
384 }
385
386 switch j.typ {
387 case NumberJSONType, StringJSONType, TrueJSONType, FalseJSONType, NullJSONType:
388 return fetchValIdxForScalar(j, idx), nil
389 case ArrayJSONType:
390 if idx < 0 {
391 idx = j.containerLen + idx
392 }
393 if idx < 0 || idx >= j.containerLen {
394 return nil, nil
395 }
396
397 // We need to find the bounds for a given index, but this is nontrivial,
398 // since some headers store an offset and some store a length.
399
400 begin, end, entry, err := j.getNthEntryBounds(idx)
401 if err != nil {
402 return nil, err
403 }
404
405 return newEncoded(entry, j.arrayGetDataRange(begin, end))
406 case ObjectJSONType:
407 return nil, nil
408 default:
409 return nil, errors.AssertionFailedf("unknown json type: %v", errors.Safe(j.typ))
410 }
411}
412
413func (j *jsonEncoded) FetchValKey(key string) (JSON, error) {
414 if dec := j.alreadyDecoded(); dec != nil {

Callers 1

FetchValKeyOrIdxMethod · 0.95

Calls 6

alreadyDecodedMethod · 0.95
getNthEntryBoundsMethod · 0.95
arrayGetDataRangeMethod · 0.95
fetchValIdxForScalarFunction · 0.85
newEncodedFunction · 0.85
FetchValIdxMethod · 0.65

Tested by

no test coverage detected