forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.slt
602 lines (462 loc) · 14 KB
/
map.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
mode cockroach
# The MAP type has an uncommon OID. If tokio-postres (the driver used
# by sqllogictest) encounters an OID it doesn't recognize (MAP in
# this case), then it queries pg_type (a wrapper around mz_types) for
# information about it. Our MAP type currently doesn't have an entry in
# mz_types, so that query fails and tokio-postgres is unable to execute
# queries with MAPs. As a workaround until MAP is reflected in pg_type,
# we just convert everything to `text`.
# Test basic string to map casts.
query error value_type parameter required
CREATE TYPE custom AS MAP (key_type=text)
query error key_type parameter required
CREATE TYPE custom AS MAP (value_type=bool)
query error unknown catalog item 'customthing'
CREATE TYPE custom AS MAP (key_type=text, value_type=bool, extra_type=customthing)
query error key_type must be of class type, but received pg_catalog.pg_enum which is of class view
CREATE TYPE tbl_map AS MAP (key_type=pg_enum, value_type=text)
query error value_type must be of class type, but received pg_catalog.pg_enum which is of class view
CREATE TYPE tbl_map AS MAP (key_type=text, value_type=pg_enum)
query error CREATE TYPE ... AS MAP option "value_type" cannot accept type modifier on numeric, you must use the default type
CREATE TYPE typ_mod_map AS MAP (key_type=text, value_type=numeric(38,0))
query error CREATE TYPE ... AS LIST option "value_type" can only use named data types, but found unnamed data type int4 list. Use CREATE TYPE to create a named type first
CREATE TYPE unnamed_element_map AS MAP (key_type=text, value_type=int4 list)
query error CREATE TYPE not yet supported
CREATE TYPE custom AS MAP (key_type=text, value_type=bool)
query error expected '\{', found a: "a=>1"
SELECT ('a=>1'::map[text=>int])::text
query T
SELECT ('{a=>1}'::map[text=>int])::text
----
{a=>1}
query T
SELECT ('{ c =>3, a=> 2, a => 1 }'::map[text=>int])::text
----
{a=>1,c=>3}
query error map key type must be text, got integer
SELECT '{1=>true}'::map[int=>bool]
query T
SELECT ('{1=>true}'::map[text=>bool])::text
----
{1=>t}
query T
SELECT ('{}'::map[text=>int])::text
----
{}
query error invalid input syntax for type boolean: "2.0"
SELECT ('{a=>1, b=>false, c=>2.0}'::map[text=>bool])::text
query T
SELECT ('{a\=\>=>2}'::map[text=>int])::text
----
{"a=>"=>2}
query T
SELECT ('{13=>hello \[\=\> value\], 31=> normal }'::map[text=>text])::text
----
{13=>"hello [=> value]",31=>normal}
query T
SELECT ('{"a"=>"hello there!", b=>"129387123"}'::map[text=>text])::text
----
{a=>"hello there!",b=>129387123}
query T
SELECT ('{key=>"here is a string => with a map operator in it"}'::map[text=>text])::text
----
{key=>"here is a string => with a map operator in it"}
query T
SELECT ('{31=> normal \ }'::map[text=>text])::text
----
{31=>"normal "}
query T
SELECT ('{31=> \ normal }'::map[text=>text])::text
----
{31=>" normal"}
query error unterminated quoted string
SELECT ('{"a"=>"hello there!}'::map[text=>text])::text
### Can be cast back to text
query T
SELECT '{a=>1}'::map[text=>int]::text
----
{a=>1}
## Nested maps
query error expected '\{', found a: "a": "\{a=>a\}"
SELECT (('{a=>a}'::map[text=>map[text=>text]])::text)::text
query error expected =>: "\{a\}": "\{a=>\{a\}\}"
SELECT ('{a=>{a}}'::map[text=>map[text=>text]])::text
query error expected '\{', found b: "b": "\{a=>\{a=>a\}, b=>b\}"
SELECT ('{a=>{a=>a}, b=>b}'::map[text=>map[text=>text]])::text
query error unterminated embedded element
SELECT ('{hello=>{world=>broken'::map[text=>map[text=>text]])::text
query error unescaped '\{' at beginning of value; perhaps you want a nested map
SELECT ('{hello=>{world=>true}}'::map[text=>bool])::text
query T
SELECT ('{hello=>{world=>nested}}'::map[text=>map[text=>text]])::text
----
{hello=>{world=>nested}}
query error map key type must be text, got integer
SELECT '{hello=>{1=>false}}'::map[text=>map[int=>bool]]
query T
SELECT ('{hello=>{world=>"2020-11-23"}}'::map[text=>map[text=>timestamp]])::text
----
{hello=>{world=>"2020-11-23 00:00:00"}}
query T
SELECT ('{hello=>{\{\}=>\"\"}}'::map[text=>map[text=>text]])::text
----
{hello=>{"{}"=>"\"\""}}
# Test map operators.
## ?
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ? 'a'
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ? 'b'
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ? 'c'
----
false
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] ? 1
query T
SELECT '{a=>1}'::map[text=>int] ? ''
----
false
query T
SELECT '{""=>1}'::map[text=>int] ? ''
----
true
query T
SELECT '{hello=>{world=>false}}'::map[text=>map[text=>bool]] -> 'hello'::text ? 'world'::text
----
true
## ?&
query error malformed array literal: missing opening left brace
SELECT '{a=>1, b=>2}'::map[text=>int] ?& 'a'
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY[1]
query error cannot determine type of empty array
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY[]
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY[NULL]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?& '{a}'
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY['a']
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY['b', 'a']
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?& ARRAY['c', 'b']
----
false
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?& ARRAY[1]
query T
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?& ARRAY['1']
----
true
query T
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?& ARRAY['']
----
false
query T
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?& ARRAY['']
----
false
query T
SELECT '{hello=>{world=>123.40}}'::map[text=>map[text=>double]] -> 'hello'::text ?& ARRAY['world']
----
true
query T
SELECT '{hello=>{world=>1293}}'::map[text=>map[text=>smallint]] -> 'hello'::text ?& ARRAY['world', 'extra']
----
false
## ?|
query error malformed array literal: missing opening left brace
SELECT '{a=>1, b=>2}'::map[text=>int] ?| 'a'
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] ?| ARRAY[1]
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?| ARRAY[NULL]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?| '{a}'
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?| ARRAY['a']
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?| ARRAY['c', 'b']
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] ?| ARRAY['c', 'd', '1']
----
false
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?| ARRAY[1]
query T
SELECT '{1=>t, 2=>f}'::map[text=>bool] ?| ARRAY['1']
----
true
query T
SELECT '{hello=>{world=>63616665-6630-3064-6465-616462656568}}'::map[text=>map[text=>uuid]] -> 'hello'::text ?| ARRAY['world', 'extra']
----
true
query T
SELECT '{hello=>{world=>"2020-11-23"}}'::map[text=>map[text=>date]] -> 'hello'::text ?| ARRAY['missing']
----
false
## @>
query error invalid input syntax for type map: expected '\{', found c: "c"
SELECT '{a=>1, b=>2}'::map[text=>int] @> 'c'
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] @> 'a'::text
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] @> ARRAY[1]
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit cast
SELECT '{a=>1, b=>2}'::map[text=>int] @> '{a=>t}'::map[text=>bool]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] @> '{a=>1}'::map[text=>int]
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] @> '{a=>1, b=>2}'::map[text=>int]
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] @> '{a=>10, b=>20}'::map[text=>int]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] @> '{a=>1, b=>2, c=>3}'::map[text=>int]
----
false
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT '{hello=>{world=>nested}}'::map[text=>map[text=>bytea]] @> '{hello=>world}'::map[text=>text]
----
false
query T
SELECT '{hello=>{world=>nested}}'::map[text=>map[text=>text]] @> '{hello=>{world=>nested}}'::map[text=>map[text=>text]]
----
true
query T
SELECT '{hello=>{world=>nested}}'::map[text=>map[text=>text]] @> '{hello=>{world=>nested}, extra=>{elements=>here}}'::map[text=>map[text=>text]]
----
false
## <@
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT '{a=>1, b=>2}'::map[text=>int] <@ '{a=>t}'::map[text=>bool]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] <@ '{a=>1}'::map[text=>int]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] <@ '{a=>1, b=>2}'::map[text=>int]
----
true
query T
SELECT '{a=>1, b=>2}'::map[text=>int] <@ '{a=>10, b=>20}'::map[text=>int]
----
false
query T
SELECT '{a=>1, b=>2}'::map[text=>int] <@ '{a=>1, b=>2, c=>3}'::map[text=>int]
----
true
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT '{hello=>{world=>a}}'::map[text=>map[text=>char]] <@ '{hello=>c}'::map[text=>char]
----
false
query T
SELECT '{hello=>{world=>16}}'::map[text=>map[text=>oid]] <@ '{hello=>{world=>16}}'::map[text=>map[text=>oid]]
----
true
query T
SELECT '{hello=>{world=>nested}}'::map[text=>map[text=>text]] <@ '{hello=>{world=>nested}, extra=>{elements=>here}}'::map[text=>map[text=>text]]
----
true
## ->
query T
SELECT '{a=>1, b=>2}'::map[text=>int] -> ''
----
NULL
query T
SELECT '{a=>1, b=>2}'::map[text=>int] -> 'a'
----
1
query T
SELECT '{a=>1, b=>2}'::map[text=>int] -> 'b'
----
2
query T
SELECT '{a=>1, b=>2}'::map[text=>int] -> 'c'
----
NULL
query error arguments cannot be implicitly cast to any implementation's parameters
SELECT '{a=>1, b=>2}'::map[text=>int] -> 1
query T
SELECT '{a=>true, b=>false}'::map[text=>bool] -> 'b'
----
false
query T
SELECT ('{a=>true, b=>false}'::map[text=>bool] -> ARRAY[]::text[])::text
----
{}
query T
SELECT ('{a=>true, b=>false}'::map[text=>bool] -> ARRAY['']::text[])::text
----
{NULL}
query T
SELECT ('{a=>1, b=>2}'::map[text=>int] -> ARRAY['a'])::text
----
{1}
query T
SELECT ('{a=>1, b=>2}'::map[text=>int] -> ARRAY['b', 'a'])::text
----
{2,1}
query T
SELECT ('{a=>1, b=>2}'::map[text=>int] -> ARRAY['b', 'a', 'c'])::text
----
{2,1,NULL}
query T
SELECT ('{hello=>{world=>nested}, another=>{map=>here}}'::map[text=>map[text=>text]] -> 'missing'::text)::text
----
NULL
query T
SELECT ('{hello=>{world=>nested}, another=>{map=>here}}'::map[text=>map[text=>text]] -> 'hello'::text)::text
----
{world=>nested}
query T
SELECT '{hello=>{world=>nested}, another=>{map=>here}}'::map[text=>map[text=>text]] -> 'hello'::text -> 'world'::text
----
nested
# 🔬 CREATE TYPE .. AS MAP
statement ok
CREATE TYPE int4_map AS MAP (key_type=text, value_type=int4);
query T
SELECT '{a=>1,b=>2}'::int4_map::text;
----
{a=>1,b=>2}
query T
SELECT pg_typeof(NULL::int4_map);
----
int4_map
# 🔬🔬 Check each valid value type
statement ok
CREATE TYPE bool_map_c AS MAP (key_type=text, value_type=bool);
query T
SELECT '{a=>true}'::bool_map_c::text
----
{a=>t}
statement ok
CREATE TYPE int8_map_c AS MAP (key_type=text, value_type=int8);
query T
SELECT '{a=>1}'::int8_map_c::text
----
{a=>1}
statement ok
CREATE TYPE int4_map_c AS MAP (key_type=text, value_type=int4);
query T
SELECT '{a=>1}'::int4_map_c::text
----
{a=>1}
statement ok
CREATE TYPE text_map_c AS MAP (key_type=text, value_type=text);
query T
SELECT '{a=>a}'::text_map_c::text
----
{a=>a}
statement ok
CREATE TYPE float4_map_c AS MAP (key_type=text, value_type=float4);
query T
SELECT '{a=>1.2}'::float4_map_c::text
----
{a=>1.2}
statement ok
CREATE TYPE float8_map_c AS MAP (key_type=text, value_type=float8);
query T
SELECT '{a=>1.2}'::float8_map_c::text
----
{a=>1.2}
statement ok
CREATE TYPE date_map_c AS MAP (key_type=text, value_type=date);
query T
SELECT '{a=>2001-01-01}'::date_map_c::text
----
{a=>2001-01-01}
statement ok
CREATE TYPE time_map_c AS MAP (key_type=text, value_type=time);
query T
SELECT '{a=>12:34:56}'::time_map_c::text
----
{a=>12:34:56}
statement ok
CREATE TYPE timestamp_map_c AS MAP (key_type=text, value_type=timestamp);
query T
SELECT '{a=>2001-01-01 12:34:56}'::timestamp_map_c::text
----
{a=>"2001-01-01 12:34:56"}
statement ok
CREATE TYPE timestamptz_map_c AS MAP (key_type=text, value_type=timestamptz);
query T
SELECT '{a=>2001-01-01 12:34:56}'::timestamptz_map_c::text
----
{a=>"2001-01-01 12:34:56+00"}
statement ok
CREATE TYPE interval_map_c AS MAP (key_type=text, value_type=interval);
query T
SELECT '{a=>1y 2d 3h 4m}'::interval_map_c::text
----
{a=>"1 year 2 days 03:04:00"}
statement ok
CREATE TYPE numeric_map_c AS MAP (key_type=text, value_type=numeric);
query T
SELECT '{a=>1.23}'::numeric_map_c::text
----
{a=>1.23}
statement ok
CREATE TYPE jsonb_map_c AS MAP (key_type=text, value_type=jsonb);
query T
SELECT '{a=>\{\"1\":2\}}'::jsonb_map_c::text;
----
{a=>"{\"1\":2}"}
# 🔬🔬 Check custom type name resolution
statement ok
CREATE TYPE bool AS MAP (key_type=text, value_type=int4)
query error invalid input syntax for type boolean: "\{a=>1\}"
SELECT '{a=>1}'::bool;
query T
SELECT '{a=>1}'::public.bool::text;
----
{a=>1}
# 🔬🔬 Check subtype resolution
# Supports qualified subtypes
statement ok
CREATE TYPE qualified_int4_map AS MAP (key_type=pg_catalog.text, value_type=pg_catalog.int4)
statement ok
CREATE TYPE qualified_qualified_int4_map AS MAP (key_type=pg_catalog.text, value_type=public.qualified_int4_map)
# Supports type aliases
statement ok
CREATE TYPE int_map AS MAP (key_type=pg_catalog.text, value_type=int)