red-arrow 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/ext/arrow/converters.hpp +15 -2
  3. data/ext/arrow/raw-records.cpp +1 -0
  4. data/ext/arrow/values.cpp +1 -0
  5. data/lib/arrow/array-builder.rb +11 -6
  6. data/lib/arrow/bigdecimal-extension.rb +5 -1
  7. data/lib/arrow/decimal128-array-builder.rb +21 -25
  8. data/lib/arrow/decimal128-data-type.rb +2 -0
  9. data/lib/arrow/decimal128.rb +18 -0
  10. data/lib/arrow/decimal256-array-builder.rb +61 -0
  11. data/lib/arrow/decimal256-array.rb +25 -0
  12. data/lib/arrow/decimal256-data-type.rb +73 -0
  13. data/lib/arrow/decimal256.rb +60 -0
  14. data/lib/arrow/fixed-size-binary-array-builder.rb +38 -0
  15. data/lib/arrow/fixed-size-binary-array.rb +26 -0
  16. data/lib/arrow/loader.rb +13 -0
  17. data/lib/arrow/version.rb +1 -1
  18. data/red-arrow.gemspec +1 -0
  19. data/test/raw-records/test-basic-arrays.rb +17 -0
  20. data/test/raw-records/test-dense-union-array.rb +14 -0
  21. data/test/raw-records/test-list-array.rb +20 -0
  22. data/test/raw-records/test-sparse-union-array.rb +14 -0
  23. data/test/raw-records/test-struct-array.rb +15 -0
  24. data/test/test-array.rb +2 -2
  25. data/test/test-bigdecimal.rb +20 -3
  26. data/test/test-decimal128-array-builder.rb +18 -1
  27. data/test/test-decimal128.rb +38 -0
  28. data/test/test-decimal256-array-builder.rb +112 -0
  29. data/test/test-decimal256-array.rb +38 -0
  30. data/test/test-decimal256-data-type.rb +31 -0
  31. data/test/test-decimal256.rb +102 -0
  32. data/test/test-fixed-size-binary-array-builder.rb +92 -0
  33. data/test/test-fixed-size-binary-array.rb +36 -0
  34. data/test/test-struct-array-builder.rb +8 -8
  35. data/test/test-struct-array.rb +2 -2
  36. data/test/values/test-basic-arrays.rb +11 -0
  37. data/test/values/test-dense-union-array.rb +14 -0
  38. data/test/values/test-list-array.rb +18 -0
  39. data/test/values/test-sparse-union-array.rb +14 -0
  40. data/test/values/test-struct-array.rb +15 -0
  41. metadata +93 -61
@@ -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
+ module Arrow
19
+ class FixedSizeBinaryArray
20
+ alias_method :get_value_raw, :get_value
21
+ # @since 3.0.0
22
+ def get_value(i)
23
+ get_value_raw(i).to_s
24
+ end
25
+ end
26
+ end
@@ -56,11 +56,17 @@ module Arrow
56
56
  require "arrow/decimal128-array"
57
57
  require "arrow/decimal128-array-builder"
58
58
  require "arrow/decimal128-data-type"
59
+ require "arrow/decimal256"
60
+ require "arrow/decimal256-array"
61
+ require "arrow/decimal256-array-builder"
62
+ require "arrow/decimal256-data-type"
59
63
  require "arrow/dense-union-data-type"
60
64
  require "arrow/dictionary-array"
61
65
  require "arrow/dictionary-data-type"
62
66
  require "arrow/field"
63
67
  require "arrow/file-output-stream"
68
+ require "arrow/fixed-size-binary-array"
69
+ require "arrow/fixed-size-binary-array-builder"
64
70
  require "arrow/group"
65
71
  require "arrow/list-array-builder"
66
72
  require "arrow/list-data-type"
@@ -141,6 +147,7 @@ module Arrow
141
147
  when "Arrow::Date32Array",
142
148
  "Arrow::Date64Array",
143
149
  "Arrow::Decimal128Array",
150
+ "Arrow::Decimal256Array",
144
151
  "Arrow::Time32Array",
145
152
  "Arrow::Time64Array",
146
153
  "Arrow::TimestampArray"
@@ -149,6 +156,12 @@ module Arrow
149
156
  method_name = "get_raw_value"
150
157
  end
151
158
  super(info, klass, method_name)
159
+ when "Arrow::Decimal128", "Arrow::Decimal256"
160
+ case method_name
161
+ when "copy"
162
+ method_name = "dup"
163
+ end
164
+ super(info, klass, method_name)
152
165
  else
153
166
  super
154
167
  end
@@ -16,7 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  module Arrow
19
- VERSION = "2.0.0"
19
+ VERSION = "3.0.0"
20
20
 
21
21
  module Version
22
22
  numbers, TAG = VERSION.split("-")
@@ -46,6 +46,7 @@ Gem::Specification.new do |spec|
46
46
  spec.test_files += Dir.glob("test/**/*")
