Skip to content

Commit

Permalink
cherry pick pingcap#35320 to release-6.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
mengxin9014 authored and ti-srebot committed Jun 28, 2022
1 parent 36a9810 commit 2df866f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions types/json/binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (bj BinaryJSON) Extract(pathExprList []PathExpression) (ret BinaryJSON, fou
// even if len(pathExprList) equals to 1.
found = true
ret = buf[0]
// Fix https://github.com/pingcap/tidb/issues/30352
if pathExprList[0].ContainsAnyAsterisk() {
ret = buildBinaryArray(buf)
}
} else {
found = true
ret = buildBinaryArray(buf)
Expand Down
4 changes: 2 additions & 2 deletions types/json/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func TestBinaryJSONExtract(t *testing.T) {
{bj1, []string{"$.*[0]"}, mustParseBinaryFromString(t, `["world", 1, true, "d"]`), true, nil},
{bj1, []string{`$.a[*]."aa"`}, mustParseBinaryFromString(t, `["bb", "cc"]`), true, nil},
{bj1, []string{`$."\"hello\""`}, mustParseBinaryFromString(t, `"world"`), true, nil},
{bj1, []string{`$**[1]`}, mustParseBinaryFromString(t, `"2"`), true, nil},
{bj1, []string{`$**[1]`}, mustParseBinaryFromString(t, `["2"]`), true, nil},
{bj3, []string{`$.properties.$type`}, mustParseBinaryFromString(t, `"TiDB"`), true, nil},
{bj4, []string{`$.properties.$type$type`}, mustParseBinaryFromString(t, `{"$a$a" : "TiDB"}`), true, nil},
{bj4, []string{`$.properties.$type$type.$a$a`}, mustParseBinaryFromString(t, `"TiDB"`), true, nil},
{bj5, []string{`$.properties.$type.$a.$b`}, mustParseBinaryFromString(t, `"TiDB"`), true, nil},
{bj5, []string{`$.properties.$type.$a.*[0]`}, mustParseBinaryFromString(t, `"TiDB"`), true, nil},
{bj5, []string{`$.properties.$type.$a.*[0]`}, mustParseBinaryFromString(t, `["TiDB"]`), true, nil},

// test extract with multi path expressions.
{bj1, []string{"$.a", "$[5]"}, mustParseBinaryFromString(t, `[[1, "2", {"aa": "bb"}, 4.0, {"aa": "cc"}]]`), true, nil},
Expand Down

0 comments on commit 2df866f

Please sign in to comment.