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,32 @@
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 Scalar
20
+ # @param other [Arrow::Scalar] The scalar to be compared.
21
+ # @param options [Arrow::EqualOptions, Hash] (nil)
22
+ # The options to custom how to compare.
23
+ #
24
+ # @return [Boolean]
25
+ # `true` if both of them have the same data, `false` otherwise.
26
+ #
27
+ # @since 5.0.0
28
+ def equal_scalar?(other, options=nil)
29
+ equal_options(other, options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,193 @@
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 SortKey
20
+ class << self
21
+ # Ensure returning suitable {Arrow::SortKey}.
22
+ #
23
+ # @overload resolve(sort_key)
24
+ #
25
+ # Returns the given sort key itself. This is convenient to use
26
+ # this method as {Arrow::SortKey} converter.
27
+ #
28
+ # @param sort_key [Arrow::SortKey] The sort key.
29
+ #
30
+ # @return [Arrow::SortKey] The given sort key itself.
31
+ #
32
+ # @overload resolve(name)
33
+ #
34
+ # Creates a new suitable sort key from column name with
35
+ # leading order mark. See {#initialize} for details about
36
+ # order mark.
37
+ #
38
+ # @return [Arrow::SortKey] A new suitable sort key.
39
+ #
40
+ # @overload resolve(name, order)
41
+ #
42
+ # Creates a new suitable sort key from column name without
43
+ # leading order mark and order. See {#initialize} for details.
44
+ #
45
+ # @return [Arrow::SortKey] A new suitable sort key.
46
+ #
47
+ # @since 4.0.0
48
+ def resolve(name, order=nil)
49
+ return name if name.is_a?(self)
50
+ new(name, order)
51
+ end
52
+
53
+ # @api private
54
+ def try_convert(value)
55
+ case value
56
+ when Symbol, String
57
+ new(value.to_s, :ascending)
58
+ else
59
+ nil
60
+ end
61
+ end
62
+ end
63
+
64
+ alias_method :initialize_raw, :initialize
65
+ private :initialize_raw
66
+ # Creates a new {Arrow::SortKey}.
67
+ #
68
+ # @overload initialize(name)
69
+ #
70
+ # @param name [Symbol, String] The name of the sort column.
71
+ #
72
+ # If `name` is a String, the first character may be processed
73
+ # as the "leading order mark". If the first character is `"+"`
74
+ # or `"-"`, they are processed as a leading order mark. If the
75
+ # first character is processed as a leading order mark, the
76
+ # first character is removed from sort column name and
77
+ # corresponding order is used. `"+"` uses ascending order and
78
+ # `"-"` uses ascending order.
79
+ #
80
+ # If `name` is not a String nor `name` doesn't start with the
81
+ # leading order mark, sort column name is `name` as-is and
82
+ # ascending order is used.
83
+ #
84
+ # @example String without the leading order mark
85
+ # key = Arrow::SortKey.new("count")
86
+ # key.name # => "count"
87
+ # key.order # => Arrow::SortOrder::ASCENDING
88
+ #
89
+ # @example String with the "+" leading order mark
90
+ # key = Arrow::SortKey.new("+count")
91
+ # key.name # => "count"
92
+ # key.order # => Arrow::SortOrder::ASCENDING
93
+ #
94
+ # @example String with the "-" leading order mark
95
+ # key = Arrow::SortKey.new("-count")
96
+ # key.name # => "count"
97
+ # key.order # => Arrow::SortOrder::DESCENDING
98
+ #
99
+ # @example Symbol that starts with "-"
100
+ # key = Arrow::SortKey.new(:"-count")
101
+ # key.name # => "-count"
102
+ # key.order # => Arrow::SortOrder::ASCENDING
103
+ #
104
+ # @overload initialize(name, order)
105
+ #
106
+ # @param name [Symbol, String] The name of the sort column.
107
+ #
108
+ # No leading order mark processing. The given `name` is used
109
+ # as-is.
110
+ #
111
+ # @param order [Symbol, String, Arrow::SortOrder] How to order
112
+ # by this sort key.
113
+ #
114
+ # If this is a Symbol or String, this must be `:ascending`,
115
+ # `"ascending"`, `:asc`, `"asc"`, `:descending`,
116
+ # `"descending"`, `:desc` or `"desc"`.
117
+ #
118
+ # @example No leading order mark processing
119
+ # key = Arrow::SortKey.new("-count", :ascending)
120
+ # key.name # => "-count"
121
+ # key.order # => Arrow::SortOrder::ASCENDING
122
+ #
123
+ # @example Order by abbreviated name with Symbol
124
+ # key = Arrow::SortKey.new("count", :desc)
125
+ # key.name # => "count"
126
+ # key.order # => Arrow::SortOrder::DESCENDING
127
+ #
128
+ # @example Order by String
129
+ # key = Arrow::SortKey.new("count", "descending")
130
+ # key.name # => "count"
131
+ # key.order # => Arrow::SortOrder::DESCENDING
132
+ #
133
+ # @example Order by Arrow::SortOrder
134
+ # key = Arrow::SortKey.new("count", Arrow::SortOrder::DESCENDING)
135
+ # key.name # => "count"
136
+ # key.order # => Arrow::SortOrder::DESCENDING
137
+ #
138
+ # @since 4.0.0
139
+ def initialize(name, order=nil)
140
+ name, order = normalize_name(name, order)
141
+ order = normalize_order(order) || :ascending
142
+ initialize_raw(name, order)
143
+ end
144
+
145
+ # @return [String] The string representation of this sort key. You
146
+ # can use recreate {Arrow::SortKey} by
147
+ # `Arrow::SortKey.new(key.to_s)`.
148
+ #
149
+ # @example Recreate Arrow::SortKey
150
+ # key = Arrow::SortKey.new("-count")
151
+ # key.to_s # => "-count"
152
+ # key == Arrow::SortKey.new(key.to_s) # => true
153
+ #
154
+ # @since 4.0.0
155
+ def to_s
156
+ if order == SortOrder::ASCENDING
157
+ "+#{name}"
158
+ else
159
+ "-#{name}"
160
+ end
161
+ end
162
+
163
+ private
164
+ def normalize_name(name, order)
165
+ case name
166
+ when Symbol
167
+ return name.to_s, order
168
+ when String
169
+ return name, order if order
170
+ if name.start_with?("-")
171
+ return name[1..-1], order || :descending
172
+ elsif name.start_with?("+")
173
+ return name[1..-1], order || :ascending
174
+ else
175
+ return name, order
176
+ end
177
+ else
178
+ return name, order
179
+ end
180
+ end
181
+
182
+ def normalize_order(order)
183
+ case order
184
+ when :asc, "asc"
185
+ :ascending
186
+ when :desc, "desc"
187
+ :descending
188
+ else
189
+ order
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,109 @@
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 SortOptions
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when Symbol, String
25
+ new(value)
26
+ when ::Array
27
+ new(*value)
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+
34
+ alias_method :initialize_raw, :initialize
35
+ private :initialize_raw
36
+ # @param sort_keys [::Array<String, Symbol, Arrow::SortKey>] The
37
+ # sort keys to be used. See {Arrow::SortKey.resolve} how to
38
+ # resolve each sort key in `sort_keys`.
39
+ #
40
+ # You can add more sort keys by {#add_sort_key} later.
41
+ #
42
+ # @example No initial sort keys
43
+ # options = Arrow::SortOptions.new
44
+ # options.sort_keys # => []
45
+ #
46
+ # @example String sort keys
47
+ # options = Arrow::SortOptions.new("count", "-age")
48
+ # options.sort_keys.collect(&:to_s) # => ["+count", "-age"]
49
+ #
50
+ # @example Symbol sort keys
51
+ # options = Arrow::SortOptions.new(:count, :age)
52
+ # options.sort_keys.collect(&:to_s) # => ["+count", "+age"]
53
+ #
54
+ # @example Mixed sort keys
55
+ # options = Arrow::SortOptions.new(:count, "-age")
56
+ # options.sort_keys.collect(&:to_s) # => ["+count", "-age"]
57
+ #
58
+ # @since 4.0.0
59
+ def initialize(*sort_keys)
60
+ initialize_raw
61
+ sort_keys.each do |sort_key|
62
+ add_sort_key(sort_key)
63
+ end
64
+ end
65
+
66
+ # @api private
67
+ alias_method :add_sort_key_raw, :add_sort_key
68
+ # Add a sort key.
69
+ #
70
+ # @return [void]
71
+ #
72
+ # @overload add_sort_key(key)
73
+ #
74
+ # @param key [Arrow::SortKey] The sort key to be added.
75
+ #
76
+ # @example Add a key to sort by "price" column in descending order
77
+ # options = Arrow::SortOptions.new
78
+ # options.add_sort_key(Arrow::SortKey.new(:price, :descending))
79
+ # options.sort_keys.collect(&:to_s) # => ["-price"]
80
+ #
81
+ # @overload add_sort_key(name)
82
+ #
83
+ # @param name [Symbol, String] The sort key name to be
84
+ # added. See also {Arrow::SortKey#initialize} for the leading
85
+ # order mark for String name.
86
+ #
87
+ # @example Add a key to sort by "price" column in descending order
88
+ # options = Arrow::SortOptions.new
89
+ # options.add_sort_key("-price")
90
+ # options.sort_keys.collect(&:to_s) # => ["-price"]
91
+ #
92
+ # @overload add_sort_key(name, order)
93
+ #
94
+ # @param name [Symbol, String] The sort key name.
95
+ #
96
+ # @param order [Symbol, String, Arrow::SortOrder] The sort
97
+ # order. See {Arrow::SortKey#initialize} for details.
98
+ #
99
+ # @example Add a key to sort by "price" column in descending order
100
+ # options = Arrow::SortOptions.new
101
+ # options.add_sort_key("price", :desc)
102
+ # options.sort_keys.collect(&:to_s) # => ["-price"]
103
+ #
104
+ # @since 4.0.0
105
+ def add_sort_key(name, order=nil)
106
+ add_sort_key_raw(SortKey.resolve(name, order))
107
+ end
108
+ end
109
+ 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 sparse union data type for {2: visible, 9: count}
36
+ # @example Create a sparse 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 sparse union data type for {2: visible, 9: count}
60
+ # @example Create a sparse union data type for `{2: visible, 9: count}`
61
61
  # fields = [
62
62
  # Arrow::Field.new("visible", :boolean),
63
63
  # {
data/lib/arrow/table.rb CHANGED
@@ -442,8 +442,8 @@ module Arrow
442
442
  RollingWindow.new(self, size)
443
443
  end
444
444
 
445
- def save(path, options={})
446
- saver = TableSaver.new(self, path, options)
445
+ def save(output, options={})
446
+ saver = TableSaver.new(self, output, options)
447
447
  saver.save
448
448
  end
449
449
 
@@ -29,7 +29,7 @@ module Arrow
29
29
  #
30
30
  # The unit must be second or millisecond.
31
31
  #
32
- # @example Create a time32 data type with {Arrow::TimeUnit}
32
+ # @example Create a time32 data type with Arrow::TimeUnit
33
33
  # Arrow::Time32DataType.new(Arrow::TimeUnit::MILLI)
34
34
  #
35
35
  # @example Create a time32 data type with Symbol
@@ -45,7 +45,7 @@ module Arrow
45
45
  #
46
46
  # The unit must be second or millisecond.
47
47
  #
48
- # @example Create a time32 data type with {Arrow::TimeUnit}
48
+ # @example Create a time32 data type with Arrow::TimeUnit
49
49
  # Arrow::Time32DataType.new(unit: Arrow::TimeUnit::MILLI)
50
50
  #
51
51
  # @example Create a time32 data type with Symbol
@@ -29,7 +29,7 @@ module Arrow
29
29
  #
30
30
  # The unit must be microsecond or nanosecond.
31
31
  #
32
- # @example Create a time64 data type with {Arrow::TimeUnit}
32
+ # @example Create a time64 data type with Arrow::TimeUnit
33
33
  # Arrow::Time64DataType.new(Arrow::TimeUnit::NANO)
34
34
  #
35
35
  # @example Create a time64 data type with Symbol
@@ -45,7 +45,7 @@ module Arrow
45
45
  #
46
46
  # The unit must be microsecond or nanosecond.
47
47
  #
48
- # @example Create a time64 data type with {Arrow::TimeUnit}
48
+ # @example Create a time64 data type with Arrow::TimeUnit
49
49
  # Arrow::Time64DataType.new(unit: Arrow::TimeUnit::NANO)
50
50
  #
51
51
  # @example Create a time64 data type with Symbol
@@ -27,7 +27,7 @@ module Arrow
27
27
  # @param unit [Arrow::TimeUnit, Symbol] The unit of the
28
28
  # timestamp data type.
29
29
  #
30
- # @example Create a timestamp data type with {Arrow::TimeUnit}
30
+ # @example Create a timestamp data type with Arrow::TimeUnit
31
31
  # Arrow::TimestampDataType.new(Arrow::TimeUnit::MILLI)
32
32
  #
33
33
  # @example Create a timestamp data type with Symbol
@@ -41,7 +41,7 @@ module Arrow
41
41
  # @option description [Arrow::TimeUnit, Symbol] :unit The unit of
42
42
  # the timestamp data type.
43
43
  #
44
- # @example Create a timestamp data type with {Arrow::TimeUnit}
44
+ # @example Create a timestamp data type with Arrow::TimeUnit
45
45
  # Arrow::TimestampDataType.new(unit: Arrow::TimeUnit::MILLI)
46
46
  #
47
47
  # @example Create a timestamp data type with Symbol
data/lib/arrow/version.rb CHANGED
@@ -16,7 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  module Arrow
19
- VERSION = "2.0.0"
19
+ VERSION = "5.0.0"
20
20
 
21
21
  module Version
22
22
  numbers, TAG = VERSION.split("-")
data/red-arrow.gemspec CHANGED
@@ -46,14 +46,16 @@ Gem::Specification.new do |spec|
46
46
  spec.test_files += Dir.glob("test/**/*")
47
47
  spec.extensions = ["ext/arrow/extconf.rb"]
48
48
 
49
+ spec.add_runtime_dependency("bigdecimal", ">= 2.0.3")
49
50
  spec.add_runtime_dependency("extpp", ">= 0.0.7")
50
- spec.add_runtime_dependency("gio2", ">= 3.3.6")
51
+ spec.add_runtime_dependency("gio2", ">= 3.4.5")
51
52
  spec.add_runtime_dependency("native-package-installer")
52
53
  spec.add_runtime_dependency("pkg-config")
53
54
 
54
55
  spec.add_development_dependency("benchmark-driver")
55
56
  spec.add_development_dependency("bundler")
56
57
  spec.add_development_dependency("faker")
58
+ spec.add_development_dependency("fiddle", ">= 1.0.9")
57
59
  spec.add_development_dependency("rake")
58
60
  spec.add_development_dependency("redcarpet")
59
61
  spec.add_development_dependency("test-unit")