red-arrow 1.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/arrow/converters.hpp +15 -2
  3. data/ext/arrow/extconf.rb +14 -3
  4. data/ext/arrow/raw-records.cpp +1 -0
  5. data/ext/arrow/values.cpp +1 -0
  6. data/lib/arrow/array-builder.rb +11 -6
  7. data/lib/arrow/array.rb +118 -0
  8. data/lib/arrow/bigdecimal-extension.rb +5 -1
  9. data/lib/arrow/data-type.rb +14 -5
  10. data/lib/arrow/decimal128-array-builder.rb +21 -25
  11. data/lib/arrow/decimal128-data-type.rb +2 -0
  12. data/lib/arrow/decimal128.rb +18 -0
  13. data/lib/arrow/decimal256-array-builder.rb +61 -0
  14. data/lib/arrow/decimal256-array.rb +25 -0
  15. data/lib/arrow/decimal256-data-type.rb +73 -0
  16. data/lib/arrow/decimal256.rb +60 -0
  17. data/lib/arrow/dense-union-data-type.rb +2 -2
  18. data/lib/arrow/dictionary-data-type.rb +2 -2
  19. data/lib/arrow/fixed-size-binary-array-builder.rb +38 -0
  20. data/lib/arrow/fixed-size-binary-array.rb +26 -0
  21. data/lib/arrow/loader.rb +15 -0
  22. data/lib/arrow/sort-key.rb +193 -0
  23. data/lib/arrow/sort-options.rb +109 -0
  24. data/lib/arrow/sparse-union-data-type.rb +2 -2
  25. data/lib/arrow/time32-data-type.rb +2 -2
  26. data/lib/arrow/time64-data-type.rb +2 -2
  27. data/lib/arrow/timestamp-data-type.rb +2 -2
  28. data/lib/arrow/version.rb +1 -1
  29. data/red-arrow.gemspec +1 -0
  30. data/test/raw-records/test-basic-arrays.rb +17 -0
  31. data/test/raw-records/test-dense-union-array.rb +14 -0
  32. data/test/raw-records/test-list-array.rb +20 -0
  33. data/test/raw-records/test-sparse-union-array.rb +14 -0
  34. data/test/raw-records/test-struct-array.rb +15 -0
  35. data/test/test-array.rb +122 -2
  36. data/test/test-bigdecimal.rb +20 -3
  37. data/test/test-decimal128-array-builder.rb +18 -1
  38. data/test/test-decimal128-data-type.rb +2 -2
  39. data/test/test-decimal128.rb +38 -0
  40. data/test/test-decimal256-array-builder.rb +112 -0
  41. data/test/test-decimal256-array.rb +38 -0
  42. data/test/test-decimal256-data-type.rb +31 -0
  43. data/test/test-decimal256.rb +102 -0
  44. data/test/test-fixed-size-binary-array-builder.rb +92 -0
  45. data/test/test-fixed-size-binary-array.rb +36 -0
  46. data/test/test-orc.rb +19 -23
  47. data/test/test-sort-indices.rb +40 -0
  48. data/test/test-sort-key.rb +81 -0
  49. data/test/test-sort-options.rb +58 -0
  50. data/test/test-struct-array-builder.rb +8 -8
  51. data/test/test-struct-array.rb +2 -2
  52. data/test/values/test-basic-arrays.rb +11 -0
  53. data/test/values/test-dense-union-array.rb +14 -0
  54. data/test/values/test-list-array.rb +18 -0
  55. data/test/values/test-sparse-union-array.rb +14 -0
  56. data/test/values/test-struct-array.rb +15 -0
  57. metadata +101 -61
