Skip to content

Commit c1fd027

Browse files
committed
Merge branch '10.2' into 10.3
2 parents e506bef + fae6539 commit c1fd027

File tree

59 files changed

+1322
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1322
-820
lines changed

mysql-test/main/func_json.result

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ select json_merge('string', 123);
306306
json_merge('string', 123)
307307
NULL
308308
Warnings:
309-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge' at position 1
309+
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge_preserve' at position 1
310310
select json_merge('"string"', 123);
311311
json_merge('"string"', 123)
312312
["string", 123]
@@ -326,7 +326,7 @@ select json_merge('a','b');
326326
json_merge('a','b')
327327
NULL
328328
Warnings:
329-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge' at position 1
329+
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge_preserve' at position 1
330330
select json_merge('{"a":"b"}','{"c":"d"}');
331331
json_merge('{"a":"b"}','{"c":"d"}')
332332
{"a": "b", "c": "d"}
@@ -843,6 +843,77 @@ SELECT CHARSET(JSON_OBJECT());
843843
CHARSET(JSON_OBJECT())
844844
latin1
845845
#
846+
# MDEV-13992 Implement JSON_MERGE_PATCH
847+
#
848+
CREATE TABLE merge_t(
849+
id INT PRIMARY KEY AUTO_INCREMENT,
850+
target VARCHAR(100), patch VARCHAR(100)
851+
);
852+
INSERT INTO merge_t(target, patch) VALUES
853+
('{"a":"b"}', '{"a":"c"}'),
854+
('{"a":"b"}', '{"b":"c"}'),
855+
('{"a":"b"}', '{"a":null}'),
856+
('{"a":"b", "b":"c"}', '{"a":null}'),
857+
('{"a":["b"]}', '{"a":"c"}'),
858+
('{"a":"c"}', '{"a":["b"]}'),
859+
('{"a": {"b":"c"}}', '{"a": {"b":"d", "c":null}}'),
860+
('{"a":[{"b":"c"}]}', '{"a": [1]}'),
861+
('["a","b"]', '["c","d"]'),
862+
('{"a":"b"}', '["c"]'),
863+
('{"a":"foo"}', 'null'),
864+
('{"a":"foo"}', '"bar"'),
865+
('{"e":null}', '{"a":1}'),
866+
('[1,2]', '{"a":"b", "c":null}'),
867+
('{}', '{"a":{"bb":{"ccc":null}}}'),
868+
(NULL, '{}'),
869+
('{}', NULL);
870+
SELECT id, target, patch,
871+
JSON_MERGE_PATCH(target, patch) AS merged,
872+
JSON_EXTRACT(JSON_MERGE_PATCH(target, patch), '$.a') AS a
873+
FROM merge_t ORDER BY id;
874+
id target patch merged a
875+
1 {"a":"b"} {"a":"c"} {"a": "c"} "c"
876+
2 {"a":"b"} {"b":"c"} {"a": "b", "b": "c"} "b"
877+
3 {"a":"b"} {"a":null} {} NULL
878+
4 {"a":"b", "b":"c"} {"a":null} {"b": "c"} NULL
879+
5 {"a":["b"]} {"a":"c"} {"a": "c"} "c"
880+
6 {"a":"c"} {"a":["b"]} {"a": ["b"]} ["b"]
881+
7 {"a": {"b":"c"}} {"a": {"b":"d", "c":null}} {"a": {"b": "d"}} {"b": "d"}
882+
8 {"a":[{"b":"c"}]} {"a": [1]} {"a": [1]} [1]
883+
9 ["a","b"] ["c","d"] ["c", "d"] NULL
884+
10 {"a":"b"} ["c"] ["c"] NULL
885+
11 {"a":"foo"} null null NULL
886+
12 {"a":"foo"} "bar" "bar" NULL
887+
13 {"e":null} {"a":1} {"e": null, "a": 1} 1
888+
14 [1,2] {"a":"b", "c":null} {"a": "b"} "b"
889+
15 {} {"a":{"bb":{"ccc":null}}} {"a": {"bb": {}}} {"bb": {}}
890+
16 NULL {} NULL NULL
891+
17 {} NULL NULL NULL
892+
DROP TABLE merge_t;
893+
SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '{"c":"d"}');
894+
JSON_MERGE_PATCH('{"a":"b"}', NULL, '{"c":"d"}')
895+
NULL
896+
SELECT JSON_MERGE_PATCH(NULL, '[1,2,3]');
897+
JSON_MERGE_PATCH(NULL, '[1,2,3]')
898+
[1, 2, 3]
899+
SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '[1,2,3]', '{"c":null,"d":"e"}');
900+
JSON_MERGE_PATCH('{"a":"b"}', NULL, '[1,2,3]', '{"c":null,"d":"e"}')
901+
{"d": "e"}
902+
SELECT JSON_MERGE_PATCH();
903+
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE_PATCH'
904+
SELECT JSON_MERGE_PATCH('{}');
905+
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE_PATCH'
906+
SELECT JSON_MERGE_PATCH('{', '[1,2,3]');
907+
JSON_MERGE_PATCH('{', '[1,2,3]')
908+
NULL
909+
Warnings:
910+
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_merge_patch'
911+
SELECT JSON_MERGE_PATCH('{"a":"b"}', '[1,');
912+
JSON_MERGE_PATCH('{"a":"b"}', '[1,')
913+
NULL
914+
Warnings:
915+
Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_merge_patch'
916+
#
846917
# End of 10.2 tests
847918
#
848919
#

