red-arrow 0.17.1 → 4.0.0

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/ext/arrow/converters.hpp +75 -32
  3. data/ext/arrow/extconf.rb +14 -3
  4. data/ext/arrow/raw-records.cpp +3 -1
  5. data/ext/arrow/values.cpp +3 -1
  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/buffer.rb +28 -0
  10. data/lib/arrow/data-type.rb +14 -5
  11. data/lib/arrow/decimal128-array-builder.rb +21 -25
  12. data/lib/arrow/decimal128-data-type.rb +2 -0
  13. data/lib/arrow/decimal128.rb +18 -0
  14. data/lib/arrow/decimal256-array-builder.rb +61 -0
  15. data/lib/arrow/decimal256-array.rb +25 -0
  16. data/lib/arrow/decimal256-data-type.rb +73 -0
  17. data/lib/arrow/decimal256.rb +60 -0
  18. data/lib/arrow/dense-union-data-type.rb +2 -2
  19. data/lib/arrow/dictionary-array.rb +24 -0
  20. data/lib/arrow/dictionary-data-type.rb +2 -2
  21. data/lib/arrow/fixed-size-binary-array-builder.rb +38 -0
  22. data/lib/arrow/fixed-size-binary-array.rb +26 -0
  23. data/lib/arrow/loader.rb +18 -0
  24. data/lib/arrow/raw-table-converter.rb +47 -0
  25. data/lib/arrow/record-batch-iterator.rb +22 -0
  26. data/lib/arrow/record-batch.rb +9 -1
  27. data/lib/arrow/sort-key.rb +193 -0
  28. data/lib/arrow/sort-options.rb +109 -0
  29. data/lib/arrow/sparse-union-data-type.rb +2 -2
  30. data/lib/arrow/struct-array-builder.rb +13 -7
  31. data/lib/arrow/table-saver.rb +6 -6
  32. data/lib/arrow/table.rb +5 -24
  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 +1 -0
  38. data/test/raw-records/test-basic-arrays.rb +17 -0
  39. data/test/raw-records/test-dense-union-array.rb +15 -34
  40. data/test/raw-records/test-list-array.rb +20 -0
  41. data/test/raw-records/test-sparse-union-array.rb +15 -33
  42. data/test/raw-records/test-struct-array.rb +15 -0
  43. data/test/test-array.rb +122 -2
  44. data/test/test-bigdecimal.rb +20 -3
  45. data/test/test-buffer.rb +11 -0
  46. data/test/test-decimal128-array-builder.rb +18 -1
  47. data/test/test-decimal128-data-type.rb +2 -2
  48. data/test/test-decimal128.rb +38 -0
  49. data/test/test-decimal256-array-builder.rb +112 -0
  50. data/test/test-decimal256-array.rb +38 -0
  51. data/test/test-decimal256-data-type.rb +31 -0
  52. data/test/test-decimal256.rb +102 -0
  53. data/test/test-dense-union-data-type.rb +2 -2
  54. data/test/test-dictionary-array.rb +41 -0
  55. data/test/test-feather.rb +1 -1
  56. data/test/test-fixed-size-binary-array-builder.rb +92 -0
  57. data/test/test-fixed-size-binary-array.rb +36 -0
  58. data/test/test-orc.rb +19 -23
  59. data/test/test-record-batch-iterator.rb +37 -0
  60. data/test/test-record-batch.rb +14 -0
  61. data/test/test-sort-indices.rb +40 -0
  62. data/test/test-sort-key.rb +81 -0
  63. data/test/test-sort-options.rb +58 -0
  64. data/test/test-sparse-union-data-type.rb +2 -2
  65. data/test/test-struct-array-builder.rb +16 -12
  66. data/test/test-struct-array.rb +2 -2
  67. data/test/values/test-basic-arrays.rb +11 -0
  68. data/test/values/test-dense-union-array.rb +15 -34
  69. data/test/values/test-list-array.rb +18 -0
  70. data/test/values/test-sparse-union-array.rb +15 -33
  71. data/test/values/test-struct-array.rb +15 -0
  72. metadata +107 -59
@@ -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
@@ -0,0 +1,28 @@
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 Buffer
20
+ alias_method :initialize_raw, :initialize
21
+ private :initialize_raw
22
+
23
+ def initialize(data)
24
+ @data = data
25
+ initialize_raw(data)
26
+ end
27
+ end
28
+ end
@@ -18,7 +18,7 @@
18
18
  module Arrow
19
19
  class DataType
20
20
  class << self
21
- # Creates a new suitable {Arrow::DataType}.
21
+ # Ensure returning suitable {Arrow::DataType}.
22
22
  #
23
23
  # @overload resolve(data_type)
24
24
  #
@@ -31,17 +31,21 @@ module Arrow
31
31
  #
32
32
  # @overload resolve(name)
33
33
  #
34
- # Creates a suitable data type from type name. For example,
35
- # you can create {Arrow::BooleanDataType} from `:boolean`.
34
+ # Creates a suitable data type from the given type name. For
35
+ # example, you can create {Arrow::BooleanDataType} from
36
+ # `:boolean`.
36
37
  #
37
38
  # @param name [String, Symbol] The type name of the data type.
38
39
  #
40
+ # @return [Arrow::DataType] A new suitable data type.
41
+ #
39
42
  # @example Create a boolean data type
40
43
  # Arrow::DataType.resolve(:boolean)
41
44
  #
42
45
  # @overload resolve(name_with_arguments)
43
46
  #
44
- # Creates a suitable data type from type name with arguments.
47
+ # Creates a new suitable data type from the given type name
48
+ # with arguments.
45
49
  #
46
50
  # @param name_with_arguments [::Array<String, ...>]
47
51
  # The type name of the data type as the first element.
@@ -51,6 +55,8 @@ module Arrow
51
55
  # For example, {Arrow::TimestampDataType} needs unit as
52
56
  # additional information.
53
57
  #
58
+ # @return [Arrow::DataType] A new suitable data type.
59
+ #
54
60
  # @example Create a boolean data type
55
61
  # Arrow::DataType.resolve([:boolean])
56
62
  #
@@ -59,7 +65,8 @@ module Arrow
59
65
  #
60
66
  # @overload resolve(description)
61
67
  #
62
- # Creates a suitable data type from data type description.
68
+ # Creates a new suitable data type from the given data type
69
+ # description.
63
70
  #
64
71
  # Data type description is a raw `Hash`. Data type description
65
72
  # must have `:type` value. `:type` is the type of the data type.
@@ -74,6 +81,8 @@ module Arrow
74
81
  # @option description [String, Symbol] :type The type name of
75
82
  # the data type.
76
83
  #
84
+ # @return [Arrow::DataType] A new suitable data type.
85
+ #
77
86
  # @example Create a boolean data type
78
87
  # Arrow::DataType.resolve(type: :boolean)
79
88
  #
@@ -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
@@ -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
  # {
@@ -0,0 +1,24 @@
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 DictionaryArray
20
+ def get_value(i)
21
+ dictionary[indices[i]]
22
+ end
23
+ end
24
+ end