-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy patharray_repeat.slt
More file actions
232 lines (201 loc) · 6.6 KB
/
array_repeat.slt
File metadata and controls
232 lines (201 loc) · 6.6 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
# 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
## array_repeat (aliases: `list_repeat`)
# array_repeat scalar function #1
query ????????
select
array_repeat(1, 5),
array_repeat(3.14, 3),
array_repeat('l', 4),
array_repeat(null, 2),
list_repeat(-1, 5),
list_repeat(-3.14, 0),
list_repeat('rust', 4),
list_repeat(null, 0);
----
[1, 1, 1, 1, 1] [3.14, 3.14, 3.14] [l, l, l, l] [NULL, NULL] [-1, -1, -1, -1, -1] [] [rust, rust, rust, rust] []
# array_repeat scalar function #2 (element as list)
query ????
select
array_repeat([1], 5),
array_repeat([1.1, 2.2, 3.3], 3),
array_repeat([null, null], 3),
array_repeat([[1, 2], [3, 4]], 2);
----
[[1], [1], [1], [1], [1]] [[1.1, 2.2, 3.3], [1.1, 2.2, 3.3], [1.1, 2.2, 3.3]] [[NULL, NULL], [NULL, NULL], [NULL, NULL]] [[[1, 2], [3, 4]], [[1, 2], [3, 4]]]
query ????
select
array_repeat(arrow_cast([1], 'LargeList(Int64)'), 5),
array_repeat(arrow_cast([1.1, 2.2, 3.3], 'LargeList(Float64)'), 3),
array_repeat(arrow_cast([null, null], 'LargeList(Int64)'), 3),
array_repeat(arrow_cast([[1, 2], [3, 4]], 'LargeList(List(Int64))'), 2);
----
[[1], [1], [1], [1], [1]] [[1.1, 2.2, 3.3], [1.1, 2.2, 3.3], [1.1, 2.2, 3.3]] [[NULL, NULL], [NULL, NULL], [NULL, NULL]] [[[1, 2], [3, 4]], [[1, 2], [3, 4]]]
# array_repeat scalar function with count of different integer types
query ????????
Select
array_repeat(1, arrow_cast(2,'Int8')),
array_repeat(2, arrow_cast(2,'Int16')),
array_repeat(3, arrow_cast(2,'Int32')),
array_repeat(4, arrow_cast(2,'Int64')),
array_repeat(1, arrow_cast(2,'UInt8')),
array_repeat(2, arrow_cast(2,'UInt16')),
array_repeat(3, arrow_cast(2,'UInt32')),
array_repeat(4, arrow_cast(2,'UInt64'));
----
[1, 1] [2, 2] [3, 3] [4, 4] [1, 1] [2, 2] [3, 3] [4, 4]
# array_repeat scalar function with count of negative integer types
query ????
Select
array_repeat(1, arrow_cast(-2,'Int8')),
array_repeat(2, arrow_cast(-2,'Int16')),
array_repeat(3, arrow_cast(-2,'Int32')),
array_repeat(4, arrow_cast(-2,'Int64'));
----
[] [] [] []
# array_repeat with columns #1
statement ok
CREATE TABLE array_repeat_table
AS VALUES
(1, 1, 1.1, 'a', make_array(4, 5, 6)),
(2, null, null, null, null),
(3, 2, 2.2, 'rust', make_array(7)),
(0, 3, 3.3, 'datafusion', make_array(8, 9));
statement ok
CREATE TABLE large_array_repeat_table
AS SELECT
column1,
column2,
column3,
column4,
arrow_cast(column5, 'LargeList(Int64)') as column5
FROM array_repeat_table;
query ??????
select
array_repeat(column2, column1),
array_repeat(column3, column1),
array_repeat(column4, column1),
array_repeat(column5, column1),
array_repeat(column2, 3),
array_repeat(make_array(1), column1)
from array_repeat_table;
----
[1] [1.1] [a] [[4, 5, 6]] [1, 1, 1] [[1]]
[NULL, NULL] [NULL, NULL] [NULL, NULL] [NULL, NULL] [NULL, NULL, NULL] [[1], [1]]
[2, 2, 2] [2.2, 2.2, 2.2] [rust, rust, rust] [[7], [7], [7]] [2, 2, 2] [[1], [1], [1]]
[] [] [] [] [3, 3, 3] []
query ??????
select
array_repeat(column2, column1),
array_repeat(column3, column1),
array_repeat(column4, column1),
array_repeat(column5, column1),
array_repeat(column2, 3),
array_repeat(make_array(1), column1)
from large_array_repeat_table;
----
[1] [1.1] [a] [[4, 5, 6]] [1, 1, 1] [[1]]
[NULL, NULL] [NULL, NULL] [NULL, NULL] [NULL, NULL] [NULL, NULL, NULL] [[1], [1]]
[2, 2, 2] [2.2, 2.2, 2.2] [rust, rust, rust] [[7], [7], [7]] [2, 2, 2] [[1], [1], [1]]
[] [] [] [] [3, 3, 3] []
statement ok
drop table array_repeat_table;
statement ok
drop table large_array_repeat_table;
# array_repeat: arrays with NULL counts
statement ok
create table array_repeat_null_count_table
as values
(1, 2),
(2, null),
(3, 1),
(4, -1),
(null, null);
query I?
select column1, array_repeat(column1, column2) from array_repeat_null_count_table;
----
1 [1, 1]
2 NULL
3 [3]
4 []
NULL NULL
statement ok
drop table array_repeat_null_count_table
# array_repeat: nested arrays with NULL counts
statement ok
create table array_repeat_nested_null_count_table
as values
([[1, 2], [3, 4]], 2),
([[5, 6], [7, 8]], null),
([[null, null], [9, 10]], 1),
(null, 3),
([[11, 12]], -1);
query ??
select column1, array_repeat(column1, column2) from array_repeat_nested_null_count_table;
----
[[1, 2], [3, 4]] [[[1, 2], [3, 4]], [[1, 2], [3, 4]]]
[[5, 6], [7, 8]] NULL
[[NULL, NULL], [9, 10]] [[[NULL, NULL], [9, 10]]]
NULL [NULL, NULL, NULL]
[[11, 12]] []
statement ok
drop table array_repeat_nested_null_count_table
# array_repeat edge cases: empty arrays
query ???
select array_repeat([], 3), array_repeat([], 0), array_repeat([], null);
----
[[], [], []] [] NULL
query ??
select array_repeat(null::int, 0), array_repeat(null::int, null);
----
[] NULL
# array_repeat LargeList with NULL count
statement ok
create table array_repeat_large_list_null_table
as values
(arrow_cast([1, 2, 3], 'LargeList(Int64)'), 2),
(arrow_cast([4, 5], 'LargeList(Int64)'), null),
(arrow_cast(null, 'LargeList(Int64)'), 3);
query ??
select column1, array_repeat(column1, column2) from array_repeat_large_list_null_table;
----
[1, 2, 3] [[1, 2, 3], [1, 2, 3]]
[4, 5] NULL
NULL [NULL, NULL, NULL]
statement ok
drop table array_repeat_large_list_null_table
# array_repeat edge cases: LargeList nested with NULL count
statement ok
create table array_repeat_large_nested_null_table
as values
(arrow_cast([[1, 2], [3, 4]], 'LargeList(List(Int64))'), 2),
(arrow_cast([[5, 6], [7, 8]], 'LargeList(List(Int64))'), null),
(arrow_cast([[null, null]], 'LargeList(List(Int64))'), 1),
(null, 3);
query ??
select column1, array_repeat(column1, column2) from array_repeat_large_nested_null_table;
----
[[1, 2], [3, 4]] [[[1, 2], [3, 4]], [[1, 2], [3, 4]]]
[[5, 6], [7, 8]] NULL
[[NULL, NULL]] [[[NULL, NULL]]]
NULL [NULL, NULL, NULL]
query error DataFusion error: Execution error: array_repeat: repeated inner array length exceeds capacity
select array_repeat([1, 2, 3], 9223372036854775807);
statement ok
drop table array_repeat_large_nested_null_table
include ./cleanup.slt.part