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
|
# 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.
module ValuesBasicArraysTests
def test_null
target = build(Arrow::NullArray.new(4))
assert_equal([nil] * 4, target.values)
end
def test_boolean
values = [true, nil, false]
target = build(Arrow::BooleanArray.new(values))
assert_equal(values, target.values)
end
def test_int8
values = [
-(2 ** 7),
nil,
(2 ** 7) - 1,
]
target = build(Arrow::Int8Array.new(values))
assert_equal(values, target.values)
end
def test_uint8
values = [
0,
nil,
(2 ** 8) - 1,
]
target = build(Arrow::UInt8Array.new(values))
assert_equal(values, target.values)
end
def test_int16
values = [
-(2 ** 15),
nil,
(2 ** 15) - 1,
]
target = build(Arrow::Int16Array.new(values))
assert_equal(values, target.values)
end
def test_uint16
values = [
0,
nil,
(2 ** 16) - 1,
]
target = build(Arrow::UInt16Array.new(values))
assert_equal(values, target.values)
end
def test_int32
values = [
-(2 ** 31),
nil,
(2 ** 31) - 1,
]
target = build(Arrow::Int32Array.new(values))
assert_equal(values, target.values)
end
def test_uint32
values = [
0,
nil,
(2 ** 32) - 1,
]
target = build(Arrow::UInt32Array.new(values))
assert_equal(values, target.values)
end
def test_int64
values = [
-(2 ** 63),
nil,
(2 ** 63) - 1,
]
target = build(Arrow::Int64Array.new(values))
assert_equal(values, target.values)
end
def test_uint64
values = [
0,
nil,
(2 ** 64) - 1,
]
target = build(Arrow::UInt64Array.new(values))
assert_equal(values, target.values)
end
def test_float
values = [
-1.0,
nil,
1.0,
]
target = build(Arrow::FloatArray.new(values))
assert_equal(values, target.values)
end
def test_double
values = [
-1.0,
nil,
1.0,
]
target = build(Arrow::DoubleArray.new(values))
assert_equal(values, target.values)
end
def test_binary
values = [
"\x00".b,
nil,
"\xff".b,
]
target = build(Arrow::BinaryArray.new(values))
assert_equal(values, target.values)
end
def test_tring
values = [
"Ruby",
nil,
"\u3042", # U+3042 HIRAGANA LETTER A
]
target = build(Arrow::StringArray.new(values))
assert_equal(values, target.values)
end
def test_date32
values = [
Date.new(1960, 1, 1),
nil,
Date.new(2017, 8, 23),
]
target = build(Arrow::Date32Array.new(values))
assert_equal(values, target.values)
end
def test_date64
values = [
DateTime.new(1960, 1, 1, 2, 9, 30),
nil,
DateTime.new(2017, 8, 23, 14, 57, 2),
]
target = build(Arrow::Date64Array.new(values))
assert_equal(values, target.values)
end
def test_timestamp_second
values = [
Time.parse("1960-01-01T02:09:30Z"),
nil,
Time.parse("2017-08-23T14:57:02Z"),
]
target = build(Arrow::TimestampArray.new(:second, values))
assert_equal(values, target.values)
end
def test_timestamp_milli
values = [
Time.parse("1960-01-01T02:09:30.123Z"),
nil,
Time.parse("2017-08-23T14:57:02.987Z"),
]
target = build(Arrow::TimestampArray.new(:milli, values))
assert_equal(values, target.values)
end
def test_timestamp_micro
values = [
Time.parse("1960-01-01T02:09:30.123456Z"),
nil,
Time.parse("2017-08-23T14:57:02.987654Z"),
]
target = build(Arrow::TimestampArray.new(:micro, values))
assert_equal(values, target.values)
end
def test_timestamp_nano
values = [
Time.parse("1960-01-01T02:09:30.123456789Z"),
nil,
Time.parse("2017-08-23T14:57:02.987654321Z"),
]
target = build(Arrow::TimestampArray.new(:nano, values))
assert_equal(values, target.values)
end
def test_time32_second
unit = Arrow::TimeUnit::SECOND
values = [
Arrow::Time.new(unit, 60 * 10), # 00:10:00
nil,
Arrow::Time.new(unit, 60 * 60 * 2 + 9), # 02:00:09
]
target = build(Arrow::Time32Array.new(:second, values))
assert_equal(values, target.values)
end
def test_time32_milli
unit = Arrow::TimeUnit::MILLI
values = [
Arrow::Time.new(unit, (60 * 10) * 1000 + 123), # 00:10:00.123
nil,
Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1000 + 987), # 02:00:09.987
]
target = build(Arrow::Time32Array.new(:milli, values))
assert_equal(values, target.values)
end
def test_time64_micro
unit = Arrow::TimeUnit::MICRO
values = [
# 00:10:00.123456
Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456),
nil,
# 02:00:09.987654
Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000 + 987_654),
]
target = build(Arrow::Time64Array.new(:micro, values))
assert_equal(values, target.values)
end
def test_time64_nano
unit = Arrow::TimeUnit::NANO
values = [
# 00:10:00.123456789
Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789),
nil,
# 02:00:09.987654321
Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000_000 + 987_654_321),
]
target = build(Arrow::Time64Array.new(:nano, values))
assert_equal(values, target.values)
end
def test_decimal128
values = [
BigDecimal("92.92"),
nil,
BigDecimal("29.29"),
]
data_type = Arrow::Decimal128DataType.new(8, 2)
target = build(Arrow::Decimal128Array.new(data_type, values))
assert_equal(values, target.values)
end
def test_decimal256
values = [
BigDecimal("92.92"),
nil,
BigDecimal("29.29"),
]
data_type = Arrow::Decimal256DataType.new(38, 2)
target = build(Arrow::Decimal256Array.new(data_type, values))
assert_equal(values, target.values)
end
end
class ValuesArrayBasicArraysTest < Test::Unit::TestCase
include ValuesBasicArraysTests
def build(array)
array
end
end
class ValuesChunkedArrayBasicArraysTest < Test::Unit::TestCase
include ValuesBasicArraysTests
def build(array)
Arrow::ChunkedArray.new([array])
end
end
|