Debian Codegraph @

mysql-test/suite/x/r/crud_doc_expr_object.result

raw
1 RUN DROP SCHEMA IF EXISTS xtest
2
3 0 rows affected
4 RUN CREATE SCHEMA xtest
5
6 1 rows affected
7
8 command ok
9 Inserting object into collection
10 send Mysqlx.Crud.Insert {
11 collection {
12 name: "xcoll"
13 schema: "xtest"
14 }
15 data_model: DOCUMENT
16 row {
17 field {
18 type: OBJECT
19 object {
20 fld {
21 key: "_id"
22 value {
23 type: LITERAL
24 literal {
25 type: V_OCTETS
26 v_octets {
27 value: "1"
28 }
29 }
30 }
31 }
32 fld {
33 key: "first_name"
34 value {
35 type: LITERAL
36 literal {
37 type: V_OCTETS
38 v_octets {
39 value: "John"
40 }
41 }
42 }
43 }
44 fld {
45 key: "last_name"
46 value {
47 type: LITERAL
48 literal {
49 type: V_OCTETS
50 v_octets {
51 value: "Snow"
52 }
53 }
54 }
55 }
56 }
57 }
58 }
59 }
60
61
62 1 rows affected
63 RUN SELECT doc FROM xtest.xcoll
64 doc
65 {"_id": "1", "last_name": "Snow", "first_name": "John"}
66 0 rows affected
67 Selecting object from collection
68 send Mysqlx.Crud.Find {
69 collection {
70 name: "xcoll"
71 schema: "xtest"
72 }
73 data_model: DOCUMENT
74 projection {
75 source {
76 type: OBJECT
77 object {
78 fld {
79 key: "name"
80 value {
81 type: FUNC_CALL
82 function_call {
83 name {
84 name: "concat"
85 }
86 param {
87 type: IDENT
88 identifier {
89 document_path {
90 type: MEMBER
91 value: "first_name"
92 }
93 }
94 }
95 param {
96 type: LITERAL
97 literal {
98 type: V_OCTETS
99 v_octets {
100 value: " "
101 }
102 }
103 }
104 param {
105 type: IDENT
106 identifier {
107 document_path {
108 type: MEMBER
109 value: "last_name"
110 }
111 }
112 }
113 }
114 }
115 }
116 fld {
117 key: "number"
118 value {
119 type: OPERATOR
120 operator {
121 name: "+"
122 param {
123 type: LITERAL
124 literal {
125 type: V_SINT
126 v_signed_int: 1
127 }
128 }
129 param {
130 type: LITERAL
131 literal {
132 type: V_SINT
133 v_signed_int: 1
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141 }
142 }
143
144 doc
145 {"name": "John Snow", "number": 2}
146 command ok
147 Selecting object from collection with alias
148 send Mysqlx.Crud.Find {
149 collection {
150 name: "xcoll"
151 schema: "xtest"
152 }
153 data_model: DOCUMENT
154 projection {
155 source {
156 type: OBJECT
157 object {
158 fld {
159 key: "name"
160 value {
161 type: FUNC_CALL
162 function_call {
163 name {
164 name: "concat"
165 }
166 param {
167 type: IDENT
168 identifier {
169 document_path {
170 type: MEMBER
171 value: "first_name"
172 }
173 }
174 }
175 param {
176 type: LITERAL
177 literal {
178 type: V_OCTETS
179 v_octets {
180 value: " "
181 }
182 }
183 }
184 param {
185 type: IDENT
186 identifier {
187 document_path {
188 type: MEMBER
189 value: "last_name"
190 }
191 }
192 }
193 }
194 }
195 }
196 }
197 }
198 alias: "hero"
199 }
200 }
201
202 doc
203 {"hero": {"name": "John Snow"}}
204 command ok
205 Selecting object with sub-object from collection
206 send Mysqlx.Crud.Find {
207 collection {
208 name: "xcoll"
209 schema: "xtest"
210 }
211 data_model: DOCUMENT
212 projection {
213 source {
214 type: OBJECT
215 object {
216 fld {
217 key: "name"
218 value {
219 type: FUNC_CALL
220 function_call {
221 name {
222 name: "concat"
223 }
224 param {
225 type: IDENT
226 identifier {
227 document_path {
228 type: MEMBER
229 value: "first_name"
230 }
231 }
232 }
233 param {
234 type: LITERAL
235 literal {
236 type: V_OCTETS
237 v_octets {
238 value: " "
239 }
240 }
241 }
242 param {
243 type: IDENT
244 identifier {
245 document_path {
246 type: MEMBER
247 value: "last_name"
248 }
249 }
250 }
251 }
252 }
253 }
254 fld {
255 key: "detail"
256 value {
257 type: OBJECT
258 object {
259 fld {
260 key: "first"
261 value {
262 type: IDENT
263 identifier {
264 document_path {
265 type: MEMBER
266 value: "first_name"
267 }
268 }
269 }
270 }
271 fld {
272 key: "last"
273 value {
274 type: IDENT
275 identifier {
276 document_path {
277 type: MEMBER
278 value: "last_name"
279 }
280 }
281 }
282 }
283 }
284 }
285 }
286 }
287 }
288 }
289 }
290
291 doc
292 {"name": "John Snow", "detail": {"last": "Snow", "first": "John"}}
293 command ok
294 Updating collection by object
295 send Mysqlx.Crud.Update {
296 collection {
297 name: "xcoll"
298 schema: "xtest"
299 }
300 data_model: DOCUMENT
301 operation {
302 source {
303 document_path {
304 type: MEMBER
305 value: "occupation"
306 }
307 }
308 operation: ITEM_SET
309 value {
310 type: OBJECT
311 object {
312 fld {
313 key: "location"
314 value {
315 type: LITERAL
316 literal {
317 type: V_OCTETS
318 v_octets {
319 value: "the wall"
320 }
321 }
322 }
323 }
324 fld {
325 key: "title"
326 value {
327 type: LITERAL
328 literal {
329 type: V_OCTETS
330 v_octets {
331 value: "lord commander"
332 }
333 }
334 }
335 }
336 }
337 }
338 }
339 }
340
341
342 1 rows affected
343 Rows matched: 1 Changed: 1 Warnings: 0
344 RUN SELECT doc FROM xtest.xcoll
345 doc
346 {"_id": "1", "last_name": "Snow", "first_name": "John", "occupation": {"title": "lord commander", "location": "the wall"}}
347 0 rows affected
348 NOT Error: empty object
349 send Mysqlx.Crud.Find {
350 collection {
351 name: "xcoll"
352 schema: "xtest"
353 }
354 data_model: DOCUMENT
355 projection {
356 source {
357 type: OBJECT
358 object {
359 }
360 }
361 }
362 }
363
364 doc
365 {}
366 command ok
367 Error: empty object key
368 send Mysqlx.Crud.Find {
369 collection {
370 name: "xcoll"
371 schema: "xtest"
372 }
373 data_model: DOCUMENT
374 projection {
375 source {
376 type: OBJECT
377 object {
378 fld {
379 key: ""
380 value {
381 type: IDENT
382 identifier {
383 document_path {
384 type: MEMBER
385 value: "first_name"
386 }
387 }
388 }
389 }
390 }
391 }
392 }
393 }
394
395 Got expected error:
396 Mysqlx.Error {
397 severity: ERROR
398 code: 5154
399 msg: "Invalid key for Mysqlx::Expr::Object"
400 sql_state: "HY000"
401 }
402
403 RUN drop schema if exists xtest
404
405 1 rows affected
406 Mysqlx.Ok {
407 msg: "bye!"
408 }
409 ok