diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2021-04-15 11:52:22 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2021-04-21 10:21:48 +0400 |
commit | 41e368f22db02e5c907aa40ae8c5c8e34ded3db9 (patch) | |
tree | b009fff0aaa1f8fcc76bf04a25366dbc0111832f /mysql-test | |
parent | 0a09525625b2f234e7adc07ad37f74cff4a0f4e2 (diff) | |
download | mariadb-git-41e368f22db02e5c907aa40ae8c5c8e34ded3db9.tar.gz |
MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion.
Only return the error if field->store produced errors, not warnings.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/suite/json/r/json_table.result | 51 | ||||
-rw-r--r-- | mysql-test/suite/json/r/json_table_mysql.result | 60 | ||||
-rw-r--r-- | mysql-test/suite/json/t/json_table.test | 17 | ||||
-rw-r--r-- | mysql-test/suite/json/t/json_table_mysql.test | 6 |
4 files changed, 119 insertions, 15 deletions
diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 3ef87b3e24b..d0a9021dd70 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -360,10 +360,12 @@ json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]' intcol int path '$.a' default '1234' on empty default '5678' on error) ) as tt; id intcol -1 5678 +1 0 2 123 3 5678 4 5678 +Warnings: +Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`intcol` at row 1 SELECT COUNT(*) FROM JSON_TABLE('[1, 2]', '$[*]' COLUMNS( I INT PATH '$')) tt; COUNT(*) 2 @@ -588,9 +590,11 @@ Error 4177 Can't store an array or an object in the scalar column 'a' of JSON_TA # MDEV-JSON_TABLE: CREATE TABLE ignores NULL ON ERROR (implicit or explicit) and fails. # CREATE TABLE t1 AS SELECT * FROM JSON_TABLE('{"x":1}', '$' COLUMNS(f DATE PATH '$.*')) AS jt; +Warnings: +Warning 1265 Data truncated for column 'f' at row 1 SELECT * FROM t1; f -NULL +0000-00-00 DROP TABLE t1; # # MDEV-25254: JSON_TABLE: Inconsistent name resolution with right joins @@ -907,5 +911,48 @@ a 2 DEALLOCATE PREPARE stmt1; # +# MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion. +# +select * from json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]' +columns ( id for ordinality, +intcol int path '$.a' default '1234' on empty default '5678' on error) +) as tt; +id intcol +1 0 +2 123 +3 5678 +4 5678 +Warnings: +Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`intcol` at row 1 +# +# MDEV-25377 JSON_TABLE: Wrong value with implicit conversion. +# +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt; +converted original +0 foo +1 1 +127 1000 +Warnings: +Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1 +Warning 1264 Out of range value for column 'converted' at row 3 +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by converted; +converted original +0 foo +1 1 +127 1000 +Warnings: +Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1 +Warning 1264 Out of range value for column 'converted' at row 1 +Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1 +Warning 1264 Out of range value for column 'converted' at row 3 +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by original; +converted original +1 1 +127 1000 +0 foo +Warnings: +Warning 1264 Out of range value for column 'converted' at row 2 +Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 3 +# # End of 10.6 tests # diff --git a/mysql-test/suite/json/r/json_table_mysql.result b/mysql-test/suite/json/r/json_table_mysql.result index 31acd80f011..ec21f18523f 100644 --- a/mysql-test/suite/json/r/json_table_mysql.result +++ b/mysql-test/suite/json/r/json_table_mysql.result @@ -59,7 +59,10 @@ id jpath_i jpath_r jsn_path jexst 2 2 2 2 0 3 33 33.3 {"x":33} 1 4 0 0.33 0.33 0 -5 66 0 asd 0 +5 0 0 asd 0 +Warnings: +Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`jpath_i` at row 5 +Warning 1366 Incorrect double value: 'asd' for column ``.`(temporary)`.`jpath_r` at row 5 select * from json_table( '[{"x":"3"},{"a":2},{"b":1},{"a":0},{"a":[1,2]}]', @@ -396,7 +399,10 @@ v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIE DROP VIEW v; SELECT * FROM JSON_TABLE('"asdf"', '$' COLUMNS (a INT PATH '$' ERROR ON ERROR)) AS jt; -ERROR HY000: Can't store an array or an object in the scalar column 'a' of JSON_TABLE 'jt'. +a +0 +Warnings: +Warning 1366 Incorrect integer value: 'asdf' for column ``.`(temporary)`.`a` at row 1 SELECT * FROM JSON_TABLE('[{"a":1},{"a":2}]', '$' COLUMNS (a INT PATH '$[*].a' ERROR ON ERROR)) AS jt; @@ -407,11 +413,16 @@ JSON_TABLE('[{"a":1},{"a":2}]', ERROR HY000: Can't store multiple matches of the path in the column 'a' of JSON_TABLE 'jt'. SELECT * FROM JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$' ERROR ON ERROR)) AS jt; -ERROR HY000: Can't store an array or an object in the scalar column 'a' of JSON_TABLE 'jt'. +a +9.9 +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 SELECT * FROM JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$')) AS jt; a -NULL +9.9 +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 SELECT * FROM JSON_TABLE('{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{"a":1,"b":{}}}}}}}}}}}}}}}}}}}', '$' COLUMNS (i0 INT PATH '$.a', @@ -525,7 +536,13 @@ i INT PATH '$', f FLOAT PATH '$', d DECIMAL PATH '$')) AS jt; tm dt i f d -NULL NULL NULL 0 0 +00:00:00 0000-00-00 0 0 0 +Warnings: +Warning 1265 Data truncated for column 'tm' at row 1 +Warning 1265 Data truncated for column 'dt' at row 1 +Warning 1366 Incorrect integer value: 'asdf' for column ``.`(temporary)`.`i` at row 1 +Warning 1366 Incorrect double value: 'asdf' for column ``.`(temporary)`.`f` at row 1 +Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`d` at row 1 SELECT * FROM JSON_TABLE('{}', '$' COLUMNS (x INT PATH '$.x' DEFAULT NULL ON EMPTY)) jt; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL ON EMPTY)) jt' at line 2 @@ -739,6 +756,8 @@ FROM JSON_TABLE('{"a":"1993-01-01"}', AS jt; jp 0000-00-00 +Warnings: +Warning 1265 Data truncated for column 'jp' at row 1 # # Bug#25532429: INVALID JSON ERROR NOT THROWN WITH EMPTY TABLES JOIN # @@ -763,6 +782,8 @@ JSON_TABLE('["3.14159"]', ) AS alias2; col18 3.1415 +Warnings: +Warning 1265 Data truncated for column 'col18' at row 1 #Truncated space doesn't trigger ON ERROR SELECT * FROM JSON_TABLE('["3.14159 "]', @@ -805,12 +826,17 @@ JSON_TABLE('[3.14159]', '$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$') ) AS alias2; col18 -NULL +0.999 +Warnings: +Warning 1264 Out of range value for column 'col18' at row 1 SELECT * FROM JSON_TABLE('[3.14159]', '$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$' ERROR ON ERROR) ) AS alias2; -ERROR HY000: Can't store an array or an object in the scalar column 'col18' of JSON_TABLE 'alias2'. +col18 +0.999 +Warnings: +Warning 1264 Out of range value for column 'col18' at row 1 SELECT * FROM JSON_TABLE('[0.9]', '$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$') @@ -825,6 +851,9 @@ DEFAULT "3.14159" ON ERROR) col18 0.000 0.000 +Warnings: +Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`col18` at row 1 +Warning 1366 Incorrect decimal value: 'ghjk' for column ``.`(temporary)`.`col18` at row 2 CREATE TABLE t1(jd JSON); INSERT INTO t1 VALUES('["asdf"]'),('["ghjk"]'); SELECT * FROM t1, @@ -835,6 +864,9 @@ DEFAULT "3.14159" ON ERROR) jd col18 ["asdf"] 0.000 ["ghjk"] 0.000 +Warnings: +Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`col18` at row 1 +Warning 1366 Incorrect decimal value: 'ghjk' for column ``.`(temporary)`.`col18` at row 1 DROP TABLE t1; # # Bug#25540027: SIG 11 IN FIND_FIELD_IN_TABLE | SQL/SQL_BASE.CC @@ -1316,13 +1348,17 @@ id SELECT id FROM JSON_TABLE('[{"id":"9223372036854775808"}]', '$[*]' COLUMNS (id BIGINT PATH '$.id')) AS json; id -NULL +9223372036854775807 +Warnings: +Warning 1264 Out of range value for column 'id' at row 1 # Here the JSON value is a NUMERIC value, and we thus know if the value # is signed or unsigned. SELECT id FROM JSON_TABLE('[{"id":9223372036854775808}]', '$[*]' COLUMNS (id BIGINT PATH '$.id')) AS json; id -NULL +9223372036854775807 +Warnings: +Warning 1264 Out of range value for column 'id' at row 1 # If we tell the JSON table column to be unsigned, we get to store the # full value correctly. SELECT id FROM JSON_TABLE('[{"id":"9223372036854775808"}]', '$[*]' COLUMNS @@ -1524,11 +1560,15 @@ b VARCHAR(3) PATH '$.b' DEFAULT '"ERR"' ON ERROR, c DATE PATH '$.c' DEFAULT '"2001-01-01"' ON ERROR, d DECIMAL PATH '$.c' DEFAULT '999' ON ERROR) ) AS jt; +Warnings: +Warning 1265 Data truncated for column 'b' at row 2 +Warning 1264 Out of range value for column 'a' at row 3 +Warning 1265 Data truncated for column 'd' at row 4 SELECT * FROM t ORDER BY id; id a b c d 1 1 abc NULL NULL 2 2 abc NULL NULL -3 111 xyz NULL NULL +3 127 xyz NULL NULL 4 NULL NULL 2012-00-00 12 DROP TABLE t; # diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index b8b16a750d1..f250fcbf58a 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -798,5 +798,22 @@ EXECUTE stmt1; DEALLOCATE PREPARE stmt1; --echo # +--echo # MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion. +--echo # +select * from json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]' + columns ( id for ordinality, + intcol int path '$.a' default '1234' on empty default '5678' on error) + ) as tt; + +--echo # +--echo # MDEV-25377 JSON_TABLE: Wrong value with implicit conversion. +--echo # +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt; + +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by converted; + +select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by original; + +--echo # --echo # End of 10.6 tests --echo # diff --git a/mysql-test/suite/json/t/json_table_mysql.test b/mysql-test/suite/json/t/json_table_mysql.test index eebc4ba11ee..aaf123c6f7c 100644 --- a/mysql-test/suite/json/t/json_table_mysql.test +++ b/mysql-test/suite/json/t/json_table_mysql.test @@ -327,7 +327,7 @@ SELECT * FROM v; SHOW CREATE VIEW v; DROP VIEW v; ---error ER_JSON_TABLE_SCALAR_EXPECTED +#--error ER_JSON_TABLE_SCALAR_EXPECTED SELECT * FROM JSON_TABLE('"asdf"', '$' COLUMNS (a INT PATH '$' ERROR ON ERROR)) AS jt; --error ER_JSON_TABLE_MULTIPLE_MATCHES @@ -339,7 +339,7 @@ SELECT * FROM SELECT * FROM JSON_TABLE('[{"a":1},{"a":2}]', '$' COLUMNS (a JSON PATH '$[*].a' ERROR ON ERROR)) AS jt; ---error ER_JSON_TABLE_SCALAR_EXPECTED +#--error ER_JSON_TABLE_SCALAR_EXPECTED SELECT * FROM JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$' ERROR ON ERROR)) AS jt; SELECT * FROM @@ -729,7 +729,7 @@ SELECT * FROM ) AS alias2; #--error ER_JT_VALUE_OUT_OF_RANGE ---error ER_JSON_TABLE_SCALAR_EXPECTED +# --error ER_JSON_TABLE_SCALAR_EXPECTED SELECT * FROM JSON_TABLE('[3.14159]', '$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$' ERROR ON ERROR) |