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,61 @@
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 Decimal256ArrayBuilder
20
+ class << self
21
+ # @since 3.0.0
22
+ def build(data_type, values)
23
+ builder = new(data_type)
24
+ builder.build(values)
25
+ end
26
+ end
27
+
28
+ alias_method :append_value_raw, :append_value
29
+ # @since 3.0.0
30
+ def append_value(value)
31
+ append_value_raw(normalize_value(value))
32
+ end
33
+
34
+ alias_method :append_values_raw, :append_values
35
+ # @since 3.0.0
36
+ def append_values(values, is_valids=nil)
37
+ if values.is_a?(::Array)
38
+ values = values.collect do |value|
39
+ normalize_value(value)
40
+ end
41
+ append_values_raw(values, is_valids)
42
+ else
43
+ append_values_packed(values, is_valids)
44
+ end
45
+ end
46
+
47
+ private
48
+ def normalize_value(value)
49
+ case value
50
+ when String
51
+ Decimal256.new(value)
52
+ when Float
53
+ Decimal256.new(value.to_s)
54
+ when BigDecimal
55
+ Decimal256.new(value.to_s)
56
+ else
57
+ value
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,25 @@
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 Decimal256Array
20
+ # @since 3.0.0
21
+ def get_value(i)
22
+ BigDecimal(format_value(i))
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,73 @@
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 Decimal256DataType
20
+ MAX_PRECISION = max_precision
21
+
22
+ alias_method :initialize_raw, :initialize
23
+ private :initialize_raw
24
+
25
+ # Creates a new {Arrow::Decimal256DataType}.
26
+ #
27
+ # @overload initialize(precision, scale)
28
+ #
29
+ # @param precision [Integer] The precision of the decimal data
30
+ # type. It's the number of digits including the number of
31
+ # digits after the decimal point.
32
+ #
33
+ # @param scale [Integer] The scale of the decimal data
34
+ # type. It's the number of digits after the decimal point.
35
+ #
36
+ # @example Create a decimal data type for "XXXXXX.YY" decimal
37
+ # Arrow::Decimal256DataType.new(8, 2)
38
+ #
39
+ # @overload initialize(description)
40
+ #
41
+ # @param description [Hash] The description of the decimal data
42
+ # type. It must have `:precision` and `:scale` values.
43
+ #
44
+ # @option description [Integer] :precision The precision of the
45
+ # decimal data type. It's the number of digits including the
46
+ # number of digits after the decimal point.
47
+ #
48
+ # @option description [Integer] :scale The scale of the decimal
49
+ # data type. It's the number of digits after the decimal
50
+ # point.
51
+ #
52
+ # @example Create a decimal data type for "XXXXXX.YY" decimal
53
+ # Arrow::Decimal256DataType.new(precision: 8,
54
+ # scale: 2)
55
+ #
56
+ # @since 3.0.0
57
+ def initialize(*args)
58
+ n_args = args.size
59
+ case n_args
60
+ when 1
61
+ description = args[0]
62
+ precision = description[:precision]
63
+ scale = description[:scale]
64
+ when 2
65
+ precision, scale = args
66
+ else
67
+ message = "wrong number of arguments (given, #{n_args}, expected 1..2)"
68
+ raise ArgumentError, message
69
+ end
70
+ initialize_raw(precision, scale)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,60 @@
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 Decimal256
20
+ alias_method :to_s_raw, :to_s
21
+
22
+ # @overload to_s
23
+ #
24
+ # @return [String]
25
+ # The string representation of the decimal.
26
+ #
27
+ # @overload to_s(scale)
28
+ #
29
+ # @param scale [Integer] The scale of the decimal.
30
+ # @return [String]
31
+ # The string representation of the decimal including the scale.
32
+ #
33
+ # @since 3.0.0
34
+ def to_s(scale=nil)
35
+ if scale
36
+ to_string_scale(scale)
37
+ else
38
+ to_s_raw
39
+ end
40
+ end
41
+
42
+ alias_method :abs!, :abs
43
+
44
+ # @since 3.0.0
45
+ def abs
46
+ copied = dup
47
+ copied.abs!
48
+ copied
49
+ end
50
+
51
+ alias_method :negate!, :negate
52
+
53
+ # @since 3.0.0
54
+ def negate
55
+ copied = dup
56
+ copied.negate!
57
+ copied
58
+ end
59
+ end
60
+ end
@@ -33,7 +33,7 @@ module Arrow
33
33
  # @param type_codes [::Array<Integer>] The IDs that indicates
34
34
  # corresponding fields.
35
35
  #
36
- # @example Create a dense union data type for {2: visible, 9: count}
36
+ # @example Create a dense union data type for `{2: visible, 9: count}`
37
37
  # fields = [
38
38
  # Arrow::Field.new("visible", :boolean),
39
39
  # {
@@ -57,7 +57,7 @@ module Arrow
57
57
  # @option description [::Array<Integer>] :type_codes The IDs
58
58
  # that indicates corresponding fields.
59
59
  #
60
- # @example Create a dense union data type for {2: visible, 9: count}
60
+ # @example Create a dense union data type for `{2: visible, 9: count}`
61
61
  # fields = [
62
62
  # Arrow::Field.new("visible", :boolean),
63
63
  # {
@@ -50,7 +50,7 @@ module Arrow
50
50
  # @param ordered [Boolean] Whether dictionary contents are
51
51
  # ordered or not.
52
52
  #
53
- # @example Create a dictionary data type for {0: "Hello", 1: "World"}
53
+ # @example Create a dictionary data type for `{0: "Hello", 1: "World"}`
54
54
  # index_data_type = :int8
