Skip to content

Commit 41e368f

Browse files
author
Alexey Botchkov
committed
MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion.
Only return the error if field->store produced errors, not warnings.
1 parent 0a09525 commit 41e368f

File tree

5 files changed

+146
-33
lines changed

5 files changed

+146
-33
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,12 @@ json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]'
360360
intcol int path '$.a' default '1234' on empty default '5678' on error)
361361
) as tt;
362362
id intcol
363-
1 5678
363+
1 0
364364
2 123
365365
3 5678
366366
4 5678
367+
Warnings:
368+
Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`intcol` at row 1
367369
SELECT COUNT(*) FROM JSON_TABLE('[1, 2]', '$[*]' COLUMNS( I INT PATH '$')) tt;
368370
COUNT(*)
369371
2
@@ -588,9 +590,11 @@ Error 4177 Can't store an array or an object in the scalar column 'a' of JSON_TA
588590
# MDEV-JSON_TABLE: CREATE TABLE ignores NULL ON ERROR (implicit or explicit) and fails.
589591
#
590592
CREATE TABLE t1 AS SELECT * FROM JSON_TABLE('{"x":1}', '$' COLUMNS(f DATE PATH '$.*')) AS jt;
593+
Warnings:
594+
Warning 1265 Data truncated for column 'f' at row 1
591595
SELECT * FROM t1;
592596
f
593-
NULL
597+
0000-00-00
594598
DROP TABLE t1;
595599
#
596600
# MDEV-25254: JSON_TABLE: Inconsistent name resolution with right joins
@@ -907,5 +911,48 @@ a
907911
2
908912
DEALLOCATE PREPARE stmt1;
909913
#
914+
# MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion.
915+
#
916+
select * from json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]'
917+
columns ( id for ordinality,
918+
intcol int path '$.a' default '1234' on empty default '5678' on error)
919+
) as tt;
920+
id intcol
921+
1 0
922+
2 123
923+
3 5678
924+
4 5678
925+
Warnings:
926+
Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`intcol` at row 1
927+
#
928+
# MDEV-25377 JSON_TABLE: Wrong value with implicit conversion.
929+
#
930+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt;
931+
converted original
932+
0 foo
933+
1 1
934+
127 1000
935+
Warnings:
936+
Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1
937+
Warning 1264 Out of range value for column 'converted' at row 3
938+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by converted;
939+
converted original
940+
0 foo
941+
1 1
942+
127 1000
943+
Warnings:
944+
Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1
945+
Warning 1264 Out of range value for column 'converted' at row 1
946+
Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 1
947+
Warning 1264 Out of range value for column 'converted' at row 3
948+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by original;
949+
converted original
950+
1 1
951+
127 1000
952+
0 foo
953+
Warnings:
954+
Warning 1264 Out of range value for column 'converted' at row 2
955+
Warning 1366 Incorrect integer value: 'foo' for column ``.`(temporary)`.`converted` at row 3
956+
#
910957
# End of 10.6 tests
911958
#

