red-arrow 2.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/arrow/arrow.cpp +3 -0
- data/ext/arrow/converters.hpp +15 -2
- data/ext/arrow/memory-view.cpp +311 -0
- data/ext/arrow/memory-view.hpp +26 -0
- data/ext/arrow/raw-records.cpp +1 -0
- data/ext/arrow/values.cpp +1 -0
- data/lib/arrow/array-builder.rb +11 -6
- data/lib/arrow/array.rb +130 -0
- data/lib/arrow/bigdecimal-extension.rb +5 -1
- data/lib/arrow/buffer.rb +10 -6
- data/lib/arrow/constructor-arguments-gc-guardable.rb +25 -0
- data/lib/arrow/data-type.rb +14 -5
- data/lib/arrow/datum.rb +98 -0
- data/lib/arrow/decimal128-array-builder.rb +21 -25
- data/lib/arrow/decimal128-data-type.rb +2 -0
- data/lib/arrow/decimal128.rb +18 -0
- data/lib/arrow/decimal256-array-builder.rb +61 -0
- data/lib/arrow/decimal256-array.rb +25 -0
- data/lib/arrow/decimal256-data-type.rb +73 -0
- data/lib/arrow/decimal256.rb +60 -0
- data/lib/arrow/dense-union-data-type.rb +2 -2
- data/lib/arrow/dictionary-data-type.rb +2 -2
- data/lib/arrow/equal-options.rb +38 -0
- data/lib/arrow/fixed-size-binary-array-builder.rb +38 -0
- data/lib/arrow/fixed-size-binary-array.rb +26 -0
- data/lib/arrow/loader.rb +46 -0
- data/lib/arrow/scalar.rb +32 -0
- data/lib/arrow/sort-key.rb +193 -0
- data/lib/arrow/sort-options.rb +109 -0
- data/lib/arrow/sparse-union-data-type.rb +2 -2
- data/lib/arrow/table.rb +2 -2
- data/lib/arrow/time32-data-type.rb +2 -2
- data/lib/arrow/time64-data-type.rb +2 -2
- data/lib/arrow/timestamp-data-type.rb +2 -2
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +3 -1
- data/test/helper.rb +1 -0
- data/test/raw-records/test-basic-arrays.rb +17 -0
- data/test/raw-records/test-dense-union-array.rb +14 -0
- data/test/raw-records/test-list-array.rb +20 -0
- data/test/raw-records/test-sparse-union-array.rb +14 -0
- data/test/raw-records/test-struct-array.rb +15 -0
- data/test/test-array.rb +156 -2
- data/test/test-bigdecimal.rb +20 -3
- data/test/test-boolean-scalar.rb +26 -0
- data/test/test-decimal128-array-builder.rb +18 -1
- data/test/test-decimal128-data-type.rb +2 -2
- data/test/test-decimal128.rb +38 -0
- data/test/test-decimal256-array-builder.rb +112 -0
- data/test/test-decimal256-array.rb +38 -0
- data/test/test-decimal256-data-type.rb +31 -0
- data/test/test-decimal256.rb +102 -0
- data/test/test-fixed-size-binary-array-builder.rb +92 -0
- data/test/test-fixed-size-binary-array.rb +36 -0
- data/test/test-float-scalar.rb +46 -0
- data/test/test-function.rb +176 -0
- data/test/test-memory-view.rb +434 -0
- data/test/test-orc.rb +19 -23
- data/test/test-sort-indices.rb +40 -0
- data/test/test-sort-key.rb +81 -0
- data/test/test-sort-options.rb +58 -0
- data/test/test-struct-array-builder.rb +8 -8
- data/test/test-struct-array.rb +2 -2
- data/test/values/test-basic-arrays.rb +11 -0
- data/test/values/test-dense-union-array.rb +14 -0
- data/test/values/test-list-array.rb +18 -0
- data/test/values/test-sparse-union-array.rb +14 -0
- data/test/values/test-struct-array.rb +15 -0
- metadata +127 -59
data/test/helper.rb
CHANGED
@@ -329,6 +329,23 @@ module RawRecordsBasicArraysTests
|
|
329
329
|
records)
|
330
330
|
assert_equal(records, target.raw_records)
|
331
331
|
end
|
332
|
+
|
333
|
+
def test_decimal256
|
334
|
+
records = [
|
335
|
+
[BigDecimal("92.92")],
|
336
|
+
[nil],
|
337
|
+
[BigDecimal("29.29")],
|
338
|
+
]
|
339
|
+
target = build({
|
340
|
+
column: {
|
341
|
+
type: :decimal256,
|
342
|
+
precision: 38,
|
343
|
+
scale: 2,
|
344
|
+
}
|
345
|
+
},
|
346
|
+
records)
|
347
|
+
assert_equal(records, target.raw_records)
|
348
|
+
end
|
332
349
|
end
|
333
350
|
|
334
351
|
class RawRecordsRecordBatchBasicArraysTest < Test::Unit::TestCase
|
@@ -345,6 +345,20 @@ module RawRecordsDenseUnionArrayTests
|
|
345
345
|
assert_equal(records, target.raw_records)
|
346
346
|
end
|
347
347
|
|
348
|
+
def test_decimal256
|
349
|
+
records = [
|
350
|
+
[{"0" => BigDecimal("92.92")}],
|
351
|
+
[{"1" => nil}],
|
352
|
+
]
|
353
|
+
target = build({
|
354
|
+
type: :decimal256,
|
355
|
+
precision: 38,
|
356
|
+
scale: 2,
|
357
|
+
},
|
358
|
+
records)
|
359
|
+
assert_equal(records, target.raw_records)
|
360
|
+
end
|
361
|
+
|
348
362
|
def test_list
|
349
363
|
records = [
|
350
364
|
[{"0" => [true, nil, false]}],
|
@@ -379,6 +379,26 @@ module RawRecordsListArrayTests
|
|
379
379
|
assert_equal(records, target.raw_records)
|
380
380
|
end
|
381
381
|
|
382
|
+
def test_decimal256
|
383
|
+
records = [
|
384
|
+
[
|
385
|
+
[
|
386
|
+
BigDecimal("92.92"),
|
387
|
+
nil,
|
388
|
+
BigDecimal("29.29"),
|
389
|
+
],
|
390
|
+
],
|
391
|
+
[nil],
|
392
|
+
]
|
393
|
+
target = build({
|
394
|
+
type: :decimal256,
|
395
|
+
precision: 38,
|
396
|
+
scale: 2,
|
397
|
+
},
|
398
|
+
records)
|
399
|
+
assert_equal(records, target.raw_records)
|
400
|
+
end
|
401
|
+
|
382
402
|
def test_list
|
383
403
|
records = [
|
384
404
|
[
|
@@ -335,6 +335,20 @@ module RawRecordsSparseUnionArrayTests
|
|
335
335
|
assert_equal(records, target.raw_records)
|
336
336
|
end
|
337
337
|
|
338
|
+
def test_decimal256
|
339
|
+
records = [
|
340
|
+
[{"0" => BigDecimal("92.92")}],
|
341
|
+
[{"1" => nil}],
|
342
|
+
]
|
343
|
+
target = build({
|
344
|
+
type: :decimal256,
|
345
|
+
precision: 38,
|
346
|
+
scale: 2,
|
347
|
+
},
|
348
|
+
records)
|
349
|
+
assert_equal(records, target.raw_records)
|
350
|
+
end
|
351
|
+
|
338
352
|
def test_list
|
339
353
|
records = [
|
340
354
|
[{"0" => [true, nil, false]}],
|
@@ -329,6 +329,21 @@ module RawRecordsStructArrayTests
|
|
329
329
|
assert_equal(records, target.raw_records)
|
330
330
|
end
|
331
331
|
|
332
|
+
def test_decimal256
|
333
|
+
records = [
|
334
|
+
[{"field" => BigDecimal("92.92")}],
|
335
|
+
[nil],
|
336
|
+
[{"field" => nil}],
|
337
|
+
]
|
338
|
+
target = build({
|
339
|
+
type: :decimal256,
|
340
|
+
precision: 38,
|
341
|
+
scale: 2,
|
342
|
+
},
|
343
|
+
records)
|
344
|
+
assert_equal(records, target.raw_records)
|
345
|
+
end
|
346
|
+
|
332
347
|
def test_list
|
333
348
|
records = [
|
334
349
|
[{"field" => [true, nil, false]}],
|
data/test/test-array.rb
CHANGED
@@ -64,6 +64,40 @@ class ArrayTest < Test::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
sub_test_case("#equal_array?") do
|
68
|
+
test("no options") do
|
69
|
+
array1 = Arrow::FloatArray.new([1.1, Float::NAN])
|
70
|
+
array2 = Arrow::FloatArray.new([1.1, Float::NAN])
|
71
|
+
assert do
|
72
|
+
not array1.equal_array?(array2)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
test("approx") do
|
77
|
+
array1 = Arrow::FloatArray.new([1.1])
|
78
|
+
array2 = Arrow::FloatArray.new([1.100001])
|
79
|
+
assert do
|
80
|
+
array1.equal_array?(array2, approx: true)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test("nans-equal") do
|
85
|
+
array1 = Arrow::FloatArray.new([1.1, Float::NAN])
|
86
|
+
array2 = Arrow::FloatArray.new([1.1, Float::NAN])
|
87
|
+
assert do
|
88
|
+
array1.equal_array?(array2, nans_equal: true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test("absolute-tolerance") do
|
93
|
+
array1 = Arrow::FloatArray.new([1.1])
|
94
|
+
array2 = Arrow::FloatArray.new([1.101])
|
95
|
+
assert do
|
96
|
+
array1.equal_array?(array2, approx: true, absolute_tolerance: 0.01)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
67
101
|
sub_test_case("#cast") do
|
68
102
|
test("Symbol") do
|
69
103
|
assert_equal(Arrow::Int32Array.new([1, 2, 3]),
|
@@ -160,12 +194,132 @@ class ArrayTest < Test::Unit::TestCase
|
|
160
194
|
|
161
195
|
test("Arrow::ChunkedArray") do
|
162
196
|
chunks = [
|
163
|
-
Arrow::Int16Array.new([1,
|
164
|
-
Arrow::Int16Array.new([
|
197
|
+
Arrow::Int16Array.new([1, 4]),
|
198
|
+
Arrow::Int16Array.new([0, 3])
|
165
199
|
]
|
166
200
|
right = Arrow::ChunkedArray.new(chunks)
|
167
201
|
assert_equal(Arrow::BooleanArray.new([true, true, true, false]),
|
168
202
|
@array.is_in(right))
|
169
203
|
end
|
170
204
|
end
|
205
|
+
|
206
|
+
sub_test_case("#concatenate") do
|
207
|
+
test("Arrow::Array: same") do
|
208
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
|
209
|
+
Arrow::Int32Array.new([1, 2, nil]).
|
210
|
+
concatenate(Arrow::Int32Array.new([4, 5]),
|
211
|
+
Arrow::Int32Array.new([6])))
|
212
|
+
end
|
213
|
+
|
214
|
+
test("Arrow::Array: castable") do
|
215
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
|
216
|
+
Arrow::Int32Array.new([1, 2, nil]).
|
217
|
+
concatenate(Arrow::Int8Array.new([4, 5]),
|
218
|
+
Arrow::UInt32Array.new([6])))
|
219
|
+
end
|
220
|
+
|
221
|
+
test("Arrow::Array: non-castable") do
|
222
|
+
assert_raise(Arrow::Error::Invalid) do
|
223
|
+
Arrow::Int32Array.new([1, 2, nil]).
|
224
|
+
concatenate(Arrow::StringArray.new(["X"]))
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
test("Array") do
|
229
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,nil, 6]),
|
230
|
+
Arrow::Int32Array.new([1, 2, nil]).
|
231
|
+
concatenate([4, nil],
|
232
|
+
[6]))
|
233
|
+
end
|
234
|
+
|
235
|
+
test("invalid") do
|
236
|
+
message = "[array][resolve] can't build int32 array: 4"
|
237
|
+
assert_raise(ArgumentError.new(message)) do
|
238
|
+
Arrow::Int32Array.new([1, 2, nil]).
|
239
|
+
concatenate(4)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
sub_test_case("#+") do
|
245
|
+
test("Arrow::Array: same") do
|
246
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
|
247
|
+
Arrow::Int32Array.new([1, 2, nil]) +
|
248
|
+
Arrow::Int32Array.new([4, 5, 6]))
|
249
|
+
end
|
250
|
+
|
251
|
+
test("Arrow::Array: castable") do
|
252
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
|
253
|
+
Arrow::Int32Array.new([1, 2, nil]) +
|
254
|
+
Arrow::Int8Array.new([4, 5, 6]))
|
255
|
+
end
|
256
|
+
|
257
|
+
test("Arrow::Array: non-castable") do
|
258
|
+
assert_raise(Arrow::Error::Invalid) do
|
259
|
+
Arrow::Int32Array.new([1, 2, nil]) +
|
260
|
+
Arrow::StringArray.new(["X"])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
test("Array") do
|
265
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,nil, 6]),
|
266
|
+
Arrow::Int32Array.new([1, 2, nil]) +
|
267
|
+
[4, nil, 6])
|
268
|
+
end
|
269
|
+
|
270
|
+
test("invalid") do
|
271
|
+
message = "[array][resolve] can't build int32 array: 4"
|
272
|
+
assert_raise(ArgumentError.new(message)) do
|
273
|
+
Arrow::Int32Array.new([1, 2, nil]) + 4
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
sub_test_case("#resolve") do
|
279
|
+
test("Arrow::Array: same") do
|
280
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil]),
|
281
|
+
Arrow::Int32Array.new([]).
|
282
|
+
resolve(Arrow::Int32Array.new([1, 2, nil])))
|
283
|
+
end
|
284
|
+
|
285
|
+
test("Arrow::Array: castable") do
|
286
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil]),
|
287
|
+
Arrow::Int32Array.new([]).
|
288
|
+
resolve(Arrow::Int8Array.new([1, 2, nil])))
|
289
|
+
end
|
290
|
+
|
291
|
+
test("Arrow::Array: non-castable") do
|
292
|
+
assert_raise(Arrow::Error::Invalid) do
|
293
|
+
Arrow::Int32Array.new([]) +
|
294
|
+
Arrow::StringArray.new(["X"])
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
test("Array: non-parametric") do
|
299
|
+
assert_equal(Arrow::Int32Array.new([1, 2, nil]),
|
300
|
+
Arrow::Int32Array.new([]).
|
301
|
+
resolve([1, 2, nil]))
|
302
|
+
end
|
303
|
+
|
304
|
+
test("Array: parametric") do
|
305
|
+
list_data_type = Arrow::ListDataType.new(name: "visible", type: :boolean)
|
306
|
+
list_array = Arrow::ListArray.new(list_data_type, [])
|
307
|
+
assert_equal(Arrow::ListArray.new(list_data_type,
|
308
|
+
[
|
309
|
+
[true, false],
|
310
|
+
nil,
|
311
|
+
]),
|
312
|
+
list_array.resolve([
|
313
|
+
[true, false],
|
314
|
+
nil,
|
315
|
+
]))
|
316
|
+
end
|
317
|
+
|
318
|
+
test("invalid") do
|
319
|
+
message = "[array][resolve] can't build int32 array: 4"
|
320
|
+
assert_raise(ArgumentError.new(message)) do
|
321
|
+
Arrow::Int32Array.new([]).resolve(4)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
171
325
|
end
|
data/test/test-bigdecimal.rb
CHANGED
@@ -16,8 +16,25 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
class BigDecimalTest < Test::Unit::TestCase
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
sub_test_case("#to_arrow") do
|
20
|
+
def test_128_positive
|
21
|
+
assert_equal(Arrow::Decimal128.new("0.1e38"),
|
22
|
+
BigDecimal("0.1e38").to_arrow)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_128_negative
|
26
|
+
assert_equal(Arrow::Decimal128.new("-0.1e38"),
|
27
|
+
BigDecimal("-0.1e38").to_arrow)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_256_positive
|
31
|
+
assert_equal(Arrow::Decimal256.new("0.1e39"),
|
32
|
+
BigDecimal("0.1e39").to_arrow)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_256_negative
|
36
|
+
assert_equal(Arrow::Decimal256.new("-0.1e39"),
|
37
|
+
BigDecimal("-0.1e39").to_arrow)
|
38
|
+
end
|
22
39
|
end
|
23
40
|
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
class BooleanScalarTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@scalar = Arrow::BooleanScalar.new(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
test("#value") do
|
24
|
+
assert_equal(true, @scalar.value)
|
25
|
+
end
|
26
|
+
end
|
@@ -80,8 +80,13 @@ class Decimal128ArrayBuilderTest < Test::Unit::TestCase
|
|
80
80
|
test("is_valids") do
|
81
81
|
@builder.append_values([
|
82
82
|
Arrow::Decimal128.new("10.1"),
|
83
|
-
nil,
|
84
83
|
Arrow::Decimal128.new("10.1"),
|
84
|
+
Arrow::Decimal128.new("10.1"),
|
85
|
+
],
|
86
|
+
[
|
87
|
+
true,
|
88
|
+
false,
|
89
|
+
true,
|
85
90
|
])
|
86
91
|
array = @builder.finish
|
87
92
|
assert_equal([
|
@@ -91,5 +96,17 @@ class Decimal128ArrayBuilderTest < Test::Unit::TestCase
|
|
91
96
|
],
|
92
97
|
array.to_a)
|
93
98
|
end
|
99
|
+
|
100
|
+
test("packed") do
|
101
|
+
@builder.append_values(Arrow::Decimal128.new("10.1").to_bytes.to_s * 3,
|
102
|
+
[true, false, true])
|
103
|
+
array = @builder.finish
|
104
|
+
assert_equal([
|
105
|
+
BigDecimal("10.1"),
|
106
|
+
nil,
|
107
|
+
BigDecimal("10.1"),
|
108
|
+
],
|
109
|
+
array.to_a)
|
110
|
+
end
|
94
111
|
end
|
95
112
|
end
|
@@ -18,12 +18,12 @@
|
|
18
18
|
class Decimal128DataTypeTest < Test::Unit::TestCase
|
19
19
|
sub_test_case(".new") do
|
20
20
|
test("ordered arguments") do
|
21
|
-
assert_equal("
|
21
|
+
assert_equal("decimal128(8, 2)",
|
22
22
|
Arrow::Decimal128DataType.new(8, 2).to_s)
|
23
23
|
end
|
24
24
|
|
25
25
|
test("description") do
|
26
|
-
assert_equal("
|
26
|
+
assert_equal("decimal128(8, 2)",
|
27
27
|
Arrow::Decimal128DataType.new(precision: 8,
|
28
28
|
scale: 2).to_s)
|
29
29
|
end
|
data/test/test-decimal128.rb
CHANGED
@@ -60,5 +60,43 @@ class Decimal128Test < Test::Unit::TestCase
|
|
60
60
|
@decimal128.to_s(1))
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
test("#abs") do
|
65
|
+
decimal128 = Arrow::Decimal128.new("-10.1")
|
66
|
+
assert_equal([
|
67
|
+
Arrow::Decimal128.new("-10.1"),
|
68
|
+
Arrow::Decimal128.new("10.1"),
|
69
|
+
],
|
70
|
+
[
|
71
|
+
decimal128,
|
72
|
+
decimal128.abs,
|
73
|
+
])
|
74
|
+
end
|
75
|
+
|
76
|
+
test("#abs!") do
|
77
|
+
decimal128 = Arrow::Decimal128.new("-10.1")
|
78
|
+
decimal128.abs!
|
79
|
+
assert_equal(Arrow::Decimal128.new("10.1"),
|
80
|
+
decimal128)
|
81
|
+
end
|
82
|
+
|
83
|
+
test("#negate") do
|
84
|
+
decimal128 = Arrow::Decimal128.new("-10.1")
|
85
|
+
assert_equal([
|
86
|
+
Arrow::Decimal128.new("-10.1"),
|
87
|
+
Arrow::Decimal128.new("10.1"),
|
88
|
+
],
|
89
|
+
[
|
90
|
+
decimal128,
|
91
|
+
decimal128.negate,
|
92
|
+
])
|
93
|
+
end
|
94
|
+
|
95
|
+
test("#negate!") do
|
96
|
+
decimal128 = Arrow::Decimal128.new("-10.1")
|
97
|
+
decimal128.negate!
|
98
|
+
assert_equal(Arrow::Decimal128.new("10.1"),
|
99
|
+
decimal128)
|
100
|
+
end
|
63
101
|
end
|
64
102
|
end
|