55
55
  # value_data_type = :string
56
56
  # ordered = true
@@ -91,7 +91,7 @@ module Arrow
91
91
  # @option description [Boolean] :ordered Whether dictionary
92
92
  # contents are ordered or not.
93
93
  #
94
- # @example Create a dictionary data type for {0: "Hello", 1: "World"}
94
+ # @example Create a dictionary data type for `{0: "Hello", 1: "World"}`
95
95
  # Arrow::DictionaryDataType.new(index_data_type: :int8,
96
96
  # value_data_type: :string,
97
97
  # ordered: true)
@@ -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
+ module Arrow
19
+ class EqualOptions
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when Hash
25
+ options = new
26
+ value.each do |k, v|
27
+ setter = :"#{k}="
28
+ return unless options.respond_to?(setter)
29
+ options.__send__(setter, v)
30
+ end
31
+ options
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ 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
+ module Arrow
19
+ class FixedSizeBinaryArrayBuilder
20
+ class << self
21
+ # @since 3.0.0
22
+ def build(data_type, values)
23
+ builder = new(data_type)
24
+ builder.build(values)
25
+ end
26
+ end
27
+
28
+ alias_method :append_values_raw, :append_values
29
+ # @since 3.0.0
30
+ def append_values(values, is_valids=nil)
31
+ if values.is_a?(::Array)
32
+ append_values_raw(values, is_valids)
33
+ else
34
+ append_values_packed(values, is_valids)
35
+ end
36
+ end
37
+ end
38
+ 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
+ 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
data/lib/arrow/loader.rb CHANGED
@@ -29,6 +29,7 @@ module Arrow
29
29
  def post_load(repository, namespace)
30
30
  require_libraries
31
31
  require_extension_library
32
+ gc_guard
32
33
  end
33
34
 
34
35
  def require_libraries
@@ -52,15 +53,23 @@ module Arrow
52
53
  require "arrow/date32-array-builder"
53
54
  require "arrow/date64-array"
54
55
  require "arrow/date64-array-builder"
56
+ require "arrow/datum"
55
57
  require "arrow/decimal128"
56
58
  require "arrow/decimal128-array"
57
59
  require "arrow/decimal128-array-builder"
58
60
  require "arrow/decimal128-data-type"
61
+ require "arrow/decimal256"
62
+ require "arrow/decimal256-array"
63
+ require "arrow/decimal256-array-builder"
64
+ require "arrow/decimal256-data-type"
59
65
  require "arrow/dense-union-data-type"
60
66
  require "arrow/dictionary-array"
61
67
  require "arrow/dictionary-data-type"
68
+ require "arrow/equal-options"
62
69
  require "arrow/field"
63
70
  require "arrow/file-output-stream"
71
+ require "arrow/fixed-size-binary-array"
72
+ require "arrow/fixed-size-binary-array-builder"
64
73
  require "arrow/group"
65
74
  require "arrow/list-array-builder"
66
75
  require "arrow/list-data-type"
@@ -74,8 +83,11 @@ module Arrow
74
83
  require "arrow/record-batch-iterator"
75
84
  require "arrow/record-batch-stream-reader"
76
85
  require "arrow/rolling-window"
86
+ require "arrow/scalar"
77
87
  require "arrow/schema"
78
88
  require "arrow/slicer"
89
+ require "arrow/sort-key"
90
+ require "arrow/sort-options"
79
91
  require "arrow/sparse-union-data-type"
80
92
  require "arrow/struct-array"
81
93
  require "arrow/struct-array-builder"
@@ -104,6 +116,27 @@ module Arrow
104
116
  require "arrow.so"
105
117
  end
106
118
 
119
+ def gc_guard
120
+ require "arrow/constructor-arguments-gc-guardable"
121
+
122
+ [
123
+ @base_module::BinaryScalar,
124
+ @base_module::Buffer,
125
+ @base_module::DenseUnionScalar,
126
+ @base_module::FixedSizeBinaryScalar,
127
+ @base_module::LargeBinaryScalar,
128
+ @base_module::LargeListScalar,
129
+ @base_module::LargeStringScalar,
130
+ @base_module::ListScalar,
131
+ @base_module::MapScalar,
132
+ @base_module::SparseUnionScalar,
133
+ @base_module::StringScalar,
134
+ @base_module::StructScalar,
135
+ ].each do |klass|
136
+ klass.prepend(ConstructorArgumentsGCGuardable)
137
+ end
138
+ end
139
+
107
140
  def load_object_info(info)
108
141
  super
109
142
 
@@ -141,6 +174,7 @@ module Arrow
141
174
  when "Arrow::Date32Array",
142
175
  "Arrow::Date64Array",
143
176
  "Arrow::Decimal128Array",
177
+ "Arrow::Decimal256Array",
144
178
  "Arrow::Time32Array",
145
179
  "Arrow::Time64Array",
146
180
  "Arrow::TimestampArray"
@@ -149,6 +183,18 @@ module Arrow
149
183
  method_name = "get_raw_value"
150
184
  end
151
185
  super(info, klass, method_name)
186
+ when "Arrow::Decimal128", "Arrow::Decimal256"
187
+ case method_name
188
+ when "copy"
189
+ method_name = "dup"
190
+ end
191
+ super(info, klass, method_name)
192
+ when "Arrow::BooleanScalar"
193
+ case method_name
194
+ when "value?"
195
+ method_name = "value"
196
+ end
197
+ super(info, klass, method_name)
152
198
  else
153
199
  super
154
200
  end