47
47
  spec.extensions = ["ext/arrow/extconf.rb"]
48
48
 
49
+ spec.add_runtime_dependency("bigdecimal", ">= 2.0.3")
49
50
  spec.add_runtime_dependency("extpp", ">= 0.0.7")
50
51
  spec.add_runtime_dependency("gio2", ">= 3.3.6")
51
52
  spec.add_runtime_dependency("native-package-installer")
@@ -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]}],
@@ -160,8 +160,8 @@ class ArrayTest < Test::Unit::TestCase
160
160
 
161
161
  test("Arrow::ChunkedArray") do
162
162
  chunks = [
163
- Arrow::Int16Array.new([1, 0]),
164
- Arrow::Int16Array.new([1, 0, 3])
163
+ Arrow::Int16Array.new([1, 4]),
164
+ Arrow::Int16Array.new([0, 3])
165
165
  ]
166
166
  right = Arrow::ChunkedArray.new(chunks)
167
167
  assert_equal(Arrow::BooleanArray.new([true, true, true, false]),
@@ -16,8 +16,25 @@
16
16
  # under the License.
17
17
 
18
18
  class BigDecimalTest < Test::Unit::TestCase
19
- test("#to_arrow") do
20
- assert_equal(Arrow::Decimal128.new("3.14"),
21
- BigDecimal("3.14").to_arrow)
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
@@ -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
@@ -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
@@ -0,0 +1,112 @@
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 Decimal256ArrayBuilderTest < Test::Unit::TestCase
19
+ def setup
20
+ @data_type = Arrow::Decimal256DataType.new(3, 1)
21
+ @builder = Arrow::Decimal256ArrayBuilder.new(@data_type)
22
+ end
23
+
24
+ sub_test_case("#append_value") do
25
+ test("nil") do
26
+ @builder.append_value(nil)
27
+ array = @builder.finish
28
+ assert_equal(nil, array[0])
29
+ end
30
+
31
+ test("Arrow::Decimal256") do
32
+ @builder.append_value(Arrow::Decimal256.new("10.1"))
33
+ array = @builder.finish
34
+ assert_equal(BigDecimal("10.1"),
35
+ array[0])
36
+ end
37
+
38
+ test("String") do
39
+ @builder.append_value("10.1")
40
+ array = @builder.finish
41
+ assert_equal(BigDecimal("10.1"),
42
+ array[0])
43
+ end
44
+
45
+ test("Float") do
46
+ @builder.append_value(10.1)
47
+ array = @builder.finish
48
+ assert_equal(BigDecimal("10.1"),
49
+ array[0])
50
+ end
51
+
52
+ test("BigDecimal") do
53
+ @builder.append_value(BigDecimal("10.1"))
54
+ array = @builder.finish
55
+ assert_equal(BigDecimal("10.1"),
56
+ array[0])
57
+ end
58
+ end
59
+
60
+ sub_test_case("#append_values") do
61
+ test("mixed") do
62
+ @builder.append_values([
63
+ Arrow::Decimal256.new("10.1"),
64
+ nil,
65
+ "10.1",
66
+ 10.1,
67
+ BigDecimal("10.1"),
68
+ ])
69
+ array = @builder.finish
70
+ assert_equal([
71
+ BigDecimal("10.1"),
72
+ nil,
73
+ BigDecimal("10.1"),
74
+ BigDecimal("10.1"),
75
+ BigDecimal("10.1"),
76
+ ],
77
+ array.to_a)
78
+ end
79
+
80
+ test("is_valids") do
81
+ @builder.append_values([
82
+ Arrow::Decimal256.new("10.1"),
83
+ Arrow::Decimal256.new("10.1"),
84
+ Arrow::Decimal256.new("10.1"),
85
+ ],
86
+ [
87
+ true,
88
+ false,
89
+ true,
90
+ ])
91
+ array = @builder.finish
92
+ assert_equal([
93
+ BigDecimal("10.1"),
94
+ nil,
95
+ BigDecimal("10.1"),
96
+ ],
97
+ array.to_a)
98
+ end
99
+
100
+ test("packed") do
101
+ @builder.append_values(Arrow::Decimal256.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
111
+ end
112
+ end
@@ -0,0 +1,38 @@
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 Decimal256ArrayTest < Test::Unit::TestCase
19
+ sub_test_case(".new") do
20
+ test("build") do
21
+ data_type = Arrow::Decimal256DataType.new(3, 1)
22
+ values = [
23
+ 10.1,
24
+ nil,
25
+ "10.1",
26
+ BigDecimal("10.1"),
27
+ ]
28
+ array = Arrow::Decimal256Array.new(data_type, values)
29
+ assert_equal([
30
+ BigDecimal("10.1"),
31
+ nil,
32
+ BigDecimal("10.1"),
33
+ BigDecimal("10.1"),
34
+ ],
35
+ array.to_a)
36
+ end
37
+ end
38
+ end