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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/ext/arrow/arrow.cpp +3 -0
  3. data/ext/arrow/converters.hpp +15 -2
  4. data/ext/arrow/memory-view.cpp +311 -0
  5. data/ext/arrow/memory-view.hpp +26 -0
  6. data/ext/arrow/raw-records.cpp +1 -0
  7. data/ext/arrow/values.cpp +1 -0
  8. data/lib/arrow/array-builder.rb +11 -6
  9. data/lib/arrow/array.rb +130 -0
  10. data/lib/arrow/bigdecimal-extension.rb +5 -1
  11. data/lib/arrow/buffer.rb +10 -6
  12. data/lib/arrow/constructor-arguments-gc-guardable.rb +25 -0
  13. data/lib/arrow/data-type.rb +14 -5
  14. data/lib/arrow/datum.rb +98 -0
  15. data/lib/arrow/decimal128-array-builder.rb +21 -25
  16. data/lib/arrow/decimal128-data-type.rb +2 -0
  17. data/lib/arrow/decimal128.rb +18 -0
  18. data/lib/arrow/decimal256-array-builder.rb +61 -0
  19. data/lib/arrow/decimal256-array.rb +25 -0
  20. data/lib/arrow/decimal256-data-type.rb +73 -0
  21. data/lib/arrow/decimal256.rb +60 -0
  22. data/lib/arrow/dense-union-data-type.rb +2 -2
  23. data/lib/arrow/dictionary-data-type.rb +2 -2
  24. data/lib/arrow/equal-options.rb +38 -0
  25. data/lib/arrow/fixed-size-binary-array-builder.rb +38 -0
  26. data/lib/arrow/fixed-size-binary-array.rb +26 -0
  27. data/lib/arrow/loader.rb +46 -0
  28. data/lib/arrow/scalar.rb +32 -0
  29. data/lib/arrow/sort-key.rb +193 -0
  30. data/lib/arrow/sort-options.rb +109 -0
  31. data/lib/arrow/sparse-union-data-type.rb +2 -2
  32. data/lib/arrow/table.rb +2 -2
  33. data/lib/arrow/time32-data-type.rb +2 -2
  34. data/lib/arrow/time64-data-type.rb +2 -2
  35. data/lib/arrow/timestamp-data-type.rb +2 -2
  36. data/lib/arrow/version.rb +1 -1
  37. data/red-arrow.gemspec +3 -1
  38. data/test/helper.rb +1 -0
  39. data/test/raw-records/test-basic-arrays.rb +17 -0
  40. data/test/raw-records/test-dense-union-array.rb +14 -0
  41. data/test/raw-records/test-list-array.rb +20 -0
  42. data/test/raw-records/test-sparse-union-array.rb +14 -0
  43. data/test/raw-records/test-struct-array.rb +15 -0
  44. data/test/test-array.rb +156 -2
  45. data/test/test-bigdecimal.rb +20 -3
  46. data/test/test-boolean-scalar.rb +26 -0
  47. data/test/test-decimal128-array-builder.rb +18 -1
  48. data/test/test-decimal128-data-type.rb +2 -2
  49. data/test/test-decimal128.rb +38 -0
  50. data/test/test-decimal256-array-builder.rb +112 -0
  51. data/test/test-decimal256-array.rb +38 -0
  52. data/test/test-decimal256-data-type.rb +31 -0
  53. data/test/test-decimal256.rb +102 -0
  54. data/test/test-fixed-size-binary-array-builder.rb +92 -0
  55. data/test/test-fixed-size-binary-array.rb +36 -0
  56. data/test/test-float-scalar.rb +46 -0
  57. data/test/test-function.rb +176 -0
  58. data/test/test-memory-view.rb +434 -0
  59. data/test/test-orc.rb +19 -23
  60. data/test/test-sort-indices.rb +40 -0
  61. data/test/test-sort-key.rb +81 -0
  62. data/test/test-sort-options.rb +58 -0
  63. data/test/test-struct-array-builder.rb +8 -8
  64. data/test/test-struct-array.rb +2 -2
  65. data/test/values/test-basic-arrays.rb +11 -0
  66. data/test/values/test-dense-union-array.rb +14 -0
  67. data/test/values/test-list-array.rb +18 -0
  68. data/test/values/test-sparse-union-array.rb +14 -0
  69. data/test/values/test-struct-array.rb +15 -0
  70. metadata +127 -59
