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

Method doRemovePath

pkg/util/json/json.go:2814–2850  ·  view source on GitHub ↗
(path []string)

Source from the content-addressed store, hash-verified

2812}
2813
2814func (j jsonArray) doRemovePath(path []string) (JSON, bool, error) {
2815 if len(path) == 0 {
2816 return j, false, nil
2817 }
2818 // In path-deletion we have to attempt to parse numbers (this is different
2819 // from the `-` operator, where strings just never match on arrays).
2820 idx, err := strconv.Atoi(path[0])
2821 if err != nil {
2822 // TODO(yuzefovich): give the position of the path element to match psql.
2823 err := errors.Newf("a path element is not an integer: %s", path[0])
2824 err = pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
2825 return j, false, err
2826 }
2827 if len(path) == 1 {
2828 return j.RemoveIndex(idx)
2829 }
2830
2831 if idx < -len(j) || idx >= len(j) {
2832 return j, false, nil
2833 }
2834 if idx < 0 {
2835 idx += len(j)
2836 }
2837 newVal, ok, err := j[idx].doRemovePath(path[1:])
2838 if err != nil {
2839 return nil, false, err
2840 }
2841 if !ok {
2842 return j, false, nil
2843 }
2844
2845 result := make(jsonArray, len(j))
2846 copy(result, j)
2847 result[idx] = newVal
2848
2849 return result, true, nil
2850}
2851
2852func (j jsonObject) doRemovePath(path []string) (JSON, bool, error) {
2853 if len(path) == 0 {

Callers 1

RemovePathMethod · 0.95

Calls 3

RemoveIndexMethod · 0.95
WithCandidateCodeFunction · 0.92
doRemovePathMethod · 0.65

Tested by

no test coverage detected