mysql-test/main/func_json.test

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,49 @@ SELECT JSON_ARRAY(_UTF8 'str', JSON_OBJECT(_LATIN1 'plugin', _LATIN1'unix_socket
491491
SELECT CHARSET(JSON_ARRAY());
492492
SELECT CHARSET(JSON_OBJECT());
493493

494+
--echo #
495+
--echo # MDEV-13992 Implement JSON_MERGE_PATCH
496+
--echo #
497+
498+
CREATE TABLE merge_t(
499+
id INT PRIMARY KEY AUTO_INCREMENT,
500+
target VARCHAR(100), patch VARCHAR(100)
501+
);
502+
INSERT INTO merge_t(target, patch) VALUES
503+
('{"a":"b"}', '{"a":"c"}'),
504+
('{"a":"b"}', '{"b":"c"}'),
505+
('{"a":"b"}', '{"a":null}'),
506+
('{"a":"b", "b":"c"}', '{"a":null}'),
507+
('{"a":["b"]}', '{"a":"c"}'),
508+
('{"a":"c"}', '{"a":["b"]}'),
509+
('{"a": {"b":"c"}}', '{"a": {"b":"d", "c":null}}'),
510+
('{"a":[{"b":"c"}]}', '{"a": [1]}'),
511+
('["a","b"]', '["c","d"]'),
512+
('{"a":"b"}', '["c"]'),
513+
('{"a":"foo"}', 'null'),
514+
('{"a":"foo"}', '"bar"'),
515+
('{"e":null}', '{"a":1}'),
516+
('[1,2]', '{"a":"b", "c":null}'),
517+
('{}', '{"a":{"bb":{"ccc":null}}}'),
518+
(NULL, '{}'),
519+
('{}', NULL);
520+
SELECT id, target, patch,
521+
JSON_MERGE_PATCH(target, patch) AS merged,
522+
JSON_EXTRACT(JSON_MERGE_PATCH(target, patch), '$.a') AS a
523+
FROM merge_t ORDER BY id;
524+
DROP TABLE merge_t;
525+
526+
SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '{"c":"d"}');
527+
SELECT JSON_MERGE_PATCH(NULL, '[1,2,3]');
528+
SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '[1,2,3]', '{"c":null,"d":"e"}');
529+
530+
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
531+
SELECT JSON_MERGE_PATCH();
532+
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
533+
SELECT JSON_MERGE_PATCH('{}');
534+
SELECT JSON_MERGE_PATCH('{', '[1,2,3]');
535+
SELECT JSON_MERGE_PATCH('{"a":"b"}', '[1,');
536+
494537
--echo #
495538
--echo # End of 10.2 tests
496539
--echo #

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,13 @@ select json_merge( '[1, 2]', '[3, 4' );
821821
json_merge( '[1, 2]', '[3, 4' )
822822
NULL
823823
Warnings:
824-
Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_merge'
824+
Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_merge_preserve'
825825
error ER_INVALID_JSON_TEXT_IN_PARAM
826826
select json_merge( '[1, 2', '[3, 4]' );
827827
json_merge( '[1, 2', '[3, 4]' )
828828
NULL
829829
Warnings:
830-
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_merge'
830+
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_merge_preserve'
831831
select json_merge( '1', '2' );
832832
json_merge( '1', '2' )
833833
[1, 2]

