forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_view.slt
More file actions
1337 lines (1183 loc) · 37.4 KB
/
string_view.slt
File metadata and controls
1337 lines (1183 loc) · 37.4 KB
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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
include ./init_data.slt.part
# --------------------------------------
# Setup test tables with different physical string types
# and repeat tests in `string_query.slt.part`
# --------------------------------------
statement ok
create table test_basic_operator as
select
arrow_cast(column1, 'Utf8View') as ascii_1,
arrow_cast(column2, 'Utf8View') as ascii_2,
arrow_cast(column3, 'Utf8View') as unicode_1,
arrow_cast(column4, 'Utf8View') as unicode_2
from test_source;
statement ok
create table test_substr as
select arrow_cast(col1, 'Utf8View') as c1 from test_substr_base;
statement ok
create table test_datetime as
select
arrow_cast(column1, 'Utf8View') as ts,
arrow_cast(column2, 'Utf8View') as d,
arrow_cast(column3, 'Utf8View') as t
from test_datetime_base;
statement ok
drop table test_source
#
# common test for string-like functions and operators
#
include ./string_query.slt.part
#
# Clean up
#
statement ok
drop table test_basic_operator;
statement ok
drop table test_substr_base;
statement ok
drop table test_datetime_base;
# --------------------------------------
# String_view specific tests
# --------------------------------------
statement ok
create table test_source as values
('Andrew', 'X'),
('Xiangpeng', 'Xiangpeng'),
('Raphael', 'R'),
('', 'Warsaw'),
(NULL, 'R');
# Table with the different combination of column types
statement ok
create table test as
SELECT
arrow_cast(column1, 'Utf8') as column1_utf8,
arrow_cast(column2, 'Utf8') as column2_utf8,
arrow_cast(column1, 'LargeUtf8') as column1_large_utf8,
arrow_cast(column2, 'LargeUtf8') as column2_large_utf8,
arrow_cast(column1, 'Utf8View') as column1_utf8view,
arrow_cast(column2, 'Utf8View') as column2_utf8view,
arrow_cast(column1, 'Dictionary(Int32, Utf8)') as column1_dict,
arrow_cast(column2, 'Dictionary(Int32, Utf8)') as column2_dict
FROM test_source;
statement ok
drop table test_source
########
## StringView Function test
########
query I
select octet_length(column1_utf8view) from test;
----
6
9
7
0
NULL
query T
select btrim(column1_large_utf8) from test;
----
Andrew
Xiangpeng
Raphael
(empty)
NULL
########
## StringView to Other Types column
########
# test StringViewArray with Utf8 columns
query TTBBBB
select
column1_utf8, column2_utf8,
column1_utf8view = column2_utf8,
column2_utf8 = column1_utf8view,
column1_utf8view <> column2_utf8,
column2_utf8 <> column1_utf8view
from test;
----
Andrew X false false true true
Xiangpeng Xiangpeng true true false false
Raphael R false false true true
(empty) Warsaw false false true true
NULL R NULL NULL NULL NULL
# test StringViewArray with LargeUtf8 columns
query TTBBBB
select
column1_utf8, column2_utf8,
column1_utf8view = column2_large_utf8,
column2_large_utf8 = column1_utf8view,
column1_utf8view <> column2_large_utf8,
column2_large_utf8 <> column1_utf8view
from test;
----
Andrew X false false true true
Xiangpeng Xiangpeng true true false false
Raphael R false false true true
(empty) Warsaw false false true true
NULL R NULL NULL NULL NULL
########
## StringView to Dictionary
########
# test StringViewArray with Dictionary columns
query TTBBBB
select
column1_utf8, column2_utf8,
column1_utf8view = column2_dict,
column2_dict = column1_utf8view,
column1_utf8view <> column2_dict,
column2_dict <> column1_utf8view
from test;
----
Andrew X false false true true
Xiangpeng Xiangpeng true true false false
Raphael R false false true true
(empty) Warsaw false false true true
NULL R NULL NULL NULL NULL
# StringView column to Dict scalar
query TTBBBB
select
column1_utf8, column2_utf8,
column1_utf8view = arrow_cast('Andrew', 'Dictionary(Int32, Utf8)'),
arrow_cast('Andrew', 'Dictionary(Int32, Utf8)') = column1_utf8view,
column1_utf8view <> arrow_cast('Andrew', 'Dictionary(Int32, Utf8)'),
arrow_cast('Andrew', 'Dictionary(Int32, Utf8)') <> column1_utf8view
from test;
----
Andrew X true true false false
Xiangpeng Xiangpeng false false true true
Raphael R false false true true
(empty) Warsaw false false true true
NULL R NULL NULL NULL NULL
# Dict column to StringView scalar
query TTBBBB
select
column1_utf8, column2_utf8,
column1_dict = arrow_cast('Andrew', 'Utf8View'),
arrow_cast('Andrew', 'Utf8View') = column1_dict,
column1_dict <> arrow_cast('Andrew', 'Utf8View'),
arrow_cast('Andrew', 'Utf8View') <> column1_dict
from test;
----
Andrew X true true false false
Xiangpeng Xiangpeng false false true true
Raphael R false false true true
(empty) Warsaw false false true true
NULL R NULL NULL NULL NULL
########
## Coercion Rules
########
statement ok
set datafusion.explain.logical_plan_only = true;
# Filter should have a StringView literal and no column cast
query TT
explain SELECT column1_utf8 from test where column1_utf8view = 'Andrew';
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: test.column1_utf8view = Utf8View("Andrew")
03)----TableScan: test projection=[column1_utf8, column1_utf8view]
# reverse order should be the same
query TT
explain SELECT column1_utf8 from test where 'Andrew' = column1_utf8view;
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: test.column1_utf8view = Utf8View("Andrew")
03)----TableScan: test projection=[column1_utf8, column1_utf8view]
query TT
explain SELECT column1_utf8 from test where column1_utf8 = arrow_cast('Andrew', 'Utf8View');
----
logical_plan
01)Filter: test.column1_utf8 = Utf8("Andrew")
02)--TableScan: test projection=[column1_utf8]
query TT
explain SELECT column1_utf8 from test where arrow_cast('Andrew', 'Utf8View') = column1_utf8;
----
logical_plan
01)Filter: test.column1_utf8 = Utf8("Andrew")
02)--TableScan: test projection=[column1_utf8]
query TT
explain SELECT column1_utf8 from test where column1_utf8view = arrow_cast('Andrew', 'Dictionary(Int32, Utf8)');
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: test.column1_utf8view = Utf8View("Andrew")
03)----TableScan: test projection=[column1_utf8, column1_utf8view]
query TT
explain SELECT column1_utf8 from test where arrow_cast('Andrew', 'Dictionary(Int32, Utf8)') = column1_utf8view;
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: test.column1_utf8view = Utf8View("Andrew")
03)----TableScan: test projection=[column1_utf8, column1_utf8view]
# compare string / stringview
# Should cast string -> stringview (which is cheap), not stringview -> string (which is not)
query TT
explain SELECT column1_utf8 from test where column1_utf8view = column2_utf8;
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: test.column1_utf8view = CAST(test.column2_utf8 AS Utf8View)
03)----TableScan: test projection=[column1_utf8, column2_utf8, column1_utf8view]
query TT
explain SELECT column1_utf8 from test where column2_utf8 = column1_utf8view;
----
logical_plan
01)Projection: test.column1_utf8
02)--Filter: CAST(test.column2_utf8 AS Utf8View) = test.column1_utf8view
03)----TableScan: test projection=[column1_utf8, column2_utf8, column1_utf8view]
query TT
EXPLAIN SELECT
COUNT(DISTINCT column1_utf8),
COUNT(DISTINCT column1_utf8view),
COUNT(DISTINCT column1_dict)
FROM test;
----
logical_plan
01)Aggregate: groupBy=[[]], aggr=[[count(DISTINCT test.column1_utf8), count(DISTINCT test.column1_utf8view), count(DISTINCT test.column1_dict)]]
02)--TableScan: test projection=[column1_utf8, column1_utf8view, column1_dict]
### `STARTS_WITH`
# Test STARTS_WITH with utf8view against utf8view, utf8, and largeutf8
# (should be no casts)
query TT
EXPLAIN SELECT
STARTS_WITH(column1_utf8view, column2_utf8view) as c1,
STARTS_WITH(column1_utf8view, column2_utf8) as c2,
STARTS_WITH(column1_utf8view, column2_large_utf8) as c3
FROM test;
----
logical_plan
01)Projection: starts_with(test.column1_utf8view, test.column2_utf8view) AS c1, starts_with(test.column1_utf8view, test.column2_utf8) AS c2, starts_with(test.column1_utf8view, test.column2_large_utf8) AS c3
02)--TableScan: test projection=[column2_utf8, column2_large_utf8, column1_utf8view, column2_utf8view]
query BBB
SELECT
STARTS_WITH(column1_utf8view, column2_utf8view) as c1,
STARTS_WITH(column1_utf8view, column2_utf8) as c2,
STARTS_WITH(column1_utf8view, column2_large_utf8) as c3
FROM test;
----
false false false
true true true
true true true
false false false
NULL NULL NULL
# Test STARTS_WITH with utf8 against utf8view, utf8, and largeutf8
# Should work, but will have to cast to common types
# should cast utf8 -> utf8view and largeutf8 -> utf8view
query TT
EXPLAIN SELECT
STARTS_WITH(column1_utf8, column2_utf8view) as c1,
STARTS_WITH(column1_utf8, column2_utf8) as c3,
STARTS_WITH(column1_utf8, column2_large_utf8) as c4
FROM test;
----
logical_plan
01)Projection: starts_with(test.column1_utf8, test.column2_utf8view) AS c1, starts_with(test.column1_utf8, test.column2_utf8) AS c3, starts_with(test.column1_utf8, test.column2_large_utf8) AS c4
02)--TableScan: test projection=[column1_utf8, column2_utf8, column2_large_utf8, column2_utf8view]
query BBB
SELECT
STARTS_WITH(column1_utf8, column2_utf8view) as c1,
STARTS_WITH(column1_utf8, column2_utf8) as c3,
STARTS_WITH(column1_utf8, column2_large_utf8) as c4
FROM test;
----
false false false
true true true
true true true
false false false
NULL NULL NULL
# Test STARTS_WITH with utf8view against literals
# In this case, the literals should be cast to utf8view. The columns
# should not be cast to utf8.
query TT
EXPLAIN SELECT
STARTS_WITH(column1_utf8view, 'äöüß') as c1,
STARTS_WITH(column1_utf8view, '') as c2,
STARTS_WITH(column1_utf8view, NULL) as c3,
STARTS_WITH(NULL, column1_utf8view) as c4
FROM test;
----
logical_plan
01)Projection: test.column1_utf8view LIKE Utf8View("äöüß%") AS c1, CASE test.column1_utf8view IS NOT NULL WHEN Boolean(true) THEN Boolean(true) END AS c2, starts_with(test.column1_utf8view, Utf8View(NULL)) AS c3, starts_with(Utf8View(NULL), test.column1_utf8view) AS c4
02)--TableScan: test projection=[column1_utf8view]
## Test STARTS_WITH is rewitten to LIKE when the pattern is a constant
query TT
EXPLAIN SELECT
STARTS_WITH(column1_utf8, 'foo%') as c1,
STARTS_WITH(column1_large_utf8, 'foo%') as c2,
STARTS_WITH(column1_utf8view, 'foo%') as c3,
STARTS_WITH(column1_utf8, 'f_o') as c4,
STARTS_WITH(column1_large_utf8, 'f_o') as c5,
STARTS_WITH(column1_utf8view, 'f_o') as c6
FROM test;
----
logical_plan
01)Projection: test.column1_utf8 LIKE Utf8("foo\%%") AS c1, test.column1_large_utf8 LIKE LargeUtf8("foo\%%") AS c2, test.column1_utf8view LIKE Utf8View("foo\%%") AS c3, test.column1_utf8 LIKE Utf8("f\_o%") AS c4, test.column1_large_utf8 LIKE LargeUtf8("f\_o%") AS c5, test.column1_utf8view LIKE Utf8View("f\_o%") AS c6
02)--TableScan: test projection=[column1_utf8, column1_large_utf8, column1_utf8view]
## Test STARTS_WITH works with column arguments
query TT
EXPLAIN SELECT
STARTS_WITH(column1_utf8, substr(column1_utf8, 1, 2)) as c1,
STARTS_WITH(column1_large_utf8, substr(column1_large_utf8, 1, 2)) as c2,
STARTS_WITH(column1_utf8view, substr(column1_utf8view, 1, 2)) as c3
FROM test;
----
logical_plan
01)Projection: starts_with(test.column1_utf8, substr(test.column1_utf8, Int64(1), Int64(2))) AS c1, starts_with(test.column1_large_utf8, substr(test.column1_large_utf8, Int64(1), Int64(2))) AS c2, starts_with(test.column1_utf8view, substr(test.column1_utf8view, Int64(1), Int64(2))) AS c3
02)--TableScan: test projection=[column1_utf8, column1_large_utf8, column1_utf8view]
query BBB
SELECT
STARTS_WITH(column1_utf8, substr(column1_utf8, 1, 2)) as c1,
STARTS_WITH(column1_large_utf8, substr(column1_large_utf8, 1, 2)) as c2,
STARTS_WITH(column1_utf8view, substr(column1_utf8view, 1, 2)) as c3
FROM test;
----
true true true
true true true
true true true
true true true
NULL NULL NULL
# Ensure that INIT cap works with utf8view
query TT
EXPLAIN SELECT
INITCAP(column1_utf8view) as c
FROM test;
----
logical_plan
01)Projection: initcap(test.column1_utf8view) AS c
02)--TableScan: test projection=[column1_utf8view]
# Create a table with lowercase strings
statement ok
CREATE TABLE test_lowercase AS SELECT
lower(column1_utf8) as column1_utf8_lower,
lower(column1_large_utf8) as column1_large_utf8_lower,
lower(column1_utf8view) as column1_utf8view_lower
FROM test;
# Test INITCAP with utf8view, utf8, and largeutf8
# Should not cast anything
query TT
EXPLAIN SELECT
INITCAP(column1_utf8view_lower) as c1,
INITCAP(column1_utf8_lower) as c2,
INITCAP(column1_large_utf8_lower) as c3
FROM test_lowercase;
----
logical_plan
01)Projection: initcap(test_lowercase.column1_utf8view_lower) AS c1, initcap(test_lowercase.column1_utf8_lower) AS c2, initcap(test_lowercase.column1_large_utf8_lower) AS c3
02)--TableScan: test_lowercase projection=[column1_utf8_lower, column1_large_utf8_lower, column1_utf8view_lower]
statement ok
drop table test_lowercase
# Ensure string functions use native StringView implementation
# and do not fall back to Utf8 or LargeUtf8
# Should see no casts to Utf8 in the plans below
## Ensure no casts for LIKE/ILIKE
query TT
EXPLAIN SELECT
column1_utf8view like '%foo%' as "like",
column1_utf8view ilike '%foo%' as "ilike"
FROM test;
----
logical_plan
01)Projection: test.column1_utf8view LIKE Utf8View("%foo%") AS like, test.column1_utf8view ILIKE Utf8View("%foo%") AS ilike
02)--TableScan: test projection=[column1_utf8view]
query TT
EXPLAIN SELECT
SUBSTR(column1_utf8view, 1, 3) as c1,
SUBSTR(column2_utf8, 1, 3) as c2,
SUBSTR(column2_large_utf8, 1, 3) as c3
FROM test;
----
logical_plan
01)Projection: substr(test.column1_utf8view, Int64(1), Int64(3)) AS c1, substr(test.column2_utf8, Int64(1), Int64(3)) AS c2, substr(test.column2_large_utf8, Int64(1), Int64(3)) AS c3
02)--TableScan: test projection=[column2_utf8, column2_large_utf8, column1_utf8view]
## Ensure no casts for SUBSTR
query TT
EXPLAIN SELECT
SUBSTR(column1_utf8view, 1, 3) as c1,
SUBSTR(column2_utf8, 1, 3) as c2,
SUBSTR(column2_large_utf8, 1, 3) as c3
FROM test;
----
logical_plan
01)Projection: substr(test.column1_utf8view, Int64(1), Int64(3)) AS c1, substr(test.column2_utf8, Int64(1), Int64(3)) AS c2, substr(test.column2_large_utf8, Int64(1), Int64(3)) AS c3
02)--TableScan: test projection=[column2_utf8, column2_large_utf8, column1_utf8view]
# Test ASCII with utf8view against utf8view, utf8, and largeutf8
# (should be no casts)
query TT
EXPLAIN SELECT
ASCII(column1_utf8view) as c1,
ASCII(column2_utf8) as c2,
ASCII(column2_large_utf8) as c3
FROM test;
----
logical_plan
01)Projection: ascii(test.column1_utf8view) AS c1, ascii(test.column2_utf8) AS c2, ascii(test.column2_large_utf8) AS c3
02)--TableScan: test projection=[column2_utf8, column2_large_utf8, column1_utf8view]
query TT
EXPLAIN SELECT
ASCII(column1_utf8) as c1,
ASCII(column1_large_utf8) as c2,
ASCII(column2_utf8view) as c3,
ASCII('hello') as c4,
ASCII(arrow_cast('world', 'Utf8View')) as c5
FROM test;
----
logical_plan
01)Projection: ascii(test.column1_utf8) AS c1, ascii(test.column1_large_utf8) AS c2, ascii(test.column2_utf8view) AS c3, Int32(104) AS c4, Int32(119) AS c5
02)--TableScan: test projection=[column1_utf8, column1_large_utf8, column2_utf8view]
# Test ASCII with literals cast to Utf8View
query TT
EXPLAIN SELECT
ASCII(arrow_cast('äöüß', 'Utf8View')) as c1,
ASCII(arrow_cast('', 'Utf8View')) as c2,
ASCII(arrow_cast(NULL, 'Utf8View')) as c3
FROM test;
----
logical_plan
01)Projection: Int32(228) AS c1, Int32(0) AS c2, Int32(NULL) AS c3
02)--TableScan: test projection=[]
## Ensure no casts for BTRIM
# Test BTRIM with Utf8View input
query TT
EXPLAIN SELECT
BTRIM(column1_utf8view) AS l
FROM test;
----
logical_plan
01)Projection: btrim(test.column1_utf8view) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test BTRIM with Utf8View input and Utf8View pattern
query TT
EXPLAIN SELECT
BTRIM(column1_utf8view, 'foo') AS l
FROM test;
----
logical_plan
01)Projection: btrim(test.column1_utf8view, Utf8("foo")) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test BTRIM with Utf8View bytes longer than 12
query TT
EXPLAIN SELECT
BTRIM(column1_utf8view, 'this is longer than 12') AS l
FROM test;
----
logical_plan
01)Projection: btrim(test.column1_utf8view, Utf8("this is longer than 12")) AS l
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for LTRIM
# Test LTRIM with Utf8View input
query TT
EXPLAIN SELECT
LTRIM(column1_utf8view) AS l
FROM test;
----
logical_plan
01)Projection: ltrim(test.column1_utf8view) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test LTRIM with Utf8View input and Utf8View pattern
query TT
EXPLAIN SELECT
LTRIM(column1_utf8view, 'foo') AS l
FROM test;
----
logical_plan
01)Projection: ltrim(test.column1_utf8view, Utf8("foo")) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test LTRIM with Utf8View bytes longer than 12
query TT
EXPLAIN SELECT
LTRIM(column1_utf8view, 'this is longer than 12') AS l
FROM test;
----
logical_plan
01)Projection: ltrim(test.column1_utf8view, Utf8("this is longer than 12")) AS l
02)--TableScan: test projection=[column1_utf8view]
## ensure no casts for RTRIM
# Test RTRIM with Utf8View input
query TT
EXPLAIN SELECT
RTRIM(column1_utf8view) AS l
FROM test;
----
logical_plan
01)Projection: rtrim(test.column1_utf8view) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test RTRIM with Utf8View input and Utf8View pattern
query TT
EXPLAIN SELECT
RTRIM(column1_utf8view, 'foo') AS l
FROM test;
----
logical_plan
01)Projection: rtrim(test.column1_utf8view, Utf8("foo")) AS l
02)--TableScan: test projection=[column1_utf8view]
# Test RTRIM with Utf8View bytes longer than 12
query TT
EXPLAIN SELECT
RTRIM(column1_utf8view, 'this is longer than 12') AS l
FROM test;
----
logical_plan
01)Projection: rtrim(test.column1_utf8view, Utf8("this is longer than 12")) AS l
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for CHARACTER_LENGTH
query TT
EXPLAIN SELECT
CHARACTER_LENGTH(column1_utf8view) AS l
FROM test;
----
logical_plan
01)Projection: character_length(test.column1_utf8view) AS l
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for CONCAT Utf8View
query TT
EXPLAIN SELECT
concat(column1_utf8view, column2_utf8view) as c
FROM test;
----
logical_plan
01)Projection: concat(test.column1_utf8view, test.column2_utf8view) AS c
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for CONCAT LargeUtf8
query TT
EXPLAIN SELECT
concat(column1_large_utf8, column2_large_utf8) as c
FROM test;
----
logical_plan
01)Projection: concat(test.column1_large_utf8, test.column2_large_utf8) AS c
02)--TableScan: test projection=[column1_large_utf8, column2_large_utf8]
## Ensure no casts for CONCAT_WS
query TT
EXPLAIN SELECT
concat_ws(', ', column1_utf8view, column2_utf8view) as c
FROM test;
----
logical_plan
01)Projection: concat_ws(Utf8View(", "), test.column1_utf8view, test.column2_utf8view) AS c
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure CONCAT_WS simplification preserves Utf8View for merged literals
query TT
EXPLAIN SELECT
concat_ws(', ', column1_utf8view, 'foo', 'bar', column2_utf8view) as c
FROM test;
----
logical_plan
01)Projection: concat_ws(Utf8View(", "), test.column1_utf8view, Utf8View("foo, bar"), test.column2_utf8view) AS c
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for CONTAINS
query TT
EXPLAIN SELECT
CONTAINS(column1_utf8view, 'foo') as c1,
CONTAINS(column1_utf8view, column2_utf8view) as c2,
CONTAINS(column1_utf8view, column2_large_utf8) as c3,
CONTAINS(column1_utf8, column2_utf8view) as c4,
CONTAINS(column1_utf8, column2_utf8) as c5,
CONTAINS(column1_utf8, column2_large_utf8) as c6,
CONTAINS(column1_large_utf8, column1_utf8view) as c7,
CONTAINS(column1_large_utf8, column2_utf8) as c8,
CONTAINS(column1_large_utf8, column2_large_utf8) as c9
FROM test;
----
logical_plan
01)Projection: contains(test.column1_utf8view, Utf8("foo")) AS c1, contains(test.column1_utf8view, test.column2_utf8view) AS c2, contains(test.column1_utf8view, test.column2_large_utf8) AS c3, contains(test.column1_utf8, test.column2_utf8view) AS c4, contains(test.column1_utf8, test.column2_utf8) AS c5, contains(test.column1_utf8, test.column2_large_utf8) AS c6, contains(test.column1_large_utf8, test.column1_utf8view) AS c7, contains(test.column1_large_utf8, test.column2_utf8) AS c8, contains(test.column1_large_utf8, test.column2_large_utf8) AS c9
02)--TableScan: test projection=[column1_utf8, column2_utf8, column1_large_utf8, column2_large_utf8, column1_utf8view, column2_utf8view]
## Ensure no casts for ENDS_WITH
query TT
EXPLAIN SELECT
ENDS_WITH(column1_utf8view, 'foo') as c1,
ENDS_WITH(column2_utf8view, column2_utf8view) as c2
FROM test;
----
logical_plan
01)Projection: ends_with(test.column1_utf8view, Utf8("foo")) AS c1, ends_with(test.column2_utf8view, test.column2_utf8view) AS c2
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for LEVENSHTEIN
query TT
EXPLAIN SELECT
levenshtein(column1_utf8view, 'foo') as c1,
levenshtein(column1_utf8view, column2_utf8view) as c2
FROM test;
----
logical_plan
01)Projection: levenshtein(test.column1_utf8view, Utf8("foo")) AS c1, levenshtein(test.column1_utf8view, test.column2_utf8view) AS c2
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for LOWER
query TT
EXPLAIN SELECT
LOWER(column1_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: lower(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for UPPER
query TT
EXPLAIN SELECT
UPPER(column1_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: upper(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for LPAD
query TT
EXPLAIN SELECT
LPAD(column1_utf8view, 12, ' ') as c1
FROM test;
----
logical_plan
01)Projection: lpad(test.column1_utf8view, Int64(12), Utf8(" ")) AS c1
02)--TableScan: test projection=[column1_utf8view]
query TT
EXPLAIN SELECT
LPAD(column1_utf8view, 12, column2_large_utf8) as c1
FROM test;
----
logical_plan
01)Projection: lpad(test.column1_utf8view, Int64(12), test.column2_large_utf8) AS c1
02)--TableScan: test projection=[column2_large_utf8, column1_utf8view]
query TT
EXPLAIN SELECT
LPAD(column1_utf8view, 12, column2_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: lpad(test.column1_utf8view, Int64(12), test.column2_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for OCTET_LENGTH
query TT
EXPLAIN SELECT
OCTET_LENGTH(column1_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: octet_length(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for OVERLAY
query TT
EXPLAIN SELECT
OVERLAY(column1_utf8view PLACING 'foo' FROM 2 ) as c1
FROM test;
----
logical_plan
01)Projection: overlay(test.column1_utf8view, Utf8View("foo"), Int64(2)) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Should run CONCAT successfully with utf8 and utf8view
query T
SELECT
concat(column1_utf8view, column2_utf8) as c
FROM test;
----
AndrewX
XiangpengXiangpeng
RaphaelR
Warsaw
R
## Should run CONCAT successfully with utf8 utf8view and largeutf8
query T
SELECT
concat(column1_utf8view, column2_utf8, column2_large_utf8) as c
FROM test;
----
AndrewXX
XiangpengXiangpengXiangpeng
RaphaelRR
WarsawWarsaw
RR
## Ensure no casts for REGEXP_LIKE
query TT
EXPLAIN SELECT
REGEXP_LIKE(column1_utf8view, '^https?://(?:www\.)?([^/]+)/.*$') AS k
FROM test;
----
logical_plan
01)Projection: test.column1_utf8view ~ Utf8View("^https?://(?:www\.)?([^/]+)/.*$") AS k
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for REGEXP_MATCH
query TT
EXPLAIN SELECT
REGEXP_MATCH(column1_utf8view, '^https?://(?:www\.)?([^/]+)/.*$') AS k
FROM test;
----
logical_plan
01)Projection: regexp_match(test.column1_utf8view, Utf8View("^https?://(?:www\.)?([^/]+)/.*$")) AS k
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for REGEXP_REPLACE
query TT
EXPLAIN SELECT
REGEXP_REPLACE(column1_utf8view, '^https?://(?:www\.)?([^/]+)/.*$', '\1') AS k
FROM test;
----
logical_plan
01)Projection: regexp_replace(test.column1_utf8view, Utf8View("^https?://(?:www\.)?([^/]+)/.*$"), Utf8View("\1")) AS k
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for REPEAT
query TT
EXPLAIN SELECT
REPEAT(column1_utf8view, 2) as c1
FROM test;
----
logical_plan
01)Projection: repeat(test.column1_utf8view, Int64(2)) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for REPLACE
query TT
EXPLAIN SELECT
REPLACE(column1_utf8view, 'foo', 'bar') as c1,
REPLACE(column1_utf8view, column2_utf8view, 'bar') as c2
FROM test;
----
logical_plan
01)Projection: replace(test.column1_utf8view, Utf8("foo"), Utf8("bar")) AS c1, replace(test.column1_utf8view, test.column2_utf8view, Utf8("bar")) AS c2
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for REVERSE
query TT
EXPLAIN SELECT
REVERSE(column1_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: reverse(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for RIGHT
query TT
EXPLAIN SELECT
RIGHT(column1_utf8view, 3) as c2
FROM test;
----
logical_plan
01)Projection: right(test.column1_utf8view, Int64(3)) AS c2
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for LEFT
query TT
EXPLAIN SELECT
LEFT(column1_utf8view, 3) as c2
FROM test;
----
logical_plan
01)Projection: left(test.column1_utf8view, Int64(3)) AS c2
02)--TableScan: test projection=[column1_utf8view]
## Ensure no casts for RPAD
query TT
EXPLAIN SELECT
RPAD(column1_utf8view, 1) as c1,
RPAD(column1_utf8view, 2, column2_utf8view) as c2
FROM test;
----
logical_plan
01)Projection: rpad(test.column1_utf8view, Int64(1)) AS c1, rpad(test.column1_utf8view, Int64(2), test.column2_utf8view) AS c2
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
query TT
EXPLAIN SELECT
RPAD(column1_utf8view, 12, column2_large_utf8) as c1
FROM test;
----
logical_plan
01)Projection: rpad(test.column1_utf8view, Int64(12), test.column2_large_utf8) AS c1
02)--TableScan: test projection=[column2_large_utf8, column1_utf8view]
query TT
EXPLAIN SELECT
RPAD(column1_utf8view, 12, column2_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: rpad(test.column1_utf8view, Int64(12), test.column2_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for SPLIT_PART
query TT
EXPLAIN SELECT
SPLIT_PART(column1_utf8view, 'f', 1) as c1,
SPLIT_PART('testtesttest',column1_utf8view, 1) as c2
FROM test;
----
logical_plan
01)Projection: split_part(test.column1_utf8view, Utf8("f"), Int64(1)) AS c1, split_part(Utf8("testtesttest"), test.column1_utf8view, Int64(1)) AS c2
02)--TableScan: test projection=[column1_utf8view]
# SPLIT_PART with Utf8View
query T
SELECT split_part(arrow_cast('abc~@~def~@~ghi', 'Utf8View'), '~@~', 2);
----
def
query T
SELECT split_part(arrow_cast('abc~@~def~@~ghi', 'Utf8View'), '~@~', 20);
----
(empty)
query T
SELECT split_part(arrow_cast('abc~@~def~@~ghi', 'Utf8View'), '~@~', -1);
----
ghi
statement error DataFusion error: Execution error: field position must not be zero
SELECT split_part(arrow_cast('abc~@~def~@~ghi', 'Utf8View'), '~@~', 0);
query T
SELECT split_part(arrow_cast('a,b', 'Utf8View'), '', 1);
----
a,b
query T
SELECT split_part(arrow_cast('a,b', 'Utf8View'), '', 2);
----
(empty)
query T
SELECT split_part(arrow_cast('a,b', 'Utf8View'), '', -1);
----
a,b
# Single-char delimiter
query T
SELECT split_part(arrow_cast('a.b.c', 'Utf8View'), '.', 2);
----
b
# Verify Utf8View input produces Utf8View output
query T
SELECT arrow_typeof(split_part(arrow_cast('a.b.c', 'Utf8View'), '.', 2));
----
Utf8View
# SPLIT_PART with Utf8View column (exercises the array fast path)
query T
SELECT split_part(column1_utf8view, 'ph', 1) FROM test;
----
Andrew
Xiangpeng
Ra
(empty)
NULL
query T
SELECT split_part(column1_utf8view, 'ph', 2) FROM test;
----
(empty)
(empty)
ael
(empty)
NULL
# Negative position
query T
SELECT split_part(column1_utf8view, 'ph', -1) FROM test;
----
Andrew
Xiangpeng
ael
(empty)
NULL
# Delimiter not found returns full string
query T
SELECT split_part(column1_utf8view, 'ZZZ', 1) FROM test;
----
Andrew
Xiangpeng
Raphael
(empty)
NULL
# Empty delimiter with column
query T
SELECT split_part(column1_utf8view, '', 1) FROM test;
----
Andrew