@@ -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
@@ -0,0 +1,31 @@
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 Decimal256DataTypeTest < Test::Unit::TestCase
19
+ sub_test_case(".new") do
20
+ test("ordered arguments") do
21
+ assert_equal("decimal256(8, 2)",
22
+ Arrow::Decimal256DataType.new(8, 2).to_s)
23
+ end
24
+
25
+ test("description") do
26
+ assert_equal("decimal256(8, 2)",
27
+ Arrow::Decimal256DataType.new(precision: 8,
28
+ scale: 2).to_s)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,102 @@
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 Decimal256Test < Test::Unit::TestCase
19
+ sub_test_case("instance methods") do
20
+ def setup
21
+ @decimal256 = Arrow::Decimal256.new("10.1")
22
+ end
23
+
24
+ sub_test_case("#==") do
25
+ test("Arrow::Decimal256") do
26
+ assert do
27
+ @decimal256 == @decimal256
28
+ end
29
+ end
30
+
31
+ test("not Arrow::Decimal256") do
32
+ assert do
33
+ not (@decimal256 == 10.1)
34
+ end
35
+ end
36
+ end
37
+
38
+ sub_test_case("#!=") do
39
+ test("Arrow::Decimal256") do
40
+ assert do
41
+ not (@decimal256 != @decimal256)
42
+ end
43
+ end
44
+
45
+ test("not Arrow::Decimal256") do
46
+ assert do
47
+ @decimal256 != 10.1
48
+ end
49
+ end
50
+ end
51
+
52
+ sub_test_case("#to_s") do
53
+ test("default") do
54
+ assert_equal("101",
55
+ @decimal256.to_s)
56
+ end
57
+
58
+ test("scale") do
59
+ assert_equal("10.1",
60
+ @decimal256.to_s(1))
61
+ end
62
+ end
63
+
64
+ test("#abs") do
65
+ decimal256 = Arrow::Decimal256.new("-10.1")
66
+ assert_equal([
67
+ Arrow::Decimal256.new("-10.1"),
68
+ Arrow::Decimal256.new("10.1"),
69
+ ],
70
+ [
71
+ decimal256,
72
+ decimal256.abs,
73
+ ])
74
+ end
75
+
76
+ test("#abs!") do
77
+ decimal256 = Arrow::Decimal256.new("-10.1")
78
+ decimal256.abs!
79
+ assert_equal(Arrow::Decimal256.new("10.1"),
80
+ decimal256)
81
+ end
82
+
83
+ test("#negate") do
84
+ decimal256 = Arrow::Decimal256.new("-10.1")
85
+ assert_equal([
86
+ Arrow::Decimal256.new("-10.1"),
87
+ Arrow::Decimal256.new("10.1"),
88
+ ],
89
+ [
90
+ decimal256,
91
+ decimal256.negate,
92
+ ])
93
+ end
94
+
95
+ test("#negate!") do
96
+ decimal256 = Arrow::Decimal256.new("-10.1")
97
+ decimal256.negate!
98
+ assert_equal(Arrow::Decimal256.new("10.1"),
99
+ decimal256)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,92 @@
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 FixedSizeBinaryArrayBuilderTest < Test::Unit::TestCase
19
+ def setup
20
+ @data_type = Arrow::FixedSizeBinaryDataType.new(4)
21
+ @builder = Arrow::FixedSizeBinaryArrayBuilder.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("String") do
32
+ @builder.append_value("0123")
33
+ array = @builder.finish
34
+ assert_equal("0123", array[0])
35
+ end
36
+
37
+ test("GLib::Bytes") do
38
+ @builder.append_value(GLib::Bytes.new("0123"))
39
+ array = @builder.finish
40
+ assert_equal("0123", array[0])
41
+ end
42
+ end
43
+
44
+ sub_test_case("#append_values") do
45
+ test("mixed") do
46
+ @builder.append_values([
47
+ "0123",
48
+ nil,
49
+ GLib::Bytes.new("abcd"),
50
+ ])
51
+ array = @builder.finish
52
+ assert_equal([
53
+ "0123",
54
+ nil,
55
+ "abcd",
56
+ ],
57
+ array.to_a)
58
+ end
59
+
60
+ test("is_valids") do
61
+ @builder.append_values([
62
+ "0123",
63
+ "0123",
64
+ "0123",
65
+ ],
66
+ [
67
+ true,
68
+ false,
69
+ true,
70
+ ])
71
+ array = @builder.finish
72
+ assert_equal([
73
+ "0123",
74
+ nil,
75
+ "0123",
76
+ ],
77
+ array.to_a)
78
+ end
79
+
80
+ test("packed") do
81
+ @builder.append_values("0123" * 3,
82
+ [true, false, true])
83
+ array = @builder.finish
84
+ assert_equal([
85
+ "0123",
86
+ nil,
87
+ "0123",
88
+ ],
89
+ array.to_a)
90
+ end
91
+ end
92
+ end
@@ -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
@@ -0,0 +1,46 @@
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 FloatScalarTest < Test::Unit::TestCase
19
+ sub_test_case("#equal_scalar?") do
20
+ test("no options") do
21
+ scalar1 = Arrow::FloatScalar.new(1.1)
22
+ scalar2 = Arrow::FloatScalar.new(1.1000001)
23
+ assert do
24
+ not scalar1.equal_scalar?(scalar2)
25
+ end
26
+ end
27
+
28
+ test(":approx") do
29
+ scalar1 = Arrow::FloatScalar.new(1.1)
30
+ scalar2 = Arrow::FloatScalar.new(1.1000001)
31
+ assert do
32
+ scalar1.equal_scalar?(scalar2, approx: true)
33
+ end
34
+ end
35
+
36
+ test(":absolute_tolerance") do
37
+ scalar1 = Arrow::FloatScalar.new(1.1)
38
+ scalar2 = Arrow::FloatScalar.new(1.1001)
39
+ assert do
40
+ scalar1.equal_scalar?(scalar2,
41
+ approx: true,
42
+ absolute_tolerance: 0.001)
43
+ end
44
+ end
45
+ end
46
+ end