diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2020-07-16 14:46:21 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2020-07-16 14:46:21 +0400 |
commit | d3a311a8e9508ef94dddb6b7f4d366337a9fd64a (patch) | |
tree | 6fb726ce683ba1760df1f08be6f98cf0ef2dfbd2 /mysql-test/suite/json/r/json_table.result | |
parent | b1ab211dee599eabd9a5b886fafa3adea29ae041 (diff) | |
download | mariadb-git-d3a311a8e9508ef94dddb6b7f4d366337a9fd64a.tar.gz |
MDEV-17399 Add support for JSON_TABLE.
ha_json_table handler implemented.
JSON_TABLE() added to SQL syntax.
Diffstat (limited to 'mysql-test/suite/json/r/json_table.result')
-rw-r--r-- | mysql-test/suite/json/r/json_table.result | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result new file mode 100644 index 00000000000..c5cd0998133 --- /dev/null +++ b/mysql-test/suite/json/r/json_table.result @@ -0,0 +1,220 @@ +select * from json_table('[{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}]', '$[*]' COLUMNS( a INT PATH '$.a')) as tt; +a +1 +2 +select * from JSON_TABLE( '[ {"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +a b +1 11 +1 111 +2 22 +2 222 +SELECT * FROM JSON_TABLE( '[ {"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'), NESTED PATH '$.b[*]' COLUMNS (c INT PATH '$') ) ) jt; +a b c +1 11 NULL +1 111 NULL +1 NULL 11 +1 NULL 111 +2 22 NULL +2 222 NULL +2 NULL 22 +2 NULL 222 +create table t1 (id varchar(5), json varchar(1024)); +insert into t1 values ('j1', '[{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}]'); +insert into t1 values ('j2', '[{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}]'); +select id, json, a from t1, json_table(t1.json, '$[*]' COLUMNS(js_id FOR ORDINALITY, a INT PATH '$.a')) as tt; +id json a +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 1 +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 2 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 3 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 4 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 5 +select * from t1, JSON_TABLE(t1.json, '$[*]' COLUMNS(js_id FOR ORDINALITY, a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (l_js_id FOR ORDINALITY, b INT PATH '$'))) as jt; +id json js_id a l_js_id b +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 1 1 1 11 +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 1 1 2 111 +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 2 2 1 22 +j1 [{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}] 2 2 2 222 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 1 3 1 11 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 1 3 2 111 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 2 4 1 22 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 2 4 2 222 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 3 5 1 22 +j2 [{"a": 3, "b": [11,111]}, {"a": 4, "b": [22,222]}, {"a": 5, "b": [22,222]}] 3 5 2 222 +select * from t1, JSON_TABLE(t1.no_field, '$[*]' COLUMNS(js_id FOR ORDINALITY, a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (l_js_id FOR ORDINALITY, b INT PATH '$'))) as jt; +ERROR 42S22: Unknown column 't1.no_field' in 'JSON_TABLE argument' +select * from t1, JSON_TABLE(t1.no_field, '$[*]' COLUMNS(js_id FOR ORDINALITY, a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (l_js_id FOR ORDINALITY, a INT PATH '$'))) as jt; +ERROR 42S21: Duplicate column name 'a' +DROP TABLE t1; +create table t1 (item_name varchar(32), item_props varchar(1024)); +insert into t1 values ('Laptop', '{"color": "black", "price": 1000}'); +insert into t1 values ('Jeans', '{"color": "blue", "price": 50}'); +select * from t1 left join json_table(t1.item_props,'$' columns( color varchar(100) path '$.color')) as T on 1; +item_name item_props color +Laptop {"color": "black", "price": 1000} black +Jeans {"color": "blue", "price": 50} blue +select * from t1 right join json_table(t1.item_props,'$' columns( color varchar(100) path '$.color')) as T on 1; +ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions +DROP TABLE t1; +select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +a b +101 11 +101 111 +2 22 +2 222 +select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '202' on error, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +a b +NULL 11 +NULL 111 +2 22 +2 222 +select * from JSON_TABLE( '[ {"a": [1, 2], "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +a b +NULL 11 +NULL 111 +2 22 +2 222 +select * from JSON_TABLE( '[ {"a": [1, 2], "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '202' on error default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +a b +202 11 +202 111 +2 22 +2 222 +select * from JSON_TABLE( '[{"a": [1, 2], "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3} xx YY]', '$[*]' COLUMNS( a INT PATH '$.a' default '202' on error default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +ERROR HY000: Syntax error in JSON text in argument 1 to function 'JSON_TABLE' at position 65 +select * from JSON_TABLE( '[{"a": [1, 2], "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' error on error default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt; +ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'. +select * from json_table('{"a":0}',"$" columns(a decimal(1,1) path '$.a')) foo; +a +0.0 +connect con1,localhost,root,,; +select a from json_table('{"a":0}',"$" columns(a for ordinality)) foo; +a +1 +connection default; +disconnect con1; +create database db; +use db; +create table t (a text); +insert into t values ('{"foo":"bar"}'); +create user u@localhost; +grant select (a) on db.t to u@localhost; +connect con1,localhost,u,,db; +select a from t; +a +{"foo":"bar"} +select * from t, json_table(t.a, '$' columns(f varchar(20) path '$.foo')) as jt; +a f +{"foo":"bar"} bar +connection default; +disconnect con1; +drop user u@localhost; +drop database db; +use test; +create table t1 ( +color varchar(32), +price int +); +insert into t1 values ("red", 100), ("blue", 50); +insert into t1 select * from t1; +insert into t1 select * from t1; +set optimizer_switch='firstmatch=off'; +select * from +json_table('[{"color": "blue", "price": 50}, + {"color": "red", "price": 100}]', +'$[*]' columns( color varchar(100) path '$.color', +price text path '$.price' + ) +) as T +where +T.color in (select color from t1 where t1.price=T.price); +color price +blue 50 +red 100 +drop table t1; +select * from +json_table(' [ {"color": "blue", "sizes": [1,2,3,4], "prices" : [10,20]}, + {"color": "red", "sizes": [10,11,12,13,14], "prices" : [100,200,300]} ]', +'$[*]' columns( +color varchar(4) path '$.color', +seq0 for ordinality, +nested path '$.sizes[*]' + columns (seq1 for ordinality, +size int path '$'), +nested path '$.prices[*]' + columns (seq2 for ordinality, +price int path '$') +) +) as T; +color seq0 seq1 size seq2 price +blue 1 1 1 NULL NULL +blue 1 2 2 NULL NULL +blue 1 3 3 NULL NULL +blue 1 4 4 NULL NULL +blue 1 NULL NULL 1 10 +blue 1 NULL NULL 2 20 +red 2 1 10 NULL NULL +red 2 2 11 NULL NULL +red 2 3 12 NULL NULL +red 2 4 13 NULL NULL +red 2 5 14 NULL NULL +red 2 NULL NULL 1 100 +red 2 NULL NULL 2 200 +red 2 NULL NULL 3 300 +select * from json_table('[{"color": "blue", "price": 50}, + {"color": "red", "price": 100}, + {"color": "rojo", "price": 10.0}, + {"color": "blanco", "price": 11.0}]', +'$[*]' columns( color varchar(100) path '$.color', +price text path '$.price', seq for ordinality)) as T order by color desc; +color price seq +rojo 10.0 3 +red 100 2 +blue 50 1 +blanco 11.0 4 +create view v as select * from json_table('{"as":"b", "x":123}',"$" columns(a varchar(8) path '$.a' default '-' on empty, x int path '$.x')) x; +select * from v; +a x +- 123 +show create table v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `x`.`a` AS `a`,`x`.`x` AS `x` from JSON_TABLE('{"as":"b", "x":123}', "$" COLUMNS (`a` varchar(8) PATH "$.a" DEFAULT '-' ON EMPTY, `x` int(11) PATH "$.x")) x latin1 latin1_swedish_ci +drop view v; +select * from json_table('{"as":"b", "x":123}', +"$" columns(a varchar(8) path '$.a' default '-' on empty null on error null on empty, x int path '$.x')) x; +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, x int path '$.x')) x' at line 2 +select * from json_table('{"a":"foo","b":"bar"}', '$' + columns (v varchar(20) path '$.*')) as jt; +v +NULL +select * from json_table('{"a":"foo","b":"bar"}', '$' + columns (v varchar(20) path '$.*' default '-' on error)) as jt; +v +- +select * from json_table('{"b":"bar"}', '$' + columns (v varchar(20) path '$.*' default '-' on error)) as jt; +v +bar +create table t1 (a varchar(100)); +insert into t1 values ('1'); +select * from t1 as T, json_table(T.a, '$[*]' columns(color varchar(100) path '$.nonexistent', seq for ordinality)) as T; +ERROR 42000: Not unique table/alias: 'T' +drop table t1; +prepare s from 'select * from +json_table(?, + \'$[*]\' columns( color varchar(100) path \'$.color\', + price text path \'$.price\', + seq for ordinality)) as T +order by color desc; '; +execute s using '[{"color": "red", "price":1}, {"color":"brown", "price":2}]'; +color price seq +red 1 1 +brown 2 2 +deallocate prepare s; +create view v2 as select * from json_table('[{"co\\\\lor": "blue", "price": 50}]', '$[*]' columns( color varchar(100) path '$.co\\\\lor') ) as T; +select * from v2; +color +blue +drop view v2; +# +# End of 10.5 tests +# |