MCPcopy Create free account
hub / github.com/dolthub/doltgresql / FetchValKey

Method FetchValKey

postgres/parser/json/encoded.go:424–465  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

422}
423
424func (j *jsonEncoded) FetchValKey(key string) (JSON, error) {
425 if dec := j.alreadyDecoded(); dec != nil {
426 return dec.FetchValKey(key)
427 }
428
429 if j.Type() == ObjectJSONType {
430 // TODO(justin): This is not as absolutely efficient as it could be - every
431 // lookup we have to seek to find the actual location of the key. We could
432 // be caching the locations of all the intermediate keys that we have to
433 // scan in order to get to this one, in case we need to look them up later,
434 // or maybe there's something fancier we could do if we know the locations
435 // of the offsets by strategically positioning our binary search guesses to
436 // land on them.
437 var err error
438 i := sort.Search(j.containerLen, func(idx int) bool {
439 data, _, err := j.objectGetNthDataRange(idx)
440 if err != nil {
441 return false
442 }
443 return string(data) >= key
444 })
445 if err != nil {
446 return nil, err
447 }
448
449 // The sort.Search API implies that we have to double-check if the key we
450 // landed on is the one we were searching for in the first place.
451 if i >= j.containerLen {
452 return nil, nil
453 }
454
455 data, _, err := j.objectGetNthDataRange(i)
456 if err != nil {
457 return nil, err
458 }
459
460 if string(data) == key {
461 return j.objectNthValue(i)
462 }
463 }
464 return nil, nil
465}
466
467// shallowDecode decodes only the keys of an object, and doesn't decode any
468// elements of an array. It can be used to save a decode-encode cycle for

Callers 2

ExistsMethod · 0.95
FetchValKeyOrIdxMethod · 0.95

Calls 5

alreadyDecodedMethod · 0.95
TypeMethod · 0.95
objectGetNthDataRangeMethod · 0.95
objectNthValueMethod · 0.95
FetchValKeyMethod · 0.65

Tested by

no test coverage detected