Skip to content

Commit

Permalink
expression,json: make the behavior of JSON_VALID consistent (#57496) (
Browse files Browse the repository at this point in the history
#57505)

close #56293
  • Loading branch information
ti-chi-bot authored Nov 20, 2024
1 parent 03a5897 commit 5cf2682
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/expression/builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,8 @@ func (b *builtinJSONValidOthersSig) Clone() builtinFunc {
// evalInt evals a builtinJSONValidOthersSig.
// See https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-valid
func (b *builtinJSONValidOthersSig) evalInt(ctx EvalContext, row chunk.Row) (val int64, isNull bool, err error) {
return 0, false, nil
datum, err := b.args[0].Eval(ctx, row)
return 0, datum.IsNull(), err
}

type jsonArrayAppendFunctionClass struct {
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/expression/json.result
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,9 @@ Error 3853 (22032): Invalid JSON type in argument 1 to function json_schema_vali
select json_type(cast(cast('2024' as year) as json));
json_type(cast(cast('2024' as year) as json))
UNSIGNED INTEGER
drop table if exists t;
create table t(j json, str varchar(255), other int);
insert into t values (NULL, NULL, NULL);
select json_valid(j), json_valid(str), json_valid(other) from t;
json_valid(j) json_valid(str) json_valid(other)
NULL NULL NULL
6 changes: 6 additions & 0 deletions tests/integrationtest/t/expression/json.test
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,9 @@ SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"exclusiveMinimum": true}}}', '{
# TestIssue54494
# https://github.com/pingcap/tidb/issues/54494
select json_type(cast(cast('2024' as year) as json));

# TestJSONValidForNull
drop table if exists t;
create table t(j json, str varchar(255), other int);
insert into t values (NULL, NULL, NULL);
select json_valid(j), json_valid(str), json_valid(other) from t;

0 comments on commit 5cf2682

Please sign in to comment.