Debian Codegraph @

mysql-test/suite/x/t/crud_update_merge_patch.test

raw
1 #
2 # Functional tests of WL#10797 - mysqlx.crud.Modify: MERGE_PATCH
3 #
4 --source include/xplugin_preamble.inc
5 --source include/xplugin_create_user.inc
6
7 ## Test data
8 CREATE SCHEMA xtest;
9
10 ## Test starts here
11 --write_file $MYSQL_TMP_DIR/crud_update_merge.xpl
12 -->macro_delimiter_compress false
13 import crud.macro;
14 import crud_update.macro;
15 import crud_insert.macro;
16 import crud_find.macro;
17 import crud_delete.macro;
18 import %TABLE_SPECIFIC_OPERATIONS%;
19
20
21 -->macro Set_field_sint %FIELDS% %NAME% %VALUE%
22 -->varlet %FIELDS% %FIELDS% fld {
23 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
24 -->varlet %FIELDS% %FIELDS% value {
25 -->varlet %FIELDS% %FIELDS% type: LITERAL literal {
26 -->varlet %FIELDS% %FIELDS% type:V_SINT v_signed_int: %VALUE% }}}
27 -->endmacro
28
29
30 -->macro Set_field_string %FIELDS% %NAME% %VALUE%
31 -->varlet %FIELDS% %FIELDS% fld {
32 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
33 -->varlet %FIELDS% %FIELDS% value {
34 -->varlet %FIELDS% %FIELDS% type: LITERAL literal {
35 -->varlet %FIELDS% %FIELDS% type:V_OCTETS v_octets { value: %VALUE% }}}}
36 -->endmacro
37
38
39 -->macro Set_field_doc_member %FIELDS% %NAME% %MEMBER%
40 -->varlet %FIELDS% %FIELDS% fld {
41 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
42 -->varlet %FIELDS% %FIELDS% value {
43 -->varlet %FIELDS% %FIELDS% type: IDENT identifier {
44 -->varlet %FIELDS% %FIELDS% document_path {type:MEMBER value: %MEMBER% }}}}
45 -->endmacro
46
47 -->macro Set_field_ident %FIELDS% %NAME% %IDENT%
48 -->varlet %FIELDS% %FIELDS% fld {
49 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
50 -->varlet %FIELDS% %FIELDS% value {
51 -->varlet %FIELDS% %FIELDS% type: IDENT identifier {
52 -->varlet %FIELDS% %FIELDS% %IDENT% }}}
53 -->endmacro
54
55
56 -->macro Set_field_literal %FIELDS% %NAME% %LITERAL%
57 -->varlet %FIELDS% %FIELDS% fld {
58 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
59 -->varlet %FIELDS% %FIELDS% value {
60 -->varlet %FIELDS% %FIELDS% type: LITERAL literal {
61 -->varlet %FIELDS% %FIELDS% %LITERAL% }}}
62 -->endmacro
63
64
65 -->macro Set_field_function %FIELDS% %NAME% %FUNC% %ARGS%
66 -->varlet %FIELDS% %FIELDS% fld {
67 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
68 -->varlet %FIELDS% %FIELDS% value {
69 -->varlet %FIELDS% %FIELDS% type: FUNC_CALL function_call {
70 -->varlet %FIELDS% %FIELDS% name{ name: %FUNC% } %ARGS%}}}
71 -->endmacro
72
73 -->macro Set_field_expr_literal_plus_member_value %FIELDS% %NAME% %LITERAL% %MEMBER%
74 -->varlet %FIELDS% %FIELDS% fld {
75 -->varlet %FIELDS% %FIELDS% key:"%NAME%"
76 -->varlet %FIELDS% %FIELDS% value {
77 -->varlet %FIELDS% %FIELDS% type: OPERATOR operator {
78 -->varlet %FIELDS% %FIELDS% name:"+"
79 -->varlet %FIELDS% %FIELDS% param { type: LITERAL
80 -->varlet %FIELDS% %FIELDS% literal{
81 -->varlet %FIELDS% %FIELDS% type:V_SINT v_signed_int: %LITERAL%
82 -->varlet %FIELDS% %FIELDS% }}
83 -->varlet %FIELDS% %FIELDS% param { type: IDENT
84 -->varlet %FIELDS% %FIELDS% identifier {
85 -->varlet %FIELDS% %FIELDS% document_path {
86 -->varlet %FIELDS% %FIELDS% type: MEMBER
87 -->varlet %FIELDS% %FIELDS% value: %MEMBER%
88 -->varlet %FIELDS% %FIELDS% }}}
89 -->varlet %FIELDS% %FIELDS% }}}
90 -->endmacro
91
92
93 callmacro Setup_Schema;
94
95 title ## Implementations of test-cases from RFC 7396;
96 echo # It covers requirements from the worklog:;
97 echo # * F3 - Must allow deletion of a field;
98 echo # * F4 - Must allow setting the value of a field to;
99 echo # a literal value;
100 echo # * F6 - Must allow above operations to be performed on nested documents;
101
102 #
103 # macro Document_UpdatePatch_Find is going to execute following
104 # operations in sequence:
105 #
106 # * Insert argument 2 (document) into to collection/table (argument 1 is expected error on this operation)
107 # * Execute update with merge-patch taken from argument 3
108 # * Execute a select on collection/table and comapre the result to argument 4
109 #
110 callmacro Document_UpdatePatch_Find
111 ER_SUCCESS
112 {"a": "b", "_id": 1}
113 {"a": "c"}
114 {"a": "c", "_id": 1};
115
116 callmacro Document_UpdatePatch_Find
117 ER_SUCCESS
118 {"a": "b", "_id": 1}
119 {"b": "c"}
120 {"a": "b", "b": "c", "_id": 1};
121
122 callmacro Document_UpdatePatch_Find
123 ER_SUCCESS
124 {"a": "b", "_id": 1}
125 {"a": null}
126 {"_id": 1};
127
128 callmacro Document_UpdatePatch_Find
129 ER_SUCCESS
130 {"a": "b", "b":"c", "_id": 1}
131 {"a": null}
132 {"b": "c", "_id": 1};
133
134 callmacro Document_UpdatePatch_Find
135 ER_SUCCESS
136 {"a": ["b"], "_id": 1}
137 {"a": "c"}
138 {"a": "c", "_id": 1};
139
140 callmacro Document_UpdatePatch_Find
141 ER_SUCCESS
142 {"a": "c", "_id": 1}
143 {"a": ["b"]}
144 {"a": ["b"], "_id": 1};
145
146 callmacro Document_UpdatePatch_Find
147 ER_SUCCESS
148 {"a": {"b":"c"}, "_id": 1}
149 {"a": {"b":"d", "c": null}}
150 {"a": {"b": "d"}, "_id": 1};
151
152 callmacro Document_UpdatePatch_Find
153 ER_SUCCESS
154 {"a": [{"b": "c"}], "_id": 1}
155 {"a": [1]}
156 {"a": [1], "_id": 1};
157
158 callmacro Document_OnlyTable_UpdatePatch_Find
159 ER_SUCCESS
160 ["a", "b"]
161 ["c", "d"]
162 ["c", "d"];
163
164 callmacro DocumentProtobuf_OnlyTable_UpdatePatch_Find
165 ER_SUCCESS
166 {type: V_NULL}
167 ["c", "d"]
168 ["c", "d"];
169
170 callmacro Document_OnlyTable_UpdatePatch_Find
171 ER_SUCCESS
172 {}
173 ["c", "d"]
174 ["c", "d"];
175
176 callmacro Document_UpdatePatch_Find
177 %NO_SUPPORTED_ON_COLLECTION%
178 {"a": "foo", "_id": 1}
179 ["c"]
180 %RESULT_PATCH_ARRAY%;
181
182 callmacro Document_UpdatePatch_Find
183 ER_SUCCESS
184 {"a": "foo", "_id": 1}
185 {"_id": "foo"}
186 %RESULT_PATCH_ID%;
187
188
189 callmacro Document_UpdatePatch_Find
190 %NO_SUPPORTED_ON_COLLECTION%
191 {"a": "foo", "_id": 1}
192 null
193 %RESULT_PATCH_NULL%;
194
195 callmacro Document_UpdatePatch_Find
196 %NO_SUPPORTED_ON_COLLECTION%
197 {"a": "foo", "_id": 1}
198 "bar"
199 %RESULT_PATCH_STRING%;
200
201 callmacro Document_UpdatePatch_Find
202 ER_SUCCESS
203 {"e": null, "_id": 1}
204 {"a": 1}
205 {"a": 1, "e": null, "_id": 1};
206
207 callmacro Document_OnlyTable_UpdatePatch_Find
208 ER_SUCCESS
209 [1, 2]
210 {"a": "b","c": null}
211 {"a": "b"};
212
213 callmacro Document_UpdatePatch_Find
214 ER_SUCCESS
215 {"_id": 1}
216 {"a": "b", "c": null}
217 {"a": "b", "_id": 1};
218
219 callmacro Document_UpdatePatch_Find
220 ER_SUCCESS
221 {"_id": 1}
222 {"a": {"bb": {"ccc": null}}}
223 {"a": {"bb": {}}, "_id": 1};
224
225 #
226 # Requirement:
227 # * F1 - Must accept changes to be applied to matching documents of a collection
228 # in the form of a "patch" object, similar to a JSON object
229 varlet %PROTOBUF_FIELDS% ;
230 callmacro Set_field_sint %PROTOBUF_FIELDS% my_value_as_int 10;
231 callmacro Set_field_string %PROTOBUF_FIELDS% my_value_as_string "ten";
232 callmacro Document_UpdatePatchObj_Find
233 ER_SUCCESS
234 {"_id": 1}
235 %PROTOBUF_FIELDS%
236 {"_id": 1, "my_value_as_int": 10, "my_value_as_string": "ten"};
237
238 #
239 # Requirement:
240 # * F5 - Must allow setting the value of a field to the result of an expression
241 varlet %PROTOBUF_FIELDS% ;
242 callmacro Set_field_sint %PROTOBUF_FIELDS% b 10;
243 callmacro Set_field_expr_literal_plus_member_value %PROTOBUF_FIELDS% c 20 "a";
244 callmacro Document_UpdatePatchObj_Find
245 ER_SUCCESS
246 {"a":20, "_id": 1}
247 %PROTOBUF_FIELDS%
248 {"a": 20, "b": 10, "c": 40.0, "_id": 1};
249
250
251 #
252 # Rename field
253 #
254 varlet %PROTOBUF_FIELDS% ;
255 callmacro Set_field_doc_member %PROTOBUF_FIELDS% new_field_name "old_field_name";
256 callmacro Set_field_literal %PROTOBUF_FIELDS% old_field_name type: V_NULL;
257 callmacro Document_UpdatePatchObj_Find
258 ER_SUCCESS
259 {"_id": 1, "old_field_name": {"field": "fields value"}, "other_fields": {"a": 1}}
260 %PROTOBUF_FIELDS%
261 {"_id": 1, "other_fields": {"a": 1}, "new_field_name": {"field": "fields value"}};
262
263
264 #
265 # Get nested document using expression
266 # "a.[1].c
267 #
268 varlet %PROTOBUF_FIELDS% ;
269 callmacro Set_field_ident %PROTOBUF_FIELDS% new_field
270 document_path {type:MEMBER value: "a" } document_path {type:ARRAY_INDEX index: 1 } document_path {type:MEMBER value: "c" };
271 callmacro Document_UpdatePatchObj_Find
272 ER_SUCCESS
273 {"_id": 1, "a": [100, {"c": "nested_value"}, 4]}
274 %PROTOBUF_FIELDS%
275 {"a": [100, {"c": "nested_value"}, 4], "_id": 1, "new_field": "nested_value"};
276
277 #
278 # Use function call
279 #
280 varlet %PROTOBUF_FIELDS% ;
281 callmacro Set_field_function %PROTOBUF_FIELDS% func_call1 "DATABASE" ;
282 callmacro Set_field_function %PROTOBUF_FIELDS% func_call2 "CONCAT"
283 param { type:LITERAL literal{type:V_OCTETS v_octets{value:"A"}}} param { type:LITERAL literal{type:V_OCTETS v_octets{value:"B"}}};
284 callmacro Document_UpdatePatchObj_Find
285 ER_SUCCESS
286 {"_id": 1, "old_field": true}
287 %PROTOBUF_FIELDS%
288 {"_id": 1, "old_field": true, "func_call1": "xtest", "func_call2": "AB"};
289
290 #
291 # Use patch on collection/tavle which
292 #
293 quiet;
294 noquery_result;
295 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 1, "should_be_updated": "yes"}';
296 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 2, "should_be_updated": "yes"}';
297 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 3, "should_be_updated": "no"}';
298 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 4, "should_be_updated": "no"}';
299 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 5, "should_be_updated": "no"}';
300 callmacro Crud_insert %OBJECT% 'xdoc' Row_octet '{"_id": 6, "should_be_updated": "yes"}';
301 recvresult;
302 recvresult;
303 recvresult;
304 recvresult;
305 recvresult;
306 recvresult;
307 query_result;
308 callmacro Crud_update
309 %OBJECT% 'xdoc'
310 Op_octets %OBJECT_COLUMN% MERGE_PATCH '{"new_field": 10}'
311 Where_field "should_be_updated" "yes";
312 recvresult;
313 noquiet;
314
315 #
316 # Compare with result file
317 #
318 callmacro Crud_find %OBJECT% 'xdoc';
319 recvresult;
320
321 EOF
322
323
324 --echo #
325 --echo # Requirement:
326 --echo # * F8 - Must work for collections
327 exec $MYSQLXTEST
328 --user=x_root
329 --password=''
330 --schema=xtest
331 -v%NO_SUPPORTED_ON_COLLECTION%=ER_X_DOC_ID_MISSING
332 -v%TABLE_SPECIFIC_OPERATIONS%=test_collection_create_update_find.macro
333 --file=$MYSQL_TMP_DIR/crud_update_merge.xpl 2>&1;
334
335 --echo #
336 --echo # Requirement:
337 --echo # * F10 - Must work for JSON document fields in tables
338 exec $MYSQLXTEST
339 --user=x_root
340 --password=''
341 --schema=xtest
342 -v%NO_SUPPORTED_ON_COLLECTION%=ER_SUCCESS
343 -v%TABLE_SPECIFIC_OPERATIONS%=test_table_create_update_find.macro
344 --file=$MYSQL_TMP_DIR/crud_update_merge.xpl 2>&1;
345
346 ## Cleanup
347 --source ../include/xplugin_cleanup.inc
348