@@ -0,0 +1,36 @@
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 FixedSizeBinaryArrayTest < Test::Unit::TestCase
19
+ sub_test_case(".new") do
20
+ test("build") do
21
+ data_type = Arrow::FixedSizeBinaryDataType.new(4)
22
+ values = [
23
+ "0123",
24
+ nil,
25
+ GLib::Bytes.new("abcd"),
26
+ ]
27
+ array = Arrow::FixedSizeBinaryArray.new(data_type, values)
28
+ assert_equal([
29
+ "0123",
30
+ nil,
31
+ "abcd",
32
+ ],
33
+ array.to_a)
34
+ end
35
+ end
36
+ end
data/test/test-orc.rb CHANGED
@@ -118,39 +118,35 @@ class ORCTest < Test::Unit::TestCase
118
118
  ]
119
119
  ],
120
120
  [
121
- "map: list<item: " +
122
- "struct<key: string, value: " +
123
- "struct<int1: int32, string1: string>>>",
121
+ "map: map<string, struct<int1: int32, string1: string>>",
124
122
  [
125
123
  <<-MAP.chomp
126
124
  [
125
+ keys:
126
+ []
127
+ values:
127
128
  -- is_valid: all not null
128
- -- child 0 type: string
129
+ -- child 0 type: int32
129
130
  []
130
- -- child 1 type: struct<int1: int32, string1: string>
131
- -- is_valid: all not null
132
- -- child 0 type: int32
133
- []
134
- -- child 1 type: string
135
- [],
131
+ -- child 1 type: string
132
+ [],
133
+ keys:
134
+ [
135
+ "chani",
136
+ "mauddib"
137
+ ]
138
+ values:
136
139
  -- is_valid: all not null
137
- -- child 0 type: string
140
+ -- child 0 type: int32
141
+ [
142
+ 5,
143
+ 1
144
+ ]
145
+ -- child 1 type: string
138
146
  [
139
147
  "chani",
140
148
  "mauddib"
141
149
  ]
142
- -- child 1 type: struct<int1: int32, string1: string>
143
- -- is_valid: all not null
144
- -- child 0 type: int32
145
- [
146
- 5,
147
- 1
148
- ]
149
- -- child 1 type: string
150
- [
151
- "chani",
152
- "mauddib"
153
- ]
154
150
  ]
155
151
  MAP
156
152
  ],
@@ -0,0 +1,40 @@
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 SortIndicesTest < Test::Unit::TestCase
19
+ def setup
20
+ @table = Arrow::Table.new(number1: [16, -1, 2, 32, -4, -4, -8],
21
+ number2: [32, 2, -16, 8, 1, 4, 1])
22
+ end
23
+
24
+ sub_test_case("Table") do
25
+ test("Symbol") do
26
+ assert_equal(Arrow::UInt64Array.new([6, 4, 5, 1, 2, 0, 3]),
27
+ @table.sort_indices(:number1))
28
+ end
29
+
30
+ test("-String") do
31
+ assert_equal(Arrow::UInt64Array.new([3, 0, 2, 1, 4, 5, 6]),
32
+ @table.sort_indices("-number1"))
33
+ end
34
+
35
+ test("Symbol, -String") do
36
+ assert_equal(Arrow::UInt64Array.new([6, 5, 4, 1, 2, 0, 3]),
37
+ @table.sort_indices([:number1, "-number2"]))
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,81 @@
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 SortKeyTest < Test::Unit::TestCase
19
+ sub_test_case(".resolve") do
20
+ test("SortKey") do
21
+ assert_equal(Arrow::SortKey.new("-count"),
22
+ Arrow::SortKey.resolve(Arrow::SortKey.new("-count")))
23
+ end
24
+
25
+ test("-String") do
26
+ assert_equal(Arrow::SortKey.new("-count"),
27
+ Arrow::SortKey.resolve("-count"))
28
+ end
29
+
30
+ test("Symbol, Symbol") do
31
+ assert_equal(Arrow::SortKey.new("-count"),
32
+ Arrow::SortKey.resolve(:count, :desc))
33
+ end
34
+ end
35
+
36
+ sub_test_case("#initialize") do
37
+ test("String") do
38
+ assert_equal("+count",
39
+ Arrow::SortKey.new("count").to_s)
40
+ end
41
+
42
+ test("+String") do
43
+ assert_equal("+count",
44
+ Arrow::SortKey.new("+count").to_s)
45
+ end
46
+
47
+ test("-String") do
48
+ assert_equal("-count",
49
+ Arrow::SortKey.new("-count").to_s)
50
+ end
51
+
52
+ test("Symbol") do
53
+ assert_equal("+-count",
54
+ Arrow::SortKey.new(:"-count").to_s)
55
+ end
56
+
57
+ test("String, Symbol") do
58
+ assert_equal("--count",
59
+ Arrow::SortKey.new("-count", :desc).to_s)
60
+ end
61
+
62
+ test("String, String") do
63
+ assert_equal("--count",
64
+ Arrow::SortKey.new("-count", "desc").to_s)
65
+ end
66
+
67
+ test("String, SortOrder") do
68
+ assert_equal("--count",
69
+ Arrow::SortKey.new("-count",
70
+ Arrow::SortOrder::DESCENDING).to_s)
71
+ end
72
+ end
73
+
74
+ sub_test_case("#to_s") do
75
+ test("recreatable") do
76
+ key = Arrow::SortKey.new("-count", :desc)
77
+ assert_equal(key,
78
+ Arrow::SortKey.new(key.to_s))
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,58 @@
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 SortOptionsTest < Test::Unit::TestCase
19
+ sub_test_case("#initialize") do
20
+ test("none") do
21
+ options = Arrow::SortOptions.new
22
+ assert_equal([],
23
+ options.sort_keys.collect(&:to_s))
24
+ end
25
+
26
+ test("-String, Symbol") do
27
+ options = Arrow::SortOptions.new("-count", :age)
28
+ assert_equal(["-count", "+age"],
29
+ options.sort_keys.collect(&:to_s))
30
+ end
31
+ end
32
+
33
+ sub_test_case("instance methods") do
34
+ setup do
35
+ @options = Arrow::SortOptions.new
36
+ end
37
+
38
+ sub_test_case("#add_sort_key") do
39
+ test("-String") do
40
+ @options.add_sort_key("-count")
41
+ assert_equal(["-count"],
42
+ @options.sort_keys.collect(&:to_s))
43
+ end
44
+
45
+ test("-String, Symbol") do
46
+ @options.add_sort_key("-count", :desc)
47
+ assert_equal(["--count"],
48
+ @options.sort_keys.collect(&:to_s))
49
+ end
50
+
51
+ test("SortKey") do
52
+ @options.add_sort_key(Arrow::SortKey.new("-count"))
53
+ assert_equal(["-count"],
54
+ @options.sort_keys.collect(&:to_s))
55
+ end
56
+ end
57
+ end
58
+ end
@@ -27,8 +27,8 @@ class StructArrayBuilderTest < Test::Unit::TestCase
27
27
  @builder.append_value(nil)
28
28
  array = @builder.finish
29
29
  assert_equal([
30
- [nil],
31
- [nil],
30
+ [false],
31
+ [0],
32
32
  ],
33
33
  [
34
34
  array.find_field(0).to_a,
@@ -87,8 +87,8 @@ class StructArrayBuilderTest < Test::Unit::TestCase
87
87
  @builder.append_values([nil])
88
88
  array = @builder.finish
89
89
  assert_equal([
90
- [nil],
91
- [nil],
90
+ [false],
91
+ [0],
92
92
  ],
93
93
  [
94
94
  array.find_field(0).to_a,
@@ -130,8 +130,8 @@ class StructArrayBuilderTest < Test::Unit::TestCase
130
130
  ])
131
131
  array = @builder.finish
132
132
  assert_equal([
133
- [nil, true, false],
134
- [nil, 1, 2],
133
+ [false, true, false],
134
+ [0, 1, 2],
135
135
  ],
136
136
  [
137
137
  array.find_field(0).to_a,
@@ -152,8 +152,8 @@ class StructArrayBuilderTest < Test::Unit::TestCase
152
152
  ])
153
153
  array = @builder.finish
154
154
  assert_equal([
155
- [true, nil, true],
156
- [1, nil, 3],
155
+ [true, false, true],
156
+ [1, 0, 3],
157
157
  ],
158
158
  [
159
159
  array.find_field(0).to_a,
@@ -27,8 +27,8 @@ class StructArrayTest < Test::Unit::TestCase
27
27
  ]
28
28
  array = Arrow::StructArray.new(data_type, values)
29
29
  assert_equal([
30
- [true, nil, false],
31
- [1, nil, 2],
30
+ [true, false, false],
31
+ [1, 0, 2],
32
32
  ],
33
33
  [
34
34
  array.find_field(0).to_a,
@@ -265,6 +265,17 @@ module ValuesBasicArraysTests
265
265
  target = build(Arrow::Decimal128Array.new(data_type, values))
266
266
  assert_equal(values, target.values)
267
267
  end
268
+
269
+ def test_decimal256
270
+ values = [
271
+ BigDecimal("92.92"),
272
+ nil,
273
+ BigDecimal("29.29"),
274
+ ]
275
+ data_type = Arrow::Decimal256DataType.new(38, 2)
276
+ target = build(Arrow::Decimal256Array.new(data_type, values))
277
+ assert_equal(values, target.values)
278
+ end
268
279
  end
269
280
 
270
281
  class ValuesArrayBasicArraysTest < Test::Unit::TestCase
@@ -333,6 +333,20 @@ module ValuesDenseUnionArrayTests
333
333
  assert_equal(values, target.values)
334
334
  end
335
335
 
336
+ def test_decimal256
337
+ values = [
338
+ {"0" => BigDecimal("92.92")},
339
+ {"1" => nil},
340
+ ]
341
+ target = build({
342
+ type: :decimal256,
343
+ precision: 38,
344
+ scale: 2,
345
+ },
346
+ values)
347
+ assert_equal(values, target.values)
348
+ end
349
+
336
350
  def test_list
337
351
  values = [
338
352
  {"0" => [true, nil, false]},
@@ -354,6 +354,24 @@ module ValuesListArrayTests
354
354
  assert_equal(values, target.values)
355
355
  end
356
356
 
357
+ def test_decimal256
358
+ values = [
359
+ [
360
+ BigDecimal("92.92"),
361
+ nil,
362
+ BigDecimal("29.29"),
363
+ ],
364
+ nil,
365
+ ]
366
+ target = build({
367
+ type: :decimal256,
368
+ precision: 38,
369
+ scale: 2,
370
+ },
371
+ values)
372
+ assert_equal(values, target.values)
373
+ end
374
+
357
375
  def test_list
358
376
  values = [
359
377
  [
@@ -324,6 +324,20 @@ module ValuesSparseUnionArrayTests
324
324
  assert_equal(values, target.values)
325
325
  end
326
326
 
327
+ def test_decimal256
328
+ values = [
329
+ {"0" => BigDecimal("92.92")},
330
+ {"1" => nil},
331
+ ]
332
+ target = build({
333
+ type: :decimal256,
334
+ precision: 38,
335
+ scale: 2,
336
+ },
337
+ values)
338
+ assert_equal(values, target.values)
339
+ end
340
+
327
341
  def test_list
328
342
  values = [
329
343
  {"0" => [true, nil, false]},
@@ -326,6 +326,21 @@ module ValuesStructArrayTests
326
326
  assert_equal(values, target.values)
327
327
  end
328
328
 
329
+ def test_decimal256
330
+ values = [
331
+ {"field" => BigDecimal("92.92")},
332
+ nil,
333
+ {"field" => nil},
334
+ ]
335
+ target = build({
336
+ type: :decimal256,
337
+ precision: 38,
338
+ scale: 2,
339
+ },
340
+ values)
341
+ assert_equal(values, target.values)
342
+ end
343
+
329
344
  def test_list
330
345
  values = [
331
346
  {"field" => [true, nil, false]},