mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-32454 JSON test has problem in view protocol.
Few Item_func_json_xxx::fix_length_and_dec() functions fixed.
This commit is contained in:
@ -272,7 +272,7 @@ create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
|
|||||||
show create table t1;
|
show create table t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`f` varchar(32) DEFAULT NULL
|
`f` varchar(46) DEFAULT NULL
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
select * from t1;
|
select * from t1;
|
||||||
f
|
f
|
||||||
|
@ -87,15 +87,12 @@ select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]') as exp;
|
|||||||
select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]', '$[25]') as exp;
|
select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]', '$[25]') as exp;
|
||||||
select json_extract( '[{"a": [3, 4]}, {"b": 2}]', '$[0].a', '$[1].a') as exp;
|
select json_extract( '[{"a": [3, 4]}, {"b": 2}]', '$[0].a', '$[1].a') as exp;
|
||||||
|
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word') as exp;
|
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word') as exp;
|
||||||
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3) as exp;
|
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3) as exp;
|
||||||
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.a[2]', 2) as exp;
|
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.a[2]', 2) as exp;
|
||||||
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.c', 'word') as exp;
|
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.c', 'word') as exp;
|
||||||
|
|
||||||
select json_set('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
|
select json_set('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
|
||||||
--enable_view_protocol
|
|
||||||
|
|
||||||
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
|
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
|
||||||
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.b', '[true, false]') as exp;
|
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.b', '[true, false]') as exp;
|
||||||
@ -137,14 +134,11 @@ select json_merge('a','b');
|
|||||||
select json_merge('{"a":"b"}','{"c":"d"}');
|
select json_merge('{"a":"b"}','{"c":"d"}');
|
||||||
SELECT JSON_MERGE('[1, 2]', '{"id": 47}');
|
SELECT JSON_MERGE('[1, 2]', '{"id": 47}');
|
||||||
|
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
select json_type('{"k1":123, "k2":345}');
|
select json_type('{"k1":123, "k2":345}');
|
||||||
select json_type('[123, "k2", 345]');
|
select json_type('[123, "k2", 345]');
|
||||||
select json_type("true");
|
select json_type("true");
|
||||||
select json_type('123');
|
select json_type('123');
|
||||||
select json_type('123.12');
|
select json_type('123.12');
|
||||||
--enable_view_protocol
|
|
||||||
|
|
||||||
select json_keys('{"a":{"c":1, "d":2}, "b":2}');
|
select json_keys('{"a":{"c":1, "d":2}, "b":2}');
|
||||||
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a");
|
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a");
|
||||||
@ -173,11 +167,8 @@ select json_search( json_col, 'all', 'foot' ) as ex from t1;
|
|||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
select json_unquote('"abc"');
|
select json_unquote('"abc"');
|
||||||
select json_unquote('abc');
|
select json_unquote('abc');
|
||||||
--enable_view_protocol
|
|
||||||
#
|
#
|
||||||
# MDEV-13703 Illegal mix of collations for operation 'json_object' on using JSON_UNQUOTE as an argument.
|
# MDEV-13703 Illegal mix of collations for operation 'json_object' on using JSON_UNQUOTE as an argument.
|
||||||
#
|
#
|
||||||
@ -188,13 +179,9 @@ select json_object('foo', json_unquote(json_object('bar', c)),'qux', c) as fld f
|
|||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
select json_object("a", json_object("b", "abcd"));
|
select json_object("a", json_object("b", "abcd"));
|
||||||
select json_object("a", '{"b": "abcd"}');
|
select json_object("a", '{"b": "abcd"}');
|
||||||
select json_object("a", json_compact('{"b": "abcd"}'));
|
select json_object("a", json_compact('{"b": "abcd"}'));
|
||||||
--enable_view_protocol
|
|
||||||
|
|
||||||
|
|
||||||
select json_compact(NULL);
|
select json_compact(NULL);
|
||||||
select json_depth(json_compact(NULL));
|
select json_depth(json_compact(NULL));
|
||||||
@ -270,11 +257,8 @@ select json_merge('{"a":{"u":12, "x":"b"}}', '{"a":{"x":"c"}}') as ex ;
|
|||||||
select json_merge('{"a":{"u":12, "x":"b", "r":1}}', '{"a":{"x":"c", "r":2}}') as ex ;
|
select json_merge('{"a":{"u":12, "x":"b", "r":1}}', '{"a":{"x":"c", "r":2}}') as ex ;
|
||||||
|
|
||||||
select json_compact('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
select json_compact('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
select json_loose('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
select json_loose('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
||||||
select json_detailed('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
select json_detailed('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
|
||||||
--enable_view_protocol
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# MDEV-11856 json_search doesn't search for values with double quotes character (")
|
# MDEV-11856 json_search doesn't search for values with double quotes character (")
|
||||||
@ -466,12 +450,9 @@ drop table t1;
|
|||||||
--echo # MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
|
--echo # MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
|
||||||
--echo #
|
--echo #
|
||||||
|
|
||||||
#enable after MDEV-32454 fix
|
|
||||||
--disable_view_protocol
|
|
||||||
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6) as exp;
|
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6) as exp;
|
||||||
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6) as exp;
|
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6) as exp;
|
||||||
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6') as exp;
|
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6') as exp;
|
||||||
--enable_view_protocol
|
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # MDEV-17121 JSON_ARRAY_APPEND
|
--echo # MDEV-17121 JSON_ARRAY_APPEND
|
||||||
|
@ -3338,7 +3338,7 @@ OBJECT
|
|||||||
CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
|
CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
|
||||||
SELECT * FROM v1;
|
SELECT * FROM v1;
|
||||||
JSON_TYPE(JSON_OBJECT())
|
JSON_TYPE(JSON_OBJECT())
|
||||||
OBJE
|
OBJECT
|
||||||
drop view v1;
|
drop view v1;
|
||||||
#
|
#
|
||||||
# Bug#21198333 SIG 6 IN ITEM_CACHE_JSON::CACHE_VALUE AT SQL/ITEM.CC:9470
|
# Bug#21198333 SIG 6 IN ITEM_CACHE_JSON::CACHE_VALUE AT SQL/ITEM.CC:9470
|
||||||
|
@ -761,7 +761,7 @@ bool Item_func_json_unquote::fix_length_and_dec()
|
|||||||
{
|
{
|
||||||
collation.set(&my_charset_utf8_general_ci,
|
collation.set(&my_charset_utf8_general_ci,
|
||||||
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
|
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
|
||||||
max_length= args[0]->max_length;
|
max_length= args[0]->max_char_length() * collation.collation->mbmaxlen;
|
||||||
maybe_null= 1;
|
maybe_null= 1;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1730,7 +1730,22 @@ bool Item_func_json_array::fix_length_and_dec()
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
for (n_arg=0 ; n_arg < arg_count ; n_arg++)
|
for (n_arg=0 ; n_arg < arg_count ; n_arg++)
|
||||||
char_length+= args[n_arg]->max_char_length() + 4;
|
{
|
||||||
|
ulonglong arg_length;
|
||||||
|
Item *arg= args[n_arg];
|
||||||
|
|
||||||
|
if (!arg->is_json_type() && arg->result_type() == STRING_RESULT)
|
||||||
|
arg_length= arg->max_char_length() * 2; /*escaping possible */
|
||||||
|
else if (arg->type_handler()->is_bool_type())
|
||||||
|
arg_length= 5;
|
||||||
|
else
|
||||||
|
arg_length= arg->max_char_length();
|
||||||
|
|
||||||
|
if (arg_length < 4)
|
||||||
|
arg_length= 4; /* can be 'null' */
|
||||||
|
|
||||||
|
char_length+= arg_length + 4;
|
||||||
|
}
|
||||||
|
|
||||||
fix_char_length_ulonglong(char_length);
|
fix_char_length_ulonglong(char_length);
|
||||||
tmp_val.set_charset(collation.collation);
|
tmp_val.set_charset(collation.collation);
|
||||||
@ -2874,7 +2889,7 @@ longlong Item_func_json_depth::val_int()
|
|||||||
bool Item_func_json_type::fix_length_and_dec()
|
bool Item_func_json_type::fix_length_and_dec()
|
||||||
{
|
{
|
||||||
collation.set(&my_charset_utf8_general_ci);
|
collation.set(&my_charset_utf8_general_ci);
|
||||||
max_length= 12;
|
max_length= 12 * collation.collation->mbmaxlen;
|
||||||
maybe_null= 1;
|
maybe_null= 1;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -2940,6 +2955,11 @@ bool Item_func_json_insert::fix_length_and_dec()
|
|||||||
for (n_arg= 1; n_arg < arg_count; n_arg+= 2)
|
for (n_arg= 1; n_arg < arg_count; n_arg+= 2)
|
||||||
{
|
{
|
||||||
paths[n_arg/2].set_constant_flag(args[n_arg]->const_item());
|
paths[n_arg/2].set_constant_flag(args[n_arg]->const_item());
|
||||||
|
/*
|
||||||
|
In the resulting JSON we can insert the property
|
||||||
|
name from the path, and the value itself.
|
||||||
|
*/
|
||||||
|
char_length+= args[n_arg/2]->max_char_length() + 6;
|
||||||
char_length+= args[n_arg/2+1]->max_char_length() + 4;
|
char_length+= args[n_arg/2+1]->max_char_length() + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3749,7 +3769,20 @@ bool Item_func_json_format::fix_length_and_dec()
|
|||||||
{
|
{
|
||||||
decimals= 0;
|
decimals= 0;
|
||||||
collation.set(args[0]->collation);
|
collation.set(args[0]->collation);
|
||||||
max_length= args[0]->max_length;
|
switch (fmt)
|
||||||
|
{
|
||||||
|
case COMPACT:
|
||||||
|
max_length= args[0]->max_length;
|
||||||
|
break;
|
||||||
|
case LOOSE:
|
||||||
|
max_length= args[0]->max_length * 2;
|
||||||
|
break;
|
||||||
|
case DETAILED:
|
||||||
|
max_length= MAX_BLOB_WIDTH;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
};
|
||||||
maybe_null= 1;
|
maybe_null= 1;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user