Skip to content

Commit 5cf2682

Browse files
authored
expression,json: make the behavior of JSON_VALID consistent (#57496) (#57505)
close #56293
1 parent 03a5897 commit 5cf2682

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pkg/expression/builtin_json.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,8 @@ func (b *builtinJSONValidOthersSig) Clone() builtinFunc {
10381038
// evalInt evals a builtinJSONValidOthersSig.
10391039
// See https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-valid
10401040
func (b *builtinJSONValidOthersSig) evalInt(ctx EvalContext, row chunk.Row) (val int64, isNull bool, err error) {
1041-
return 0, false, nil
1041+
datum, err := b.args[0].Eval(ctx, row)
1042+
return 0, datum.IsNull(), err
10421043
}
10431044

10441045
type jsonArrayAppendFunctionClass struct {

tests/integrationtest/r/expression/json.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,3 +765,9 @@ Error 3853 (22032): Invalid JSON type in argument 1 to function json_schema_vali
765765
select json_type(cast(cast('2024' as year) as json));
766766
json_type(cast(cast('2024' as year) as json))
767767
UNSIGNED INTEGER
768+
drop table if exists t;
769+
create table t(j json, str varchar(255), other int);
770+
insert into t values (NULL, NULL, NULL);
771+
select json_valid(j), json_valid(str), json_valid(other) from t;
772+
json_valid(j) json_valid(str) json_valid(other)
773+
NULL NULL NULL

tests/integrationtest/t/expression/json.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,9 @@ SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"exclusiveMinimum": true}}}', '{
484484
# TestIssue54494
485485
# https://github.com/pingcap/tidb/issues/54494
486486
select json_type(cast(cast('2024' as year) as json));
487+
488+
# TestJSONValidForNull
489+
drop table if exists t;
490+
create table t(j json, str varchar(255), other int);
491+
insert into t values (NULL, NULL, NULL);
492+
select json_valid(j), json_valid(str), json_valid(other) from t;

0 commit comments

Comments
 (0)