mirror of
https://github.com/MariaDB/server.git
synced 2025-07-26 07:02:12 +03:00
MDEV-19487: JSON_TYPE doesnt detect the type of String Values
(returns NULL) and for Date/DateTime returns "INTEGER" Analysis: When the first character of json is scanned it is number. Based on that integer is returned. Fix: Scan rest of the json before returning the final result to ensure json is valid in the first place in order to have a valid type.
This commit is contained in:
@ -1697,5 +1697,13 @@ INSERT INTO t (doc) VALUES ('{ "_id" : { "$oid" : "0ca0b0f0" },"a" : [ { "a" : [
|
|||||||
ERROR 22001: Data too long for column 'id' at row 1
|
ERROR 22001: Data too long for column 'id' at row 1
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
#
|
#
|
||||||
|
# MDEV-19487: JSON_TYPE doesnt detect the type of String Values (returns NULL) and for Date/DateTime returns "INTEGER"
|
||||||
|
#
|
||||||
|
SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('2019-01-01' as Date) ), '$.date'));
|
||||||
|
JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('2019-01-01' as Date) ), '$.date'))
|
||||||
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
|
||||||
|
#
|
||||||
# End of 10.5 tests
|
# End of 10.5 tests
|
||||||
#
|
#
|
||||||
|
@ -1125,6 +1125,13 @@ INSERT INTO t (doc) VALUES ('{ "_id" : { "$oid" : "0ca0b0f0" },"a" : [ { "a" : [
|
|||||||
|
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-19487: JSON_TYPE doesnt detect the type of String Values (returns NULL) and for Date/DateTime returns "INTEGER"
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('2019-01-01' as Date) ), '$.date'));
|
||||||
|
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # End of 10.5 tests
|
--echo # End of 10.5 tests
|
||||||
--echo #
|
--echo #
|
||||||
|
@ -1002,19 +1002,27 @@ DOUBLE
|
|||||||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||||||
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
|
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
|
||||||
json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'))
|
json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'))
|
||||||
INTEGER
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# Test of json_compact(literal)
|
# Test of json_compact(literal)
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
|
select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
|
||||||
json_type(json_compact(cast('2014-11-25 18:00' as datetime)))
|
json_type(json_compact(cast('2014-11-25 18:00' as datetime)))
|
||||||
INTEGER
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
|
||||||
select json_type(json_compact(cast('2014-11-25' as date)));
|
select json_type(json_compact(cast('2014-11-25' as date)));
|
||||||
json_type(json_compact(cast('2014-11-25' as date)))
|
json_type(json_compact(cast('2014-11-25' as date)))
|
||||||
INTEGER
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
|
||||||
select json_type(json_compact(cast('18:00:59' as time)));
|
select json_type(json_compact(cast('18:00:59' as time)));
|
||||||
json_type(json_compact(cast('18:00:59' as time)))
|
json_type(json_compact(cast('18:00:59' as time)))
|
||||||
INTEGER
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 3
|
||||||
select json_type(json_compact(127));
|
select json_type(json_compact(127));
|
||||||
json_type(json_compact(127))
|
json_type(json_compact(127))
|
||||||
INTEGER
|
INTEGER
|
||||||
@ -1064,7 +1072,9 @@ json_type(json_compact(3.14E30))
|
|||||||
DOUBLE
|
DOUBLE
|
||||||
select json_type(json_compact(cast('10101abcde' as binary)));
|
select json_type(json_compact(cast('10101abcde' as binary)));
|
||||||
json_type(json_compact(cast('10101abcde' as binary)))
|
json_type(json_compact(cast('10101abcde' as binary)))
|
||||||
INTEGER
|
NULL
|
||||||
|
Warnings:
|
||||||
|
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 6
|
||||||
select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
|
select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
|
||||||
json_type(json_compact(ST_GeomFromText('POINT(1 1)')))
|
json_type(json_compact(ST_GeomFromText('POINT(1 1)')))
|
||||||
NULL
|
NULL
|
||||||
|
@ -2971,6 +2971,12 @@ String *Item_func_json_type::val_str(String *str)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ensure the json is at least valid. */
|
||||||
|
while(json_scan_next(&je) == 0) {}
|
||||||
|
|
||||||
|
if (je.s.error)
|
||||||
|
goto error;
|
||||||
|
|
||||||
str->set(type, strlen(type), &my_charset_utf8mb3_general_ci);
|
str->set(type, strlen(type), &my_charset_utf8mb3_general_ci);
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user