Skip to content

Instantly share code, notes, and snippets.

@spetrunia
Created April 14, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spetrunia/5f4f13ef5fdf91ca1f343bcb34f3c815 to your computer and use it in GitHub Desktop.
Save spetrunia/5f4f13ef5fdf91ca1f343bcb34f3c815 to your computer and use it in GitHub Desktop.
diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result
index 34f25f316d4..2fee5aae5a6 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
@@ -821,6 +825,14 @@ SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o F
ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
+# MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.
+#
+SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
+SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
+SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
#
# 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 ffe94da2750..1be1dee5381 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
@@ -1317,13 +1349,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
@@ -1525,11 +1561,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 e5f2c26c67f..694fd21ee92 100644
--- a/mysql-test/suite/json/t/json_table.test
+++ b/mysql-test/suite/json/t/json_table.test
@@ -718,6 +718,15 @@ SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o F
--error ER_JSON_TABLE_ERROR_ON_FIELD
SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+--echo # MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.
+--echo #
+--error ER_JSON_TABLE_ERROR_ON_FIELD
+SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+--error ER_JSON_TABLE_ERROR_ON_FIELD
+SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+--error ER_JSON_TABLE_ERROR_ON_FIELD
+SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+
--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..e51de0cc51a 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)
diff --git a/sql/json_table.cc b/sql/json_table.cc
index 2e890aa8c22..a306fd6c937 100644
--- a/sql/json_table.cc
+++ b/sql/json_table.cc
@@ -399,7 +399,9 @@ int ha_json_table::rnd_next(uchar *buf)
they are in).
*/
cf_orig= table->in_use->count_cuted_fields;
- table->in_use->count_cuted_fields= CHECK_FIELD_EXPRESSION;
+ table->in_use->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
+
res= fill_column_values(buf, NULL);
table->in_use->count_cuted_fields= cf_orig;
return res ? HA_ERR_JSON_TABLE : 0;
@@ -516,18 +520,23 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
else /*PATH*/
{
if (not_found)
- {
error= jc->m_on_empty.respond(jc, *f, ER_JSON_TABLE_ERROR_ON_FIELD);
- }
else
{
- if (!json_value_scalar(&je) ||
- store_json_in_field(*f, &je))
+ if (!json_value_scalar(&je))
{
error= jc->m_on_error.respond(jc, *f,
ER_JSON_TABLE_SCALAR_EXPECTED);
}
else
+ {
+ // This can encounter type conversion errors. They will emit
+ // warnings but they are not treated as errors for the purposes
+ // of JSON_TABLE's ON ERROR clauses
+ store_json_in_field(*f, &je);
+ }
+
+ if (!error)
{
/*
If the path contains wildcards, check if there are
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment