Skip to content

Commit 8b30027

Browse files
authored
json, expr: json_search should return NULL when the search path is NULL (pingcap#59714)
close pingcap#59463
1 parent ad82e3a commit 8b30027

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

pkg/expression/builtin_json_vec.go

+8
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,14 @@ func (b *builtinJSONSearchSig) vecEvalJSON(ctx EvalContext, input *chunk.Chunk,
565565
return errIncorrectArgs.GenWithStackByArgs("ESCAPE")
566566
}
567567
}
568+
569+
var isNull bool
568570
var pathExprs []types.JSONPathExpression
569571
if pathBufs != nil {
570572
pathExprs = make([]types.JSONPathExpression, 0, len(b.args)-4)
571573
for j := 0; j < len(b.args)-4; j++ {
572574
if pathBufs[j].IsNull(i) {
575+
isNull = true
573576
break
574577
}
575578
pathExpr, err := types.ParseJSONPathExpr(pathBufs[j].GetString(i))
@@ -579,6 +582,11 @@ func (b *builtinJSONSearchSig) vecEvalJSON(ctx EvalContext, input *chunk.Chunk,
579582
pathExprs = append(pathExprs, pathExpr)
580583
}
581584
}
585+
if isNull {
586+
result.AppendNull()
587+
continue
588+
}
589+
582590
bj, isNull, err := jsonBuf.GetJSON(i).Search(containType, searchBuf.GetString(i), escape, pathExprs)
583591
if err != nil {
584592
return err

tests/integrationtest/r/expression/json.result

+9
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,12 @@ json_set('{"a":"b"}', '$[last]', 1)
864864
SELECT JSON_ARRAY_APPEND('[1]', '$', JSON_ARRAY(2, 3));
865865
JSON_ARRAY_APPEND('[1]', '$', JSON_ARRAY(2, 3))
866866
[1, [2, 3]]
867+
set tidb_enable_vectorized_expression = 'ON';
868+
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
869+
json_search('{"h": "i"}', 'all', 'i', '\\', NULL)
870+
NULL
871+
set tidb_enable_vectorized_expression = 'OFF';
872+
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
873+
json_search('{"h": "i"}', 'all', 'i', '\\', NULL)
874+
NULL
875+
set tidb_enable_vectorized_expression = default;

tests/integrationtest/t/expression/json.test

+8
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,11 @@ select json_set('{"a":"b"}', '$[last]', 1);
568568

569569
# TestIssue59465
570570
SELECT JSON_ARRAY_APPEND('[1]', '$', JSON_ARRAY(2, 3));
571+
572+
# TestIssue59463
573+
# should return NULL because the path is NULL
574+
set tidb_enable_vectorized_expression = 'ON';
575+
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
576+
set tidb_enable_vectorized_expression = 'OFF';
577+
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
578+
set tidb_enable_vectorized_expression = default;

0 commit comments

Comments
 (0)