forked from StarRocks/starrocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_array
More file actions
226 lines (195 loc) · 8.97 KB
/
Copy pathtest_array
File metadata and controls
226 lines (195 loc) · 8.97 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
-- name: test_array_test01
select ARRAY<INT>[], [], ARRAY<STRING>['abc'], [123, NULL, 1.0], ['abc', NULL];
-- name: testArrayPredicate
CREATE TABLE array_data_type
(c1 int,
c2 array<bigint>,
c3 array<bigint>,
c4 array<bigint> not null,
c5 array<bigint> not null)
PRIMARY KEY(c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 1
PROPERTIES ("replication_num" = "1");
insert into array_data_type (c1, c2, c3, c4,c5) values
(1,NULL,NULL,[22, 11, 33],[22, 11, 33]);
select c2 = c3 from array_data_type;
insert into array_data_type (c1, c2, c3, c4,c5) values
(2,NULL,[22, 11, 33],[22, 11, 33],[22, 11, 33]),
(3,[22, 11, 33],[22, 11, 33],[22, 11, 33],[22, 11, 33]),
(4,[22, 11, 33],NULL,[22, 11, 33],[22, 11, 33]);
select c2 <=> c3 from array_data_type;
select c2 = c3 from array_data_type;
select c3 = c4 from array_data_type;
select c4 = c5 from array_data_type;
insert into array_data_type (c1, c2, c3, c4,c5) values
(5,[22, 11, 33],[22, 11, 33],[22, 11, 44],[22, 11, 33]);
select c4 = c5 from array_data_type;
select c4 > c5 from array_data_type;
select * from (select array_map(x -> x*2 + x*2, [1,3]) col1) t1 join (select array_map(x -> x*2 + x*2, c3) col2 from array_data_type) t2;
-- name: testArrayVarchar
CREATE TABLE array_data_type_1
(c1 int,
c2 array<datetime>,
c3 array<float>,
c4 array<varchar(10)>,
c5 array<varchar(20)>,
c6 array<array<varchar(10)>>)
PRIMARY KEY(c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 1
PROPERTIES ("replication_num" = "1");
insert into array_data_type_1 values
(1, ['2020-11-11', '2021-11-11', '2022-01-01'], [1.23, 1.35, 2.7894], ['a', 'b'], ['sss', 'eee', 'fff'], [['a', 'b']]),
(2, ['2020-01-11', null, '2022-11-01'], [2.23, 2.35, 3.7894], ['aa', null], ['ssss', 'eeee', null], [['a', null], null]),
(3, null, null, null, null, null);
select * from array_data_type_1 where c4 != ['a'] or c6 = [['a', 'b']];
select * from array_data_type_1 where c4 = ['a'] or c6 != [['a', 'b']];
select * from array_data_type_1 where c4 = cast(c4 as array<char(10)>);
select * from array_data_type_1 where c5 = c4 or c6 = [['a']];
select * from array_data_type_1 where array_map((x) -> concat(x, 'a'), c5) = c4;
select c6[0] = ['a'] from array_data_type_1;
select c6[0] > array_map((x) -> concat(x, 'a'), c5) from array_data_type_1;
-- name: testArrayTopN
CREATE TABLE array_top_n
(c1 int,
c2 array<int>)
PRIMARY KEY(c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 1
PROPERTIES ("replication_num" = "1");
insert into array_top_n values
(1, [1]),
(2, [5, 6]),
(3, [2, 3, 4]),
(4, [12, 13, 14, 15]),
(5, [7, 8, 9, 10, 11]);
select * from array_top_n order by c2[1];
select * from array_top_n order by c2[1] limit 1,10;
select * from array_top_n order by c2[1] limit 2,10;
select * from array_top_n order by c2[1] limit 3,10;
select * from array_top_n order by c2[1] limit 4,10;
select * from array_top_n order by c2[1] limit 5,10;
-- name: testArrayExpr
CREATE TABLE array_exprr
(
c1 int not null,
c2 int not null
)
PRIMARY KEY(c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 1
PROPERTIES ("replication_num" = "1");
insert into array_exprr SELECT generate_series, generate_series FROM TABLE(generate_series(1, 13336));
select count([CAST(if(c2 is null, c1 + c2, 0) as DECIMAL128(38,0)) + if(c1 is null, c2 ,0)] is null) from array_exprr;
-- name: testEmptyArray
with t0 as (
select c1 from (values([])) as t(c1)
)
select
array_concat(c1, [1])
from t0;
with t0 as (
select c1 from (values([])) as t(c1)
)
select
array_concat([1], c1)
from t0;
select array_concat(c1, [[]])
from (select c1 from (values([])) as t(c1)) t;
select array_concat(c1, [[1]])
from (select c1 from (values([])) as t(c1)) t;
select array_concat(c1, [[1]])
from (select c1 from (values([[]])) as t(c1)) t;
select array_concat(c1, [map{'a':1}])
from (select c1 from (values([map()])) as t(c1)) t;
select array_concat(c1, [map{'a':1}])
from (select c1 from (values([])) as t(c1)) t;
select array_concat(c1, [named_struct('a', 1, 'b', 2, 'c', 3)])
from (select c1 from (values([])) as t(c1)) t;
--name: testArrayNE
CREATE TABLE `t2` (
`pk` bigint(20) NOT NULL COMMENT "",
`aas_1` array<array<array<varchar(65533)>>> NULL COMMENT "",
`aad_1` array<array<array<DECIMAL128(26,2)>>> NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`pk`)
DISTRIBUTED BY HASH(`pk`) BUCKETS 3
PROPERTIES (
"replication_num" = "1",
"enable_persistent_index" = "true",
"replicated_storage" = "true",
"fast_schema_evolution" = "true",
"compression" = "LZ4"
);
insert into t2 values
(1, [[["10"],["20"],["30"]],[["60"],["5"],["4"]],[["-100","-2"],["-20","10"],["100","23"]]], [[[1.00],[2.00],[3.00]],[[6.00],[5.00],[4.00]],[[-1.00,-2.00],[-2.00,10.00],[100.00,23.00]]]);
select aad_1 != aas_1 from t2;
-- name: test_array_generate
select array_generate(1, array_length([1,2,3]),1);
select array_generate(1, NULL,1);
select array_generate(NULL,1,1);
select array_generate(1,1,NULL);
select array_generate(1,9);
select array_generate(9,1);
select array_generate(9);
select array_generate(3,3);
select array_generate(3,2,1);
select array_generate("2025-10-01", "2025-10-05",1);
select array_generate("2025-10-01", "2025-10-05",interval 1 day);
select array_generate("2025-10-01", "2025-10-05",interval 0 day);
select array_generate("2025-10-01", 10000, interval 0 day);
select array_generate("2025-10-01", "abc", 1);
select array_generate("2025-10-01", "2025-10-05",interval -1 day);
select array_generate(DATE"2025-10-01", DATE"2025-10-05",interval 1 day);
select array_generate(DATETIME"2025-10-01", DATETIME"2025-10-05",interval 1 day);
select array_generate("2025-10-01", "2027-10-05",interval 1 year);
select array_generate("2025-10-01", "2027-10-05",interval 1 QUARTER);
select array_generate("2025-10-01", "2026-10-05",interval 2 MONTH);
select array_generate("2025-10-01", "2025-12-05",interval 2 WEEK);
select array_generate("2025-10-01", "2025-10-05",interval 2 day);
select array_generate("2025-10-01 14:28:31", "2025-10-01 23:12:36",interval 3 hour);
select array_generate("2025-10-01 14:28:31", "2025-10-01 15:12:36",interval 8 MINUTE);
select array_generate("2025-10-01 14:28:31", "2025-10-01 14:29:36",interval 10 SECOND);
select array_generate("2025-10-01 14:28:31", "2025-10-01 14:28:34",interval 500 MILLISECOND);
select array_generate("2025-10-01 14:28:31", "2025-10-01 14:28:32.800000",interval 500000 MICROSECOND);
select array_generate("2027-10-05", "2025-10-01",interval 1 year);
select array_generate("2027-10-05", "2025-10-01",interval 1 QUARTER);
select array_generate("2026-10-05", "2025-10-01",interval 2 MONTH);
select array_generate("2025-12-05", "2025-10-01",interval 2 WEEK);
select array_generate("2025-10-05", "2025-10-01",interval 2 day);
select array_generate("2025-10-01 23:12:36", "2025-10-01 14:28:31",interval 3 hour);
select array_generate("2025-10-01 15:12:36", "2025-10-01 14:28:31",interval 8 MINUTE);
select array_generate("2025-10-01 14:29:36", "2025-10-01 14:28:31",interval 10 SECOND);
select array_generate("2025-10-01 14:28:34", "2025-10-01 14:28:31",interval 500 MILLISECOND);
select array_generate("2025-10-01 14:28:32.800000", "2025-10-01 14:28:31",interval 500000 MICROSECOND);
select array_generate("2025-10-05", "2025-10-01",interval -1 day);
select array_generate("2025-10-01 14:28:32.800000", "2025-10-01 14:28:31",NULL);
-- name: test_array_repeat
select array_repeat(1,5);
select array_repeat([1,2],3);
select array_repeat(1,-1);
CREATE TABLE IF NOT EXISTS repeat_test (COLA INT, COLB INT) PROPERTIES ("replication_num"="1");
INSERT INTO repeat_test (COLA, COLB) VALUES (1, 3), (NULL, 3), (2, NULL);
SELECT array_repeat(COLA, COLB) FROM repeat_test ORDER BY COLA;
-- name: test_array_flatten
select array_flatten([[1, 2], [1, 4]]);
select array_flatten([[[1],[2]],[[3],[4]]]);
CREATE TABLE IF NOT EXISTS flatten_test (COLA INT, COLB ARRAY<ARRAY<INT>>) PROPERTIES ("replication_num"="1");
INSERT INTO flatten_test (COLA, COLB) VALUES (1, [[1, 2], [1, 4]]), (2, NULL), (3, [[5], [6, 7, 8], [9]]), (4, [[2, 3], [4, 5, 6], NULL]);
SELECT array_flatten(COLB) FROM flatten_test ORDER BY COLA;
SELECT array_slice(array_flatten(COLB), 1, 2) FROM flatten_test ORDER BY COLA;
SELECT array_flatten(array_slice(COLB, 1, 2)) FROM flatten_test ORDER BY COLA;
CREATE TABLE IF NOT EXISTS flatten_one_layer_arr_test (COLA INT, COLB ARRAY<INT>) PROPERTIES ("replication_num"="1");
INSERT INTO flatten_one_layer_arr_test (COLA, COLB) VALUES (1, [1, 2, 3]);
SELECT array_flatten(COLB) FROM flatten_one_layer_arr_test ORDER BY COLA;
SELECT array_slice(array_flatten(COLB), 1, 2) FROM flatten_one_layer_arr_test ORDER BY COLA;
SELECT array_flatten(array_slice(COLB, 1, 2)) FROM flatten_one_layer_arr_test ORDER BY COLA;
-- name: test_null_or_empty
select null_or_empty([1, 2]);
select null_or_empty(null);
select null_or_empty([]);
select null_or_empty([[1,2],[1]]);
CREATE TABLE IF NOT EXISTS null_or_empty_test (COLA INT, COLB ARRAY<INT>) PROPERTIES ("replication_num"="1");
INSERT INTO null_or_empty_test (COLA, COLB) VALUES (1, []), (2, NULL), (3, [1,2]);
SELECT null_or_empty(COLB) FROM flatten_test ORDER BY COLA;