mysql-test/suite/json/r/json_table_mysql.result

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ id jpath_i jpath_r jsn_path jexst
5959
2 2 2 2 0
6060
3 33 33.3 {"x":33} 1
6161
4 0 0.33 0.33 0
62-
5 66 0 asd 0
62+
5 0 0 asd 0
63+
Warnings:
64+
Warning 1366 Incorrect integer value: 'asd' for column ``.`(temporary)`.`jpath_i` at row 5
65+
Warning 1366 Incorrect double value: 'asd' for column ``.`(temporary)`.`jpath_r` at row 5
6366
select * from
6467
json_table(
6568
'[{"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
396399
DROP VIEW v;
397400
SELECT * FROM JSON_TABLE('"asdf"',
398401
'$' COLUMNS (a INT PATH '$' ERROR ON ERROR)) AS jt;
399-
ERROR HY000: Can't store an array or an object in the scalar column 'a' of JSON_TABLE 'jt'.
402+
a
403+
0
404+
Warnings:
405+
Warning 1366 Incorrect integer value: 'asdf' for column ``.`(temporary)`.`a` at row 1
400406
SELECT * FROM
401407
JSON_TABLE('[{"a":1},{"a":2}]',
402408
'$' COLUMNS (a INT PATH '$[*].a' ERROR ON ERROR)) AS jt;
@@ -407,11 +413,16 @@ JSON_TABLE('[{"a":1},{"a":2}]',
407413
ERROR HY000: Can't store multiple matches of the path in the column 'a' of JSON_TABLE 'jt'.
408414
SELECT * FROM
409415
JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$' ERROR ON ERROR)) AS jt;
410-
ERROR HY000: Can't store an array or an object in the scalar column 'a' of JSON_TABLE 'jt'.
416+
a
417+
9.9
418+
Warnings:
419+
Warning 1264 Out of range value for column 'a' at row 1
411420
SELECT * FROM
412421
JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$')) AS jt;
413422
a
414-
NULL
423+
9.9
424+
Warnings:
425+
Warning 1264 Out of range value for column 'a' at row 1
415426
SELECT * FROM
416427
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":{}}}}}}}}}}}}}}}}}}}',
417428
'$' COLUMNS (i0 INT PATH '$.a',
@@ -525,7 +536,13 @@ i INT PATH '$',
525536
f FLOAT PATH '$',
526537
d DECIMAL PATH '$')) AS jt;
527538
tm dt i f d
528-
NULL NULL NULL 0 0
539+
00:00:00 0000-00-00 0 0 0
540+
Warnings:
541+
Warning 1265 Data truncated for column 'tm' at row 1
542+
Warning 1265 Data truncated for column 'dt' at row 1
543+
Warning 1366 Incorrect integer value: 'asdf' for column ``.`(temporary)`.`i` at row 1
544+
Warning 1366 Incorrect double value: 'asdf' for column ``.`(temporary)`.`f` at row 1
545+
Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`d` at row 1
529546
SELECT * FROM
530547
JSON_TABLE('{}', '$' COLUMNS (x INT PATH '$.x' DEFAULT NULL ON EMPTY)) jt;
531548
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"}',
739756
AS jt;
740757
jp
741758
0000-00-00
759+
Warnings:
760+
Warning 1265 Data truncated for column 'jp' at row 1
742761
#
743762
# Bug#25532429: INVALID JSON ERROR NOT THROWN WITH EMPTY TABLES JOIN
744763
#
@@ -763,6 +782,8 @@ JSON_TABLE('["3.14159"]',
763782
) AS alias2;
764783
col18
765784
3.1415
785+
Warnings:
786+
Warning 1265 Data truncated for column 'col18' at row 1
766787
#Truncated space doesn't trigger ON ERROR
767788
SELECT * FROM
768789
JSON_TABLE('["3.14159 "]',
@@ -805,12 +826,17 @@ JSON_TABLE('[3.14159]',
805826
'$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$')
806827
) AS alias2;
807828
col18
808-
NULL
829+
0.999
830+
Warnings:
831+
Warning 1264 Out of range value for column 'col18' at row 1
809832
SELECT * FROM
810833
JSON_TABLE('[3.14159]',
811834
'$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$' ERROR ON ERROR)
812835
) AS alias2;
813-
ERROR HY000: Can't store an array or an object in the scalar column 'col18' of JSON_TABLE 'alias2'.
836+
col18
837+
0.999
838+
Warnings:
839+
Warning 1264 Out of range value for column 'col18' at row 1
814840
SELECT * FROM
815841
JSON_TABLE('[0.9]',
816842
'$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$')
@@ -825,6 +851,9 @@ DEFAULT "3.14159" ON ERROR)
825851
col18
826852
0.000
827853
0.000
854+
Warnings:
855+
Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`col18` at row 1
856+
Warning 1366 Incorrect decimal value: 'ghjk' for column ``.`(temporary)`.`col18` at row 2
828857
CREATE TABLE t1(jd JSON);
829858
INSERT INTO t1 VALUES('["asdf"]'),('["ghjk"]');
830859
SELECT * FROM t1,
@@ -835,6 +864,9 @@ DEFAULT "3.14159" ON ERROR)
835864
jd col18
836865
["asdf"] 0.000
837866
["ghjk"] 0.000
867+
Warnings:
868+
Warning 1366 Incorrect decimal value: 'asdf' for column ``.`(temporary)`.`col18` at row 1
869+
Warning 1366 Incorrect decimal value: 'ghjk' for column ``.`(temporary)`.`col18` at row 1
838870
DROP TABLE t1;
839871
#
840872
# Bug#25540027: SIG 11 IN FIND_FIELD_IN_TABLE | SQL/SQL_BASE.CC
@@ -1316,13 +1348,17 @@ id
13161348
SELECT id FROM JSON_TABLE('[{"id":"9223372036854775808"}]', '$[*]' COLUMNS
13171349
(id BIGINT PATH '$.id')) AS json;
13181350
id
1319-
NULL
1351+
9223372036854775807
1352+
Warnings:
1353+
Warning 1264 Out of range value for column 'id' at row 1
13201354
# Here the JSON value is a NUMERIC value, and we thus know if the value
13211355
# is signed or unsigned.
13221356
SELECT id FROM JSON_TABLE('[{"id":9223372036854775808}]', '$[*]' COLUMNS
13231357
(id BIGINT PATH '$.id')) AS json;
13241358
id
1325-
NULL
1359+
9223372036854775807
1360+
Warnings:
1361+
Warning 1264 Out of range value for column 'id' at row 1
13261362
# If we tell the JSON table column to be unsigned, we get to store the
13271363
# full value correctly.
13281364
SELECT id FROM JSON_TABLE('[{"id":"9223372036854775808"}]', '$[*]' COLUMNS
@@ -1524,11 +1560,15 @@ b VARCHAR(3) PATH '$.b' DEFAULT '"ERR"' ON ERROR,
15241560
c DATE PATH '$.c' DEFAULT '"2001-01-01"' ON ERROR,
15251561
d DECIMAL PATH '$.c' DEFAULT '999' ON ERROR)
15261562
) AS jt;
1563+
Warnings:
1564+
Warning 1265 Data truncated for column 'b' at row 2
1565+
Warning 1264 Out of range value for column 'a' at row 3
1566+
Warning 1265 Data truncated for column 'd' at row 4
15271567
SELECT * FROM t ORDER BY id;
15281568
id a b c d
15291569
1 1 abc NULL NULL
15301570
2 2 abc NULL NULL
1531-
3 111 xyz NULL NULL
1571+
3 127 xyz NULL NULL
15321572
4 NULL NULL 2012-00-00 12
15331573
DROP TABLE t;
15341574
#

