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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 171c7e5854ed116c8324153272827255b18f1083d5ae38866903b3cb0faa2977
4
- data.tar.gz: 86c21238d83c5e4a8d114464eb8281dca5ddaff7cb6fb3e08b858a67082d4514
3
+ metadata.gz: a70c1505c294a8f74c992ec0f2ab5d651647e45dd178db8523f5b5c01e64a541
4
+ data.tar.gz: dad979599033104a25d5be3d05c57e552c803f9c8002d66b757866c425937ce9
5
5
  SHA512:
6
- metadata.gz: f46692362251101f0d18782e755dd3e2453a168ddefc564a623cc6f16a336d974fca83079faa63198b201e88e3fc678552bd69adca86bf743daf5ef7cd432ff2
7
- data.tar.gz: 887b098b1d9b832a9197a9ef08e7be63e2d12b1772c45054e02b582d47bc8382c6d73645fce3ea2982d9b1f73454a78fe8372a7b01879cb1d865b971167bc2ad
6
+ metadata.gz: b2363ba6468985a3d237cbb9cec8b2ccb5031aae94153b8f263916e811524e8a5326f408867a843b7077f624050fabcde93520b26e6f8ceb1dd094aaa0068ed6
7
+ data.tar.gz: 797b89062dfd212d92ca957b8e51c6dc8acf16ab51e5a60ecb0cbf31dd979c288f2afb71274b2235a24d31da344cfce93b40830d6dc6edd000ce0aa607ce8cde
@@ -212,7 +212,17 @@ namespace red_arrow {
212
212
 
213
213
  inline VALUE convert(const arrow::Decimal128Array& array,
214
214
  const int64_t i) {
215
- decimal_buffer_ = array.FormatValue(i);
215
+ return convert_decimal(std::move(array.FormatValue(i)));
216
+ }
217
+
218
+ inline VALUE convert(const arrow::Decimal256Array& array,
219
+ const int64_t i) {
220
+ return convert_decimal(std::move(array.FormatValue(i)));
221
+ }
222
+
223
+ private:
224
+ inline VALUE convert_decimal(std::string&& value) {
225
+ decimal_buffer_ = value;
216
226
  return rb_funcall(rb_cObject,
217
227
  id_BigDecimal,
218
228
  1,
@@ -221,7 +231,6 @@ namespace red_arrow {
221
231
  rb_ascii8bit_encoding()));
222
232
  }
223
233
 
224
- private:
225
234
  std::string decimal_buffer_;
226
235
  ListArrayValueConverter* list_array_value_converter_;
227
236
  StructArrayValueConverter* struct_array_value_converter_;
@@ -289,6 +298,7 @@ namespace red_arrow {
289
298
  VISIT(DenseUnion)
290
299
  VISIT(Dictionary)
291
300
  VISIT(Decimal128)
301
+ VISIT(Decimal256)
292
302
  // TODO
293
303
  // VISIT(Extension)
294
304
 
@@ -393,6 +403,7 @@ namespace red_arrow {
393
403
  VISIT(DenseUnion)
394
404
  VISIT(Dictionary)
395
405
  VISIT(Decimal128)
406
+ VISIT(Decimal256)
396
407
  // TODO
397
408
  // VISIT(Extension)
398
409
 
@@ -485,6 +496,7 @@ namespace red_arrow {
485
496
  VISIT(DenseUnion)
486
497
  VISIT(Dictionary)
487
498
  VISIT(Decimal128)
499
+ VISIT(Decimal256)
488
500
  // TODO
489
501
  // VISIT(Extension)
490
502
 
@@ -609,6 +621,7 @@ namespace red_arrow {
609
621
  VISIT(DenseUnion)
610
622
  VISIT(Dictionary)
611
623
  VISIT(Decimal128)
624
+ VISIT(Decimal256)
612
625
  // TODO
613
626
  // VISIT(Extension)
614
627
 
@@ -104,6 +104,7 @@ namespace red_arrow {
104
104
  VISIT(DenseUnion)
105
105
  VISIT(Dictionary)
106
106
  VISIT(Decimal128)
107
+ VISIT(Decimal256)
107
108
  // TODO
108
109
  // VISIT(Extension)
109
110
 
@@ -85,6 +85,7 @@ namespace red_arrow {
85
85
  VISIT(DenseUnion)
86
86
  VISIT(Dictionary)
87
87
  VISIT(Decimal128)
88
+ VISIT(Decimal256)
88
89
  // TODO
89
90
  // VISIT(Extension)
90
91
 
@@ -115,6 +115,17 @@ module Arrow
115
115
  builder: Date32ArrayBuilder.new,
116
116
  detected: true,
117
117
  }
118
+ when BigDecimal
119
+ if value.to_arrow.is_a?(Decimal128)
120
+ {
121
+ builder: Decimal128ArrayBuilder.new,
122
+ }
123
+ else
124
+ {
125
+ builder: Decimal256ArrayBuilder.new,
126
+ detected: true,
127
+ }
128
+ end
118
129
  when ::Array
119
130
  sub_builder_info = nil
120
131
  value.each do |sub_value|
@@ -194,11 +205,5 @@ module Arrow
194
205
  end
195
206
  end
196
207
  end
197
-
198
- def append_nulls(n)
199
- n.times do
200
- append_null
201
- end
202
- end
203
208
  end
204
209
  end
@@ -19,6 +19,10 @@ require "bigdecimal"
19
19
 
20
20
  class BigDecimal
21
21
  def to_arrow
22
- Arrow::Decimal128.new(to_s)
22
+ if precision <= Arrow::Decimal128DataType::MAX_PRECISION
23
+ Arrow::Decimal128.new(to_s)
24
+ else
25
+ Arrow::Decimal256.new(to_s)
26
+ end
23
27
  end
24
28
  end
@@ -26,36 +26,32 @@ module Arrow
26
26
 
27
27
  alias_method :append_value_raw, :append_value
28
28
  def append_value(value)
29
- case value
30
- when nil
31
- return append_null
32
- when String
33
- value = Decimal128.new(value)
34
- when Float
35
- value = Decimal128.new(value.to_s)
36
- when BigDecimal
37
- value = value.to_arrow
38
- end
39
- append_value_raw(value)
29
+ append_value_raw(normalize_value(value))
40
30
  end
41
31
 
32
+ alias_method :append_values_raw, :append_values
42
33
  def append_values(values, is_valids=nil)
43
- if is_valids
44
- is_valids.each_with_index do |is_valid, i|
45
- if is_valid
46
- append_value(values[i])
47
- else
48
- append_null
49
- end
34
+ if values.is_a?(::Array)
35
+ values = values.collect do |value|
36
+ normalize_value(value)
50
37
  end
38
+ append_values_raw(values, is_valids)
51
39
  else
52
- values.each do |value|
53
- if value.nil?
54
- append_null
55
- else
56
- append_value(value)
57
- end
58
- end
40
+ append_values_packed(values, is_valids)
41
+ end
42
+ end
43
+
44
+ private
45
+ def normalize_value(value)
46
+ case value
47
+ when String
48
+ Decimal128.new(value)
49
+ when Float
50
+ Decimal128.new(value.to_s)
51
+ when BigDecimal
52
+ Decimal128.new(value.to_s)
53
+ else
54
+ value
59
55
  end
60
56
  end
61
57
  end
@@ -17,6 +17,8 @@
17
17
 
18
18
  module Arrow
19
19
  class Decimal128DataType
20
+ MAX_PRECISION = max_precision
21
+
20
22
  alias_method :initialize_raw, :initialize
21
23
  private :initialize_raw
22
24
 
@@ -38,5 +38,23 @@ module Arrow
38
38
  to_s_raw
39
39
  end
40
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
41
59
  end
42
60
  end
@@ -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
@@ -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