Skip to content

Commit

Permalink
Merge pull request #101176 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-101059

release-23.1: sql/json: fix null's in array in inverted index support (#101176)

Co-Authored-By: Tommy Reilly <[email protected]>
  • Loading branch information
rytaft and cucaroach authored May 4, 2023
2 parents fbea48d + 7b231a3 commit c06a3dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/json
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@ SELECT true FROM x WHERE j->'a' @> '2'::JSONB
----
true

query T
SELECT j FROM x WHERE j ?| ARRAY[NULL]
----

query T
SELECT j FROM x WHERE j ?& ARRAY[NULL::STRING]
----
{"a": [1, 2, 3]}

query T
SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['foo', 'bar']
----
Expand Down
7 changes: 5 additions & 2 deletions pkg/sql/rowenc/index_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,11 @@ func EncodeExistsInvertedIndexSpans(
}
var expr inverted.Expression
for _, d := range val.(*tree.DArray).Array {
s := string(*d.(*tree.DString))
newExpr, err := json.EncodeExistsInvertedIndexSpans(nil /* inKey */, s)
ds, ok := tree.AsDString(d)
if !ok {
continue
}
newExpr, err := json.EncodeExistsInvertedIndexSpans(nil /* inKey */, string(ds))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c06a3dd

Please sign in to comment.