forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring.slt
1386 lines (1117 loc) · 20.3 KB
/
string.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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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
### column names ###
query TTT colnames
SELECT length('a'), ascii('a'), substr('a', 1) LIMIT 0
----
length ascii substr
query T colnames
SELECT length(column1) FROM (VALUES ('a')) GROUP BY length(column1) LIMIT 0
----
length
query T colnames
SELECT column1::text FROM (VALUES ('a')) LIMIT 0
----
column1
### ascii ###
statement ok
CREATE TABLE asciitest (strcol CHAR(15), vccol VARCHAR(15))
# TODO: materialize#589 Add two tests:
# 1: empty string to each column
# 2: single space in each column
statement ok
INSERT INTO asciitest VALUES ('hello world', 'goodbye moon'), (NULL, NULL),
('你好', '再见'), ('😀', '👻')
statement error
SELECT ascii(98)
query II colnames
SELECT ascii(strcol) AS strres, ascii(vccol) AS vcres FROM asciitest ORDER BY strres
----
strres vcres
104 103
20320 20877
128512 128123
NULL NULL
query I
SELECT ascii(NULL)
----
NULL
query I
SELECT ascii(substr('inside literal', 3, 4))
----
115
### substr ###
statement ok
CREATE TABLE substrtest (strcol char(15), vccol varchar(15), smicol smallint, intcol int)
statement ok
INSERT INTO substrtest VALUES ('Mg', 'Mn', 1, 1), ('magnesium', 'manganese', 3, NULL),
(NULL, NULL, 0, 0), ('24.31', '54.94', 2, 3), ('长久不见', '爱不释手', NULL, 2),
('', '', -1, 2)
# invalid input
statement error
SELECT substr(192, 1, 1)
statement error
SELECT substr('from wrong type', 1.5, 2)
statement error
SELECT substr('for wrong type', 2, 1.5)
query error negative substring length not allowed
SELECT substr('for cannot be negative', 1, -3)
query error negative substring length not allowed
SELECT substr('for still cannot be negative', 30, -2)
# standard tests
# TODO: materialize#589 SELECT strcol FROM substrtest
query T colnames
SELECT substr(vccol, 1, 3) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.
Mn
man
爱不释
NULL
query T colnames
SELECT substr(vccol, 1, 5) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.94
Mn
manga
爱不释手
NULL
query T colnames
SELECT substr(vccol, 1) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.94
Mn
manganese
爱不释手
NULL
query T colnames
SELECT substr(vccol, 3) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
(empty)
.94
nganese
释手
NULL
query T colnames
SELECT substr(vccol, 3, 1) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
(empty)
.
n
释
NULL
# negative start position
query T colnames
SELECT substr(vccol, -1) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.94
Mn
manganese
爱不释手
NULL
query T colnames
SELECT substr(vccol, -2, 6) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.
Mn
man
爱不释
NULL
query T colnames
SELECT substr(vccol, -3, 5) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
5
M
m
爱
NULL
query TT colnames
SELECT substr(strcol, -4, 5) AS strres, substr(vccol, -4, 5) AS vcres FROM substrtest ORDER BY vcres
----
strres vcres
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
NULL NULL
query TT colnames
SELECT substr(strcol, -6, 6) AS strres, substr(vccol, -6, 6) AS vcres FROM substrtest ORDER BY vcres
----
strres vcres
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
NULL NULL
query TT colnames
SELECT substr(strcol, -5, 4) AS strres, substr(vccol, -5, 4) AS vcres FROM substrtest ORDER BY vcres
----
strres vcres
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
NULL NULL
# for or start is zero
query T colnames
SELECT substr(vccol, 0) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.94
Mn
manganese
爱不释手
NULL
query T colnames
SELECT substr(vccol, 0, 3) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54
Mn
ma
爱不
NULL
query TT colnames
SELECT substr(strcol, 0, 0) AS strres, substr(vccol, 0, 0) AS vcres FROM substrtest ORDER BY vcres
----
strres vcres
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
NULL NULL
query TT colnames
SELECT substr(strcol, 3, 0) AS strres, substr(vccol, 3, 0) AS vcres FROM substrtest ORDER BY vcres
----
strres vcres
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
(empty) (empty)
NULL NULL
# NULL inputs
query T
SELECT substr(NULL, 1)
----
NULL
query T
SELECT substr(NULL, 1, 3)
----
NULL
query T
SELECT substr('text string', NULL)
----
NULL
query T
SELECT substr(NULL, NULL)
----
NULL
query T
SELECT substr('foo', NULL, 3)
----
NULL
query T
SELECT substr('bar', NULL, NULL)
----
NULL
query T
SELECT substr('baz', 2, NULL)
----
NULL
query T
SELECT substr(NULL, NULL, NULL)
----
NULL
# alternative syntax
query T colnames
SELECT substring(vccol, 1, 3) AS vcres FROM substrtest ORDER BY vcres
----
vcres
(empty)
54.
Mn
man
爱不释
NULL
# testing different kinds of int columns and NULL content in columns
query T
SELECT substr(vccol, smicol, smicol) AS vcres FROM substrtest WHERE smicol > -1 ORDER BY vcres
----
4.
M
nga
NULL
query error negative substring length not allowed
SELECT substr(vccol, smicol, smicol) AS vcres FROM substrtest ORDER BY vcres
query T
SELECT substr(vccol, intcol, intcol) AS vcres FROM substrtest ORDER BY vcres
----
(empty)
.94
M
不释
NULL
NULL
query T
SELECT substr(vccol, smicol, intcol) AS vcres FROM substrtest ORDER BY vcres
----
(empty)
4.9
M
NULL
NULL
NULL
query T
SELECT substr(vccol, intcol, smicol) AS vcres FROM substrtest WHERE smicol > -1 ORDER BY vcres
----
.9
M
NULL
NULL
query T
SELECT substr('subexpression test', ascii(''), 3)
----
su
# testing large numbers
query T
SELECT substr('abcdef', 2, 2147483648);
----
bcdef
query T
SELECT substr('abcdef', 2147483648, 2);
----
(empty)
query T
SELECT substr('abcdef', 2147483648, 2147483648);
----
(empty)
# substring alternate syntax
query T
SELECT substring('abcdef' from 2)
----
bcdef
query T
SELECT substring('abcdef', 0, 3)
----
ab
query T
SELECT substring('abcdef', 1, 3)
----
abc
query T
SELECT substring('abcdef' for 3)
----
abc
query T
SELECT substring('abcdef', 3, 3);
----
cde
query T
SELECT substring('abcdef' from 3 for 3);
----
cde
# alternate syntax does not apply to substr
statement error
SELECT substr('abcdef' from 2)
statement error
SELECT substr('abcdef' for 3)
statement error
SELECT substr('abcdef' from 3 for 3)
# alternate syntax edge cases
query T
SELECT substring('abcdef' from -1);
----
abcdef
query T
SELECT substring('abcdef' from 2 for 2147483648);
----
bcdef
query T
SELECT substring('abcdef' from 2147483648 for 2);
----
(empty)
query T
SELECT substring('abcdef' from 2147483648 for 2147483648);
----
(empty)
query T
SELECT substring('abcdef' for 2147483648);
----
abcdef
statement error
SELECT substring('abcdef' for -1)
query T
SELECT substring('abcdef' from -1);
----
abcdef
query T
SELECT substring('abcdef' from -1 for 3);
----
a
### length ###
statement ok
CREATE TABLE lengthtest(strcol char(15), vccol varchar(15))
statement ok
INSERT INTO lengthtest VALUES
('str', 'str'), (' str', ' str'), ('str ', 'str '), ('你好', '你好'),
('今日は', '今日は'), ('हेलो', 'हेलो'),
(NULL, NULL), ('', '')
# invalid input
statement error
SELECT length(99)
statement error
SELECT length('str', 99)
# standard tests
query I rowsort
SELECT octet_length(strcol) FROM lengthtest
----
15
15
15
15
19
21
23
NULL
query I rowsort
SELECT length(vccol) FROM lengthtest
----
0
2
3
3
4
4
4
NULL
query I
SELECT length('你好', 'big5')
----
3
query I
SELECT length('你好', 'iso-8859-5')
----
6
query I
SELECT octet_length('你好');
----
6
query I
SELECT bit_length('你好');
----
48
# encoding name conversion FROM pg to WHATWG
query I
SELECT length('你好', 'ISO_8859_5')
----
6
query error invalid encoding name 'iso-123'
SELECT length('你好', 'iso-123')
# NULL inputs
query I
SELECT length(NULL)
----
NULL
query I
SELECT length('str', NULL)
----
NULL
query T
SELECT replace('one', 'one', 'two')
----
two
query T
SELECT replace('in a longer string', 'longer', 'shorter')
----
in a shorter string
query T
SELECT 'hello'::bytea::text
----
\x68656c6c6f
### concat ###
query T
SELECT concat('CONCAT', 'function')
----
CONCATfunction
query T
SELECT concat('CONCAT', ' ', 'function')
----
CONCAT function
query T
SELECT concat('CONCAT', NULL , 'function')
----
CONCATfunction
query I
SELECT length(concat(''))
----
0
query I
SELECT length(concat(NULL))
----
0
query I
SELECT length(concat(' '))
----
1
query T
SELECT concat('CONCAT', 3 , 'function')
----
CONCAT3function
query T
SELECT concat('CONCAT', length('abc') , 'function')
----
CONCAT3function
query T
SELECT concat(3.32::float)
----
3.32
query T
SELECT concat(3.32::double precision)
----
3.32
query T
SELECT concat(3.32::int)
----
3
query T
SELECT concat(3.32)
----
3.32
query T
SELECT concat(3.32::decimal, 3)
----
3.323
query T
SELECT concat(3.32::float, 3)
----
3.323
query T
SELECT concat(3.32::float, '3')
----
3.323
query T
SELECT concat(true, false, 'function')
----
tffunction
query T
SELECT concat('你好')
----
你好
query T
SELECT 'CONCAT' || 'operator'
----
CONCAToperator
query T
SELECT 'CONCAT' || ' ' || 'operator'
----
CONCAT operator
query T
SELECT 'CONCAT' || NULL
----
NULL
query T
SELECT NULL || 'CONCAT'
----
NULL
query I
SELECT length('' || '')
----
0
query I
SELECT length(NULL || NULL)
----
NULL
query I
SELECT length(' ' || ' ')
----
2
query T
SELECT 'CONCAT' || 3 || 'operator'
----
CONCAT3operator
query T
SELECT 'CONCAT' || length('abc') || 'operator'
----
CONCAT3operator
query T
SELECT '' || true || false
----
truefalse
query T
SELECT '你' || '好'
----
你好
query error no overload for boolean \|\| boolean
SELECT true || false
query T
SELECT split_part('abc~@~def~@~ghi', '~@~', 2)
----
def
query T
SELECT split_part('abc~@~def~@~ghi', '', 1)
----
abc~@~def~@~ghi
query T
SELECT split_part('abc~@~def~@~ghi', '~@~', 4)
----
(empty)
query T
SELECT split_part('hello there', '', 1)
----
hello there
query T
SELECT split_part('', 'not', 1)
----
(empty)
query error field position must be greater than zero
SELECT split_part('abc~@~def~@~ghi', '~@~', 0)
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT split_part()
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT split_part('one', 'two')
query error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT split_part(1, 2, 3)
### lpad ###
query T
SELECT lpad('str', 42, 'pad')
----
padpadpadpadpadpadpadpadpadpadpadpadpadstr
query T
SELECT lpad('str', 4, 'pad')
----
pstr
query T
SELECT lpad('str', 5, 'pad')
----
pastr
query T
SELECT REPLACE(lpad('str', 5), ' ', '_')
----
__str
query T
SELECT lpad('str', 7, 'pad')
----
padpstr
query T
SELECT lpad('str', 3, 'pad')
----
str
query T
SELECT lpad('str', 2, 'pad')
----
st
query T
SELECT lpad('str', 1, 'pad')
----
s
statement error
SELECT lpad('str', -1, 'pad')
query T
SELECT lpad('str', 0, 'pad')
----
(empty)
query T
SELECT lpad('str', NULL, 'pad')
----
NULL
query T
SELECT lpad(NULL, 10, 'pad')
----
NULL
query T
SELECT lpad(NULL, 10, NULL)
----
NULL
query T
SELECT lpad('str', 10, NULL)
----
NULL
query T
SELECT lpad('str', 10, '')
----
str
query T
SELECT lpad('', 10, '')
----
(empty)
query T
SELECT lpad('', 10, 'pad')
----
padpadpadp
query T
SELECT lpad('đẹp', 1, 'pad')
----
đ
query T
SELECT lpad('str', 5, 'đẹp')
----
đẹstr
### ilike ###
# ILIKE tests lifted from Cockroach
query B
SELECT 'TEST' ILIKE 'TEST'
----
true
query B
SELECT 'TEST' ILIKE 'test'
----
true
query B
SELECT 'TEST' ILIKE 'TE%'
----
true
query B
SELECT 'TEST' ILIKE '%E%'
----
true
query B
SELECT 'TEST' ILIKE '%e%'
----
true
query B
SELECT 'TEST' ILIKE 'TES_'
----
true
query B
SELECT 'TEST' ILIKE 'TE_%'
----
true
query B
SELECT 'TEST' ILIKE 'TE_'
----
false
query B
SELECT 'TEST' ILIKE '%'
----
true
query B
SELECT 'TEST' ILIKE '%R'
----
false
query B
SELECT 'TEST' ILIKE 'TESTER'
----
false
query B
SELECT 'TEST' ILIKE 'tester'
----
false
query B
SELECT 'TEST' ILIKE ''
----
false
query B
SELECT '' ILIKE ''
----
true
query B
SELECT 'T' ILIKE '_'
----
true
query B
SELECT 'TE' ILIKE '_'
----
false
query B
SELECT 'TEST' NOT ILIKE '%E%'
----
false
query B
SELECT 'TEST' NOT ILIKE 'TES_'
----
false
query B
SELECT 'TEST' NOT ILIKE 'TeS_'
----
false
query B
SELECT 'TEST' NOT ILIKE 'TE_'
----
true
# Invalid type mods
query error length for type character varying must be within \[1-10485760\], have 0
SELECT ''::VARCHAR(0)
query error length for type character varying must be within \[1-10485760\], have 10485761
SELECT ''::VARCHAR(10485761)
query error length for type character must be within \[1-10485760\], have 0
SELECT ''::CHAR(0)
query error length for type character must be within \[1-10485760\], have 10485761
SELECT ''::CHAR(10485761)
query error length for type character varying must be within \[1-10485760\], have 0
SELECT ''::pg_catalog.VARCHAR(0)
query error length for type character varying must be within \[1-10485760\], have 10485761
SELECT ''::pg_catalog.VARCHAR(10485761)
query error length for type character must be within \[1-10485760\], have 0
SELECT ''::pg_catalog.CHAR(0)
query error length for type character must be within \[1-10485760\], have 10485761
SELECT ''::pg_catalog.CHAR(10485761)
### position ###
statement ok
CREATE TABLE positiontest (strcol1 char(15), strcol2 char(15), vccol1 varchar(15), vccol2 varchar(15))
statement ok
INSERT INTO positiontest VALUES ('om', 'Thomas', 'om', 'Thomas'), ('foo', 'barbar', 'foo', 'barbar'),
(NULL, 'str', NULL, 'str'), ('str', NULL, 'str', NULL), ('释手', '爱不释手', '释手', '爱不释手'),
('', 'str', '', 'str'), ('str', '', 'str', '')
# invalid input
statement error Expected IN, found right parenthesis
SELECT position(42)
statement error Expected IN, found right parenthesis
SELECT position('str')
statement error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT position(42 IN 'str')
statement error arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
SELECT position('str' IN 42)
statement error Expected right parenthesis, found comma
SELECT position('str' IN 42, 172)
# standard tests
#TODO: materialize#589 select position(strcol1 IN strcol2) from positiontest
query I rowsort
SELECT position(vccol1 IN vccol2) FROM positiontest
----
3
0
NULL
NULL
3
1
0
# NULL inputs
query I
SELECT position(NULL IN 'str')
----
NULL