red-arrow 6.0.1 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/ext/arrow/arrow.cpp +12 -0
- data/ext/arrow/converters.hpp +49 -10
- data/ext/arrow/extconf.rb +7 -5
- data/ext/arrow/raw-records.cpp +3 -2
- data/ext/arrow/red-arrow.hpp +7 -0
- data/ext/arrow/values.cpp +3 -2
- data/lib/arrow/array-builder.rb +40 -6
- data/lib/arrow/array-computable.rb +37 -0
- data/lib/arrow/array.rb +16 -0
- data/lib/arrow/chunked-array.rb +21 -0
- data/lib/arrow/column.rb +28 -0
- data/lib/arrow/data-type.rb +2 -1
- data/lib/arrow/datum.rb +2 -0
- data/lib/arrow/day-time-interval-array-builder.rb +29 -0
- data/lib/arrow/decimal128-array-builder.rb +16 -6
- data/lib/arrow/decimal128.rb +14 -0
- data/lib/arrow/decimal256-array-builder.rb +16 -6
- data/lib/arrow/decimal256.rb +14 -0
- data/lib/arrow/field.rb +44 -3
- data/lib/arrow/function.rb +52 -0
- data/lib/arrow/list-data-type.rb +1 -6
- data/lib/arrow/loader.rb +19 -0
- data/lib/arrow/month-day-nano-interval-array-builder.rb +29 -0
- data/lib/arrow/s3-global-options.rb +38 -0
- data/lib/arrow/sort-key.rb +61 -55
- data/lib/arrow/sort-options.rb +8 -8
- data/lib/arrow/string-array-builder.rb +30 -0
- data/lib/arrow/table-loader.rb +99 -62
- data/lib/arrow/table-saver.rb +7 -2
- data/lib/arrow/table.rb +78 -0
- data/lib/arrow/time-unit.rb +31 -0
- data/lib/arrow/time32-array-builder.rb +2 -14
- data/lib/arrow/time32-data-type.rb +9 -38
- data/lib/arrow/time64-array-builder.rb +2 -14
- data/lib/arrow/time64-data-type.rb +9 -38
- data/lib/arrow/timestamp-array-builder.rb +2 -14
- data/lib/arrow/timestamp-data-type.rb +9 -34
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +2 -11
- data/test/helper.rb +2 -0
- data/test/raw-records/test-basic-arrays.rb +30 -0
- data/test/raw-records/test-dense-union-array.rb +27 -0
- data/test/raw-records/test-dictionary-array.rb +341 -0
- data/test/raw-records/test-list-array.rb +39 -0
- data/test/raw-records/test-map-array.rb +37 -0
- data/test/raw-records/test-sparse-union-array.rb +27 -0
- data/test/raw-records/test-struct-array.rb +30 -0
- data/test/test-array-builder.rb +62 -0
- data/test/test-chunked-array.rb +6 -0
- data/test/test-column.rb +31 -0
- data/test/test-decimal128-array-builder.rb +14 -0
- data/test/test-decimal128-array.rb +5 -2
- data/test/test-decimal128.rb +26 -2
- data/test/test-decimal256-array-builder.rb +14 -0
- data/test/test-decimal256-array.rb +5 -2
- data/test/test-decimal256.rb +26 -2
- data/test/test-field.rb +26 -0
- data/test/test-function.rb +48 -14
- data/test/test-table.rb +204 -6
- data/test/values/test-basic-arrays.rb +30 -0
- data/test/values/test-dense-union-array.rb +27 -0
- data/test/values/test-dictionary-array.rb +325 -0
- data/test/values/test-list-array.rb +39 -0
- data/test/values/test-map-array.rb +33 -0
- data/test/values/test-sparse-union-array.rb +27 -0
- data/test/values/test-struct-array.rb +30 -0
- metadata +95 -196
@@ -346,6 +346,36 @@ module RawRecordsBasicArraysTests
|
|
346
346
|
records)
|
347
347
|
assert_equal(records, target.raw_records)
|
348
348
|
end
|
349
|
+
|
350
|
+
def test_month_interval
|
351
|
+
records = [
|
352
|
+
[1],
|
353
|
+
[nil],
|
354
|
+
[12],
|
355
|
+
]
|
356
|
+
target = build({column: :month_interval}, records)
|
357
|
+
assert_equal(records, target.raw_records)
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_day_time_interval
|
361
|
+
records = [
|
362
|
+
[{day: 1, millisecond: 100}],
|
363
|
+
[nil],
|
364
|
+
[{day: 2, millisecond: 300}],
|
365
|
+
]
|
366
|
+
target = build({column: :day_time_interval}, records)
|
367
|
+
assert_equal(records, target.raw_records)
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_month_day_nano_interval
|
371
|
+
records = [
|
372
|
+
[{month: 1, day: 1, nanosecond: 100}],
|
373
|
+
[nil],
|
374
|
+
[{month: 2, day: 3, nanosecond: 400}],
|
375
|
+
]
|
376
|
+
target = build({column: :month_day_nano_interval}, records)
|
377
|
+
assert_equal(records, target.raw_records)
|
378
|
+
end
|
349
379
|
end
|
350
380
|
|
351
381
|
class RawRecordsRecordBatchBasicArraysTest < Test::Unit::TestCase
|
@@ -359,6 +359,33 @@ module RawRecordsDenseUnionArrayTests
|
|
359
359
|
assert_equal(records, target.raw_records)
|
360
360
|
end
|
361
361
|
|
362
|
+
def test_month_interval
|
363
|
+
records = [
|
364
|
+
[{"0" => 1}],
|
365
|
+
[{"1" => nil}],
|
366
|
+
]
|
367
|
+
target = build(:month_interval, records)
|
368
|
+
assert_equal(records, target.raw_records)
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_day_time_interval
|
372
|
+
records = [
|
373
|
+
[{"0" => {day: 1, millisecond: 100}}],
|
374
|
+
[{"1" => nil}],
|
375
|
+
]
|
376
|
+
target = build(:day_time_interval, records)
|
377
|
+
assert_equal(records, target.raw_records)
|
378
|
+
end
|
379
|
+
|
380
|
+
def test_month_day_nano_interval
|
381
|
+
records = [
|
382
|
+
[{"0" => {month: 1, day: 1, nanosecond: 100}}],
|
383
|
+
[{"1" => nil}],
|
384
|
+
]
|
385
|
+
target = build(:month_day_nano_interval, records)
|
386
|
+
assert_equal(records, target.raw_records)
|
387
|
+
end
|
388
|
+
|
362
389
|
def test_list
|
363
390
|
records = [
|
364
391
|
[{"0" => [true, nil, false]}],
|
@@ -0,0 +1,341 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
module RawRecordsDictionaryArrayTests
|
19
|
+
def build_record_batch(array)
|
20
|
+
dictionary = array.dictionary_encode
|
21
|
+
schema = Arrow::Schema.new(column: dictionary.value_data_type)
|
22
|
+
Arrow::RecordBatch.new(schema, array.length, [dictionary])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_null
|
26
|
+
records = [
|
27
|
+
[nil],
|
28
|
+
[nil],
|
29
|
+
[nil],
|
30
|
+
[nil],
|
31
|
+
]
|
32
|
+
target = build(Arrow::NullArray.new(records.collect(&:first)))
|
33
|
+
assert_equal(records, target.raw_records)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_boolean
|
37
|
+
records = [
|
38
|
+
[true],
|
39
|
+
[nil],
|
40
|
+
[false],
|
41
|
+
]
|
42
|
+
target = build(Arrow::BooleanArray.new(records.collect(&:first)))
|
43
|
+
assert_equal(records, target.raw_records)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_int8
|
47
|
+
records = [
|
48
|
+
[-(2 ** 7)],
|
49
|
+
[nil],
|
50
|
+
[(2 ** 7) - 1],
|
51
|
+
]
|
52
|
+
target = build(Arrow::Int8Array.new(records.collect(&:first)))
|
53
|
+
assert_equal(records, target.raw_records)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_uint8
|
57
|
+
records = [
|
58
|
+
[0],
|
59
|
+
[nil],
|
60
|
+
[(2 ** 8) - 1],
|
61
|
+
]
|
62
|
+
target = build(Arrow::UInt8Array.new(records.collect(&:first)))
|
63
|
+
assert_equal(records, target.raw_records)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_int16
|
67
|
+
records = [
|
68
|
+
[-(2 ** 15)],
|
69
|
+
[nil],
|
70
|
+
[(2 ** 15) - 1],
|
71
|
+
]
|
72
|
+
target = build(Arrow::Int16Array.new(records.collect(&:first)))
|
73
|
+
assert_equal(records, target.raw_records)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_uint16
|
77
|
+
records = [
|
78
|
+
[0],
|
79
|
+
[nil],
|
80
|
+
[(2 ** 16) - 1],
|
81
|
+
]
|
82
|
+
target = build(Arrow::UInt16Array.new(records.collect(&:first)))
|
83
|
+
assert_equal(records, target.raw_records)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_int32
|
87
|
+
records = [
|
88
|
+
[-(2 ** 31)],
|
89
|
+
[nil],
|
90
|
+
[(2 ** 31) - 1],
|
91
|
+
]
|
92
|
+
target = build(Arrow::Int32Array.new(records.collect(&:first)))
|
93
|
+
assert_equal(records, target.raw_records)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_uint32
|
97
|
+
records = [
|
98
|
+
[0],
|
99
|
+
[nil],
|
100
|
+
[(2 ** 32) - 1],
|
101
|
+
]
|
102
|
+
target = build(Arrow::UInt32Array.new(records.collect(&:first)))
|
103
|
+
assert_equal(records, target.raw_records)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_int64
|
107
|
+
records = [
|
108
|
+
[-(2 ** 63)],
|
109
|
+
[nil],
|
110
|
+
[(2 ** 63) - 1],
|
111
|
+
]
|
112
|
+
target = build(Arrow::Int64Array.new(records.collect(&:first)))
|
113
|
+
assert_equal(records, target.raw_records)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_uint64
|
117
|
+
records = [
|
118
|
+
[0],
|
119
|
+
[nil],
|
120
|
+
[(2 ** 64) - 1],
|
121
|
+
]
|
122
|
+
target = build(Arrow::UInt64Array.new(records.collect(&:first)))
|
123
|
+
assert_equal(records, target.raw_records)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_float
|
127
|
+
records = [
|
128
|
+
[-1.0],
|
129
|
+
[nil],
|
130
|
+
[1.0],
|
131
|
+
]
|
132
|
+
target = build(Arrow::FloatArray.new(records.collect(&:first)))
|
133
|
+
assert_equal(records, target.raw_records)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_double
|
137
|
+
records = [
|
138
|
+
[-1.0],
|
139
|
+
[nil],
|
140
|
+
[1.0],
|
141
|
+
]
|
142
|
+
target = build(Arrow::DoubleArray.new(records.collect(&:first)))
|
143
|
+
assert_equal(records, target.raw_records)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_binary
|
147
|
+
records = [
|
148
|
+
["\x00".b],
|
149
|
+
[nil],
|
150
|
+
["\xff".b],
|
151
|
+
]
|
152
|
+
target = build(Arrow::BinaryArray.new(records.collect(&:first)))
|
153
|
+
assert_equal(records, target.raw_records)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_string
|
157
|
+
records = [
|
158
|
+
["Ruby"],
|
159
|
+
[nil],
|
160
|
+
["\u3042"], # U+3042 HIRAGANA LETTER A
|
161
|
+
]
|
162
|
+
target = build(Arrow::StringArray.new(records.collect(&:first)))
|
163
|
+
assert_equal(records, target.raw_records)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_date32
|
167
|
+
records = [
|
168
|
+
[Date.new(1960, 1, 1)],
|
169
|
+
[nil],
|
170
|
+
[Date.new(2017, 8, 23)],
|
171
|
+
]
|
172
|
+
target = build(Arrow::Date32Array.new(records.collect(&:first)))
|
173
|
+
assert_equal(records, target.raw_records)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_date64
|
177
|
+
records = [
|
178
|
+
[DateTime.new(1960, 1, 1, 2, 9, 30)],
|
179
|
+
[nil],
|
180
|
+
[DateTime.new(2017, 8, 23, 14, 57, 2)],
|
181
|
+
]
|
182
|
+
target = build(Arrow::Date64Array.new(records.collect(&:first)))
|
183
|
+
assert_equal(records, target.raw_records)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_timestamp_second
|
187
|
+
records = [
|
188
|
+
[Time.parse("1960-01-01T02:09:30Z")],
|
189
|
+
[nil],
|
190
|
+
[Time.parse("2017-08-23T14:57:02Z")],
|
191
|
+
]
|
192
|
+
target = build(Arrow::TimestampArray.new(:second, records.collect(&:first)))
|
193
|
+
assert_equal(records, target.raw_records)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_timestamp_milli
|
197
|
+
records = [
|
198
|
+
[Time.parse("1960-01-01T02:09:30.123Z")],
|
199
|
+
[nil],
|
200
|
+
[Time.parse("2017-08-23T14:57:02.987Z")],
|
201
|
+
]
|
202
|
+
target = build(Arrow::TimestampArray.new(:milli, records.collect(&:first)))
|
203
|
+
assert_equal(records, target.raw_records)
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_timestamp_micro
|
207
|
+
records = [
|
208
|
+
[Time.parse("1960-01-01T02:09:30.123456Z")],
|
209
|
+
[nil],
|
210
|
+
[Time.parse("2017-08-23T14:57:02.987654Z")],
|
211
|
+
]
|
212
|
+
target = build(Arrow::TimestampArray.new(:micro, records.collect(&:first)))
|
213
|
+
assert_equal(records, target.raw_records)
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_timestamp_nano
|
217
|
+
records = [
|
218
|
+
[Time.parse("1960-01-01T02:09:30.123456789Z")],
|
219
|
+
[nil],
|
220
|
+
[Time.parse("2017-08-23T14:57:02.987654321Z")],
|
221
|
+
]
|
222
|
+
target = build(Arrow::TimestampArray.new(:nano, records.collect(&:first)))
|
223
|
+
assert_equal(records, target.raw_records)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_time32_second
|
227
|
+
unit = Arrow::TimeUnit::SECOND
|
228
|
+
records = [
|
229
|
+
[Arrow::Time.new(unit, 60 * 10)], # 00:10:00
|
230
|
+
[nil],
|
231
|
+
[Arrow::Time.new(unit, 60 * 60 * 2 + 9)], # 02:00:09
|
232
|
+
]
|
233
|
+
target = build(Arrow::Time32Array.new(unit, records.collect(&:first)))
|
234
|
+
assert_equal(records, target.raw_records)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_time32_milli
|
238
|
+
unit = Arrow::TimeUnit::MILLI
|
239
|
+
records = [
|
240
|
+
[Arrow::Time.new(unit, (60 * 10) * 1000 + 123)], # 00:10:00.123
|
241
|
+
[nil],
|
242
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1000 + 987)], # 02:00:09.987
|
243
|
+
]
|
244
|
+
target = build(Arrow::Time32Array.new(unit, records.collect(&:first)))
|
245
|
+
assert_equal(records, target.raw_records)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_time64_micro
|
249
|
+
unit = Arrow::TimeUnit::MICRO
|
250
|
+
records = [
|
251
|
+
# 00:10:00.123456
|
252
|
+
[Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456)],
|
253
|
+
[nil],
|
254
|
+
# 02:00:09.987654
|
255
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000 + 987_654)],
|
256
|
+
]
|
257
|
+
target = build(Arrow::Time64Array.new(unit, records.collect(&:first)))
|
258
|
+
assert_equal(records, target.raw_records)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_time64_nano
|
262
|
+
unit = Arrow::TimeUnit::NANO
|
263
|
+
records = [
|
264
|
+
# 00:10:00.123456789
|
265
|
+
[Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789)],
|
266
|
+
[nil],
|
267
|
+
# 02:00:09.987654321
|
268
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000_000 + 987_654_321)],
|
269
|
+
]
|
270
|
+
target = build(Arrow::Time64Array.new(unit, records.collect(&:first)))
|
271
|
+
assert_equal(records, target.raw_records)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_decimal128
|
275
|
+
records = [
|
276
|
+
[BigDecimal("92.92")],
|
277
|
+
[nil],
|
278
|
+
[BigDecimal("29.29")],
|
279
|
+
]
|
280
|
+
data_type = Arrow::Decimal128DataType.new(8, 2)
|
281
|
+
target = build(Arrow::Decimal128Array.new(data_type, records.collect(&:first)))
|
282
|
+
assert_equal(records, target.raw_records)
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_decimal256
|
286
|
+
records = [
|
287
|
+
[BigDecimal("92.92")],
|
288
|
+
[nil],
|
289
|
+
[BigDecimal("29.29")],
|
290
|
+
]
|
291
|
+
data_type = Arrow::Decimal256DataType.new(38, 2)
|
292
|
+
target = build(Arrow::Decimal256Array.new(data_type, records.collect(&:first)))
|
293
|
+
assert_equal(records, target.raw_records)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_month_interval
|
297
|
+
records = [
|
298
|
+
[1],
|
299
|
+
[nil],
|
300
|
+
[12],
|
301
|
+
]
|
302
|
+
target = build(Arrow::MonthIntervalArray.new(records.collect(&:first)))
|
303
|
+
assert_equal(records, target.raw_records)
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_day_time_interval
|
307
|
+
records = [
|
308
|
+
[{day: 1, millisecond: 100}],
|
309
|
+
[nil],
|
310
|
+
[{day: 2, millisecond: 300}],
|
311
|
+
]
|
312
|
+
target = build(Arrow::DayTimeIntervalArray.new(records.collect(&:first)))
|
313
|
+
assert_equal(records, target.raw_records)
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_month_day_nano_interval
|
317
|
+
records = [
|
318
|
+
[{month: 1, day: 1, nanosecond: 100}],
|
319
|
+
[nil],
|
320
|
+
[{month: 2, day: 3, nanosecond: 400}],
|
321
|
+
]
|
322
|
+
target = build(Arrow::MonthDayNanoIntervalArray.new(records.collect(&:first)))
|
323
|
+
assert_equal(records, target.raw_records)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class RawRecordsRecordBatchDictionaryArraysTest < Test::Unit::TestCase
|
328
|
+
include RawRecordsDictionaryArrayTests
|
329
|
+
|
330
|
+
def build(array)
|
331
|
+
build_record_batch(array)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class RawRecordsTableDictionaryArraysTest < Test::Unit::TestCase
|
336
|
+
include RawRecordsDictionaryArrayTests
|
337
|
+
|
338
|
+
def build(array)
|
339
|
+
build_record_batch(array).to_table
|
340
|
+
end
|
341
|
+
end
|
@@ -399,6 +399,45 @@ module RawRecordsListArrayTests
|
|
399
399
|
assert_equal(records, target.raw_records)
|
400
400
|
end
|
401
401
|
|
402
|
+
def test_month_interval
|
403
|
+
records = [
|
404
|
+
[[1, nil, 12]],
|
405
|
+
[nil],
|
406
|
+
]
|
407
|
+
target = build(:month_interval, records)
|
408
|
+
assert_equal(records, target.raw_records)
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_day_time_interval
|
412
|
+
records = [
|
413
|
+
[
|
414
|
+
[
|
415
|
+
{day: 1, millisecond: 100},
|
416
|
+
nil,
|
417
|
+
{day: 2, millisecond: 300},
|
418
|
+
]
|
419
|
+
],
|
420
|
+
[nil],
|
421
|
+
]
|
422
|
+
target = build(:day_time_interval, records)
|
423
|
+
assert_equal(records, target.raw_records)
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_month_day_nano_interval
|
427
|
+
records = [
|
428
|
+
[
|
429
|
+
[
|
430
|
+
{month: 1, day: 1, nanosecond: 100},
|
431
|
+
nil,
|
432
|
+
{month: 2, day: 3, nanosecond: 400},
|
433
|
+
]
|
434
|
+
],
|
435
|
+
[nil],
|
436
|
+
]
|
437
|
+
target = build(:month_day_nano_interval, records)
|
438
|
+
assert_equal(records, target.raw_records)
|
439
|
+
end
|
440
|
+
|
402
441
|
def test_list
|
403
442
|
records = [
|
404
443
|
[
|
@@ -310,6 +310,43 @@ module RawRecordsMapArrayTests
|
|
310
310
|
assert_equal(records, target.raw_records)
|
311
311
|
end
|
312
312
|
|
313
|
+
def test_month_interval
|
314
|
+
records = [
|
315
|
+
[{"key1" => 1, "key2" => nil}],
|
316
|
+
[nil],
|
317
|
+
]
|
318
|
+
target = build(:month_interval, records)
|
319
|
+
assert_equal(records, target.raw_records)
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_day_time_interval
|
323
|
+
records = [
|
324
|
+
[
|
325
|
+
{
|
326
|
+
"key1" => {day: 1, millisecond: 100},
|
327
|
+
"key2" => nil,
|
328
|
+
},
|
329
|
+
],
|
330
|
+
[nil],
|
331
|
+
]
|
332
|
+
target = build(:day_time_interval, records)
|
333
|
+
assert_equal(records, target.raw_records)
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_month_day_nano_interval
|
337
|
+
records = [
|
338
|
+
[
|
339
|
+
{
|
340
|
+
"key1" => {month: 1, day: 1, nanosecond: 100},
|
341
|
+
"key2" => nil,
|
342
|
+
},
|
343
|
+
],
|
344
|
+
[nil],
|
345
|
+
]
|
346
|
+
target = build(:month_day_nano_interval, records)
|
347
|
+
assert_equal(records, target.raw_records)
|
348
|
+
end
|
349
|
+
|
313
350
|
def test_list
|
314
351
|
records = [
|
315
352
|
[{"key1" => [true, nil, false], "key2" => nil}],
|
@@ -349,6 +349,33 @@ module RawRecordsSparseUnionArrayTests
|
|
349
349
|
assert_equal(records, target.raw_records)
|
350
350
|
end
|
351
351
|
|
352
|
+
def test_month_interval
|
353
|
+
records = [
|
354
|
+
[{"0" => 1}],
|
355
|
+
[{"1" => nil}],
|
356
|
+
]
|
357
|
+
target = build(:month_interval, records)
|
358
|
+
assert_equal(records, target.raw_records)
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_day_time_interval
|
362
|
+
records = [
|
363
|
+
[{"0" => {day: 1, millisecond: 100}}],
|
364
|
+
[{"1" => nil}],
|
365
|
+
]
|
366
|
+
target = build(:day_time_interval, records)
|
367
|
+
assert_equal(records, target.raw_records)
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_month_day_nano_interval
|
371
|
+
records = [
|
372
|
+
[{"0" => {month: 1, day: 1, nanosecond: 100}}],
|
373
|
+
[{"1" => nil}],
|
374
|
+
]
|
375
|
+
target = build(:month_day_nano_interval, records)
|
376
|
+
assert_equal(records, target.raw_records)
|
377
|
+
end
|
378
|
+
|
352
379
|
def test_list
|
353
380
|
records = [
|
354
381
|
[{"0" => [true, nil, false]}],
|
@@ -344,6 +344,36 @@ module RawRecordsStructArrayTests
|
|
344
344
|
assert_equal(records, target.raw_records)
|
345
345
|
end
|
346
346
|
|
347
|
+
def test_month_interval
|
348
|
+
records = [
|
349
|
+
[{"field" => 1}],
|
350
|
+
[nil],
|
351
|
+
[{"field" => nil}],
|
352
|
+
]
|
353
|
+
target = build(:month_interval, records)
|
354
|
+
assert_equal(records, target.raw_records)
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_day_time_interval
|
358
|
+
records = [
|
359
|
+
[{"field" => {day: 1, millisecond: 100}}],
|
360
|
+
[nil],
|
361
|
+
[{"field" => nil}],
|
362
|
+
]
|
363
|
+
target = build(:day_time_interval, records)
|
364
|
+
assert_equal(records, target.raw_records)
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_month_day_nano_interval
|
368
|
+
records = [
|
369
|
+
[{"field" => {month: 1, day: 1, nanosecond: 100}}],
|
370
|
+
[nil],
|
371
|
+
[{"field" => nil}],
|
372
|
+
]
|
373
|
+
target = build(:month_day_nano_interval, records)
|
374
|
+
assert_equal(records, target.raw_records)
|
375
|
+
end
|
376
|
+
|
347
377
|
def test_list
|
348
378
|
records = [
|
349
379
|
[{"field" => [true, nil, false]}],
|
data/test/test-array-builder.rb
CHANGED
@@ -68,6 +68,68 @@ class ArrayBuilderTest < Test::Unit::TestCase
|
|
68
68
|
])
|
69
69
|
end
|
70
70
|
|
71
|
+
test("decimal + string") do
|
72
|
+
raw_array = [BigDecimal("10.1"), "10.1"]
|
73
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
74
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
75
|
+
end
|
76
|
+
|
77
|
+
test("NaN") do
|
78
|
+
raw_array = [BigDecimal("10.1"), BigDecimal::NAN]
|
79
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
80
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
81
|
+
end
|
82
|
+
|
83
|
+
test("Infinity") do
|
84
|
+
raw_array = [BigDecimal("10.1"), BigDecimal::INFINITY]
|
85
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
86
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
87
|
+
end
|
88
|
+
|
89
|
+
test("decimal128") do
|
90
|
+
values = [
|
91
|
+
BigDecimal("10.1"),
|
92
|
+
BigDecimal("1.11"),
|
93
|
+
BigDecimal("1"),
|
94
|
+
]
|
95
|
+
array = Arrow::Array.new(values)
|
96
|
+
data_type = Arrow::Decimal128DataType.new(3, 2)
|
97
|
+
assert_equal({
|
98
|
+
data_type: data_type,
|
99
|
+
values: [
|
100
|
+
BigDecimal("10.1"),
|
101
|
+
BigDecimal("1.11"),
|
102
|
+
BigDecimal("1"),
|
103
|
+
],
|
104
|
+
},
|
105
|
+
{
|
106
|
+
data_type: array.value_data_type,
|
107
|
+
values: array.to_a,
|
108
|
+
})
|
109
|
+
end
|
110
|
+
|
111
|
+
test("decimal256") do
|
112
|
+
values = [
|
113
|
+
BigDecimal("1" * 40 + ".1"),
|
114
|
+
BigDecimal("1" * 38 + ".11"),
|
115
|
+
BigDecimal("1" * 37),
|
116
|
+
]
|
117
|
+
array = Arrow::Array.new(values)
|
118
|
+
data_type = Arrow::Decimal256DataType.new(41, 2)
|
119
|
+
assert_equal({
|
120
|
+
data_type: data_type,
|
121
|
+
values: [
|
122
|
+
BigDecimal("1" * 40 + ".1"),
|
123
|
+
BigDecimal("1" * 38 + ".11"),
|
124
|
+
BigDecimal("1" * 37),
|
125
|
+
],
|
126
|
+
},
|
127
|
+
{
|
128
|
+
data_type: array.value_data_type,
|
129
|
+
values: array.to_a,
|
130
|
+
})
|
131
|
+
end
|
132
|
+
|
71
133
|
test("list<boolean>s") do
|
72
134
|
assert_build(Arrow::ArrayBuilder,
|
73
135
|
[
|
data/test/test-chunked-array.rb
CHANGED
@@ -180,4 +180,10 @@ class ChunkedArrayTest < Test::Unit::TestCase
|
|
180
180
|
@chunked_array.take(indices))
|
181
181
|
end
|
182
182
|
end
|
183
|
+
|
184
|
+
test("#cast") do
|
185
|
+
chunked_array = Arrow::ChunkedArray.new([[1, nil, 3]])
|
186
|
+
assert_equal(Arrow::ChunkedArray.new([["1", nil, "3"]]),
|
187
|
+
chunked_array.cast(:string))
|
188
|
+
end
|
183
189
|
end
|
data/test/test-column.rb
CHANGED
@@ -89,4 +89,35 @@ class ColumnTest < Test::Unit::TestCase
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
test("#count") do
|
94
|
+
table = Arrow::Table.new("revenue" => [1, nil, 3])
|
95
|
+
assert_equal(2, table["revenue"].count)
|
96
|
+
end
|
97
|
+
|
98
|
+
test("#min") do
|
99
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
100
|
+
assert_equal(1, table["revenue"].min)
|
101
|
+
end
|
102
|
+
|
103
|
+
test("#max") do
|
104
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
105
|
+
assert_equal(3, table["revenue"].max)
|
106
|
+
end
|
107
|
+
|
108
|
+
test("#sum") do
|
109
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
110
|
+
assert_equal(6, table["revenue"].sum)
|
111
|
+
end
|
112
|
+
|
113
|
+
test("#uniq") do
|
114
|
+
table = Arrow::Table.new("revenue" => [1, 2, 2])
|
115
|
+
assert_equal([1, 2], table["revenue"].uniq)
|
116
|
+
end
|
117
|
+
|
118
|
+
test("#cast") do
|
119
|
+
table = Arrow::Table.new("revenue" => [1, nil, 3])
|
120
|
+
assert_equal(Arrow::ChunkedArray.new([["1", nil, "3"]]),
|
121
|
+
table["revenue"].cast(:string))
|
122
|
+
end
|
92
123
|
end
|
@@ -55,6 +55,20 @@ class Decimal128ArrayBuilderTest < Test::Unit::TestCase
|
|
55
55
|
assert_equal(BigDecimal("10.1"),
|
56
56
|
array[0])
|
57
57
|
end
|
58
|
+
|
59
|
+
test("BigDecimal::NAN") do
|
60
|
+
message = "can't use NaN as an Arrow::Decimal128Array value"
|
61
|
+
assert_raise(FloatDomainError.new(message)) do
|
62
|
+
@builder.append_value(BigDecimal::NAN)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test("BigDecimal::INFINITY") do
|
67
|
+
message = "can't use Infinity as an Arrow::Decimal128Array value"
|
68
|
+
assert_raise(FloatDomainError.new(message)) do
|
69
|
+
@builder.append_value(BigDecimal::INFINITY)
|
70
|
+
end
|
71
|
+
end
|
58
72
|
end
|
59
73
|
|
60
74
|
sub_test_case("#append_values") do
|