mysql-test/suite/plugins/r/feedback_plugin_load.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ select plugin_status from information_schema.plugins where plugin_name='feedback
22
plugin_status
33
ACTIVE
44
SELECT variable_value INTO @feedback_used FROM information_schema.feedback where variable_name = 'FEEDBACK used';
5-
SELECT variable_value = @feedback_used + 1 FROM information_schema.feedback where variable_name = 'FEEDBACK used';
6-
variable_value = @feedback_used + 1
7-
0
5+
SELECT variable_value = @feedback_used + 1 as 'MUST BE 1' FROM information_schema.feedback where variable_name = 'FEEDBACK used';
6+
MUST BE 1
7+
1
88
select * from information_schema.feedback where variable_name like 'feed%'
99
and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used'
1010
and variable_name not like '%debug%';

mysql-test/suite/plugins/t/feedback_plugin_load.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ select plugin_status from information_schema.plugins where plugin_name='feedback
1717
SELECT variable_value INTO @feedback_used FROM information_schema.feedback where variable_name = 'FEEDBACK used';
1818

1919
# Now $feedback_used == X+1, and 'FEEDBACK used' is also X+1. And variable_value is increased again when we run the next SELECT
20-
SELECT variable_value = @feedback_used + 1 FROM information_schema.feedback where variable_name = 'FEEDBACK used';
20+
SELECT variable_value = @feedback_used + 1 as 'MUST BE 1' FROM information_schema.feedback where variable_name = 'FEEDBACK used';
2121

2222
# Now when we are happy with 'FEEDBACK used', we can check everything else
2323

sql/item_create.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,19 @@ class Create_func_json_merge : public Create_native_func
19821982
};
19831983

19841984

1985+
class Create_func_json_merge_patch : public Create_native_func
1986+
{
1987+
public:
1988+
virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1989+
1990+
static Create_func_json_merge_patch s_singleton;
1991+
1992+
protected:
1993+
Create_func_json_merge_patch() {}
1994+
virtual ~Create_func_json_merge_patch() {}
1995+
};
1996+
1997+
19851998
class Create_func_json_quote : public Create_func_arg1
19861999
{
19872000
public:
@@ -5514,6 +5527,30 @@ Create_func_json_merge::create_native(THD *thd, LEX_CSTRING *name,
55145527
}
55155528

55165529

5530+
Create_func_json_merge_patch Create_func_json_merge_patch::s_singleton;
5531+
5532+
Item*
5533+
Create_func_json_merge_patch::create_native(THD *thd, LEX_CSTRING *name,
5534+
List<Item> *item_list)
5535+
{
5536+
Item *func;
5537+
int arg_count;
5538+
5539+
if (item_list == NULL ||
5540+
(arg_count= item_list->elements) < 2) // json, json
5541+
{
5542+
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
5543+
func= NULL;
5544+
}
5545+
else
5546+
{
5547+
func= new (thd->mem_root) Item_func_json_merge_patch(thd, *item_list);
5548+
}
5549+
5550+
return func;
5551+
}
5552+
5553+
55175554
Create_func_json_contains Create_func_json_contains::s_singleton;
55185555

55195556
Item*
@@ -7108,6 +7145,8 @@ static Native_func_registry func_array[] =
71087145
{ { STRING_WITH_LEN("JSON_LENGTH") }, BUILDER(Create_func_json_length)},
71097146
{ { STRING_WITH_LEN("JSON_LOOSE") }, BUILDER(Create_func_json_loose)},
71107147
{ { STRING_WITH_LEN("JSON_MERGE") }, BUILDER(Create_func_json_merge)},
7148+
{ { STRING_WITH_LEN("JSON_MERGE_PATCH") }, BUILDER(Create_func_json_merge_patch)},
7149+
{ { STRING_WITH_LEN("JSON_MERGE_PRESERVE") }, BUILDER(Create_func_json_merge)},
71117150
{ { STRING_WITH_LEN("JSON_QUERY") }, BUILDER(Create_func_json_query)},
71127151
{ { STRING_WITH_LEN("JSON_QUOTE") }, BUILDER(Create_func_json_quote)},
71137152
{ { STRING_WITH_LEN("JSON_OBJECT") }, BUILDER(Create_func_json_object)},

0 commit comments

Comments
 (0)