mysql-test/suite/json/t/json_table.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,23 @@ SELECT * FROM JSON_TABLE (CONVERT('[1,2]' USING koi8u), '$[*]' COLUMNS(a CHAR(8)
797797
EXECUTE stmt1;
798798
DEALLOCATE PREPARE stmt1;
799799

800+
--echo #
801+
--echo # MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion.
802+
--echo #
803+
select * from json_table( '[{"a":"asd"}, {"a":123}, {"a":[]}, {"a":{}} ]', '$[*]'
804+
columns ( id for ordinality,
805+
intcol int path '$.a' default '1234' on empty default '5678' on error)
806+
) as tt;
807+
808+
--echo #
809+
--echo # MDEV-25377 JSON_TABLE: Wrong value with implicit conversion.
810+
--echo #
811+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt;
812+
813+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by converted;
814+
815+
select * from json_table('{"a":"foo", "b":1, "c":1000}', '$.*' columns(converted tinyint path '$', original text path '$')) as jt order by original;
816+
800817
--echo #
801818
--echo # End of 10.6 tests
802819
--echo #

mysql-test/suite/json/t/json_table_mysql.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ SELECT * FROM v;
327327
SHOW CREATE VIEW v;
328328
DROP VIEW v;
329329

330-
--error ER_JSON_TABLE_SCALAR_EXPECTED
330+
#--error ER_JSON_TABLE_SCALAR_EXPECTED
331331
SELECT * FROM JSON_TABLE('"asdf"',
332332
'$' COLUMNS (a INT PATH '$' ERROR ON ERROR)) AS jt;
333333
--error ER_JSON_TABLE_MULTIPLE_MATCHES
@@ -339,7 +339,7 @@ SELECT * FROM
339339
SELECT * FROM
340340
JSON_TABLE('[{"a":1},{"a":2}]',
341341
'$' COLUMNS (a JSON PATH '$[*].a' ERROR ON ERROR)) AS jt;
342-
--error ER_JSON_TABLE_SCALAR_EXPECTED
342+
#--error ER_JSON_TABLE_SCALAR_EXPECTED
343343
SELECT * FROM
344344
JSON_TABLE('123.456', '$' COLUMNS (a DECIMAL(2,1) PATH '$' ERROR ON ERROR)) AS jt;
345345
SELECT * FROM
@@ -729,7 +729,7 @@ SELECT * FROM
729729
) AS alias2;
730730

731731
#--error ER_JT_VALUE_OUT_OF_RANGE
732-
--error ER_JSON_TABLE_SCALAR_EXPECTED
732+
# --error ER_JSON_TABLE_SCALAR_EXPECTED
733733
SELECT * FROM
734734
JSON_TABLE('[3.14159]',
735735
'$[*]' COLUMNS (col18 DECIMAL(3,3) PATH '$' ERROR ON ERROR)

0 commit comments

Comments
 (0)