red-arrow 6.0.0 → 8.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -0
  3. data/ext/arrow/arrow.cpp +12 -0
  4. data/ext/arrow/converters.hpp +46 -10
  5. data/ext/arrow/extconf.rb +1 -1
  6. data/ext/arrow/raw-records.cpp +3 -2
  7. data/ext/arrow/red-arrow.hpp +7 -0
  8. data/ext/arrow/values.cpp +3 -2
  9. data/lib/arrow/datum.rb +2 -0
  10. data/lib/arrow/day-time-interval-array-builder.rb +29 -0
  11. data/lib/arrow/function.rb +52 -0
  12. data/lib/arrow/loader.rb +16 -0
  13. data/lib/arrow/month-day-nano-interval-array-builder.rb +29 -0
  14. data/lib/arrow/s3-global-options.rb +38 -0
  15. data/lib/arrow/sort-key.rb +61 -55
  16. data/lib/arrow/sort-options.rb +8 -8
  17. data/lib/arrow/table-loader.rb +99 -62
  18. data/lib/arrow/table-saver.rb +7 -2
  19. data/lib/arrow/table.rb +78 -0
  20. data/lib/arrow/version.rb +1 -1
  21. data/red-arrow.gemspec +1 -10
  22. data/test/helper.rb +2 -0
  23. data/test/raw-records/test-basic-arrays.rb +30 -0
  24. data/test/raw-records/test-dense-union-array.rb +27 -0
  25. data/test/raw-records/test-list-array.rb +39 -0
  26. data/test/raw-records/test-map-array.rb +37 -0
  27. data/test/raw-records/test-sparse-union-array.rb +27 -0
  28. data/test/raw-records/test-struct-array.rb +30 -0
  29. data/test/test-function.rb +48 -14
  30. data/test/test-table.rb +204 -6
  31. data/test/values/test-basic-arrays.rb +30 -0
  32. data/test/values/test-dense-union-array.rb +27 -0
  33. data/test/values/test-dictionary-array.rb +295 -0
  34. data/test/values/test-list-array.rb +39 -0
  35. data/test/values/test-map-array.rb +33 -0
  36. data/test/values/test-sparse-union-array.rb +27 -0
  37. data/test/values/test-struct-array.rb +30 -0
  38. metadata +88 -194
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c553e573f87398da7d492e8339684bb86b73d1fff02b56cff3277bb87d96a4cd
4
- data.tar.gz: 9b97be2878369da0bed9ac8621330926b8a95144d833de6798858a210f88c92a
3
+ metadata.gz: f43d3875f2e48876cd47533124a9fcf9559e263e63e3954c65fedd36b4e59744
4
+ data.tar.gz: 2548f661536d3288f4ad8bb25d6587a78ee51d810a85a7d533ccdaf595439a12
5
5
  SHA512:
6
- metadata.gz: 0bc3526645457a551e25621ba3efaa52a3ad7398e8216c34440651beab58886ec8b52804b7afe227f953b727871980a2ac9a9b1153776499b48cd790ae476304
7
- data.tar.gz: 9f3032d5a54a9b0b911edd273916ce68f140c50753d13cb88b950166ea771138f432d738a3a694f44bfff985fcf8329457e97712dca10a7f8a8430d3d8cb82f6
6
+ metadata.gz: caeffbc164f14db7b056263f1ecd449afe2feec3ccbf7b883c147d415199c9ddc6c20398b00c34884248c103fbb7c55aa225719d8b8e75ac7f49337ee89d557e
7
+ data.tar.gz: ae5a793e06b63bd80e3499f794193f47f72ff7510a558d2d0e61314068d5bd3a1986e5083bda749b00b73a4615901beb320521eeb360576b93fcb9a1e9d9510a
data/Gemfile CHANGED
@@ -20,3 +20,13 @@
20
20
  source "https://rubygems.org/"
21
21
 
22
22
  gemspec
23
+
24
+ gem "benchmark-driver"
25
+ gem "bundler"
26
+ gem "faker"
27
+ gem "fiddle", ">= 1.0.9"
28
+ gem "rake"
29
+ gem "redcarpet"
30
+ gem "test-unit"
31
+ gem "webrick"
32
+ gem "yard"
data/ext/arrow/arrow.cpp CHANGED
@@ -36,6 +36,13 @@ namespace red_arrow {
36
36
  ID id_jd;
37
37
  ID id_new;
38
38
  ID id_to_datetime;
39
+
40
+ namespace symbols {
41
+ VALUE day;
42
+ VALUE millisecond;
43
+ VALUE month;
44
+ VALUE nanosecond;
45
+ }
39
46
  }
40
47
 
41
48
  extern "C" void Init_arrow() {
@@ -81,4 +88,9 @@ extern "C" void Init_arrow() {
81
88
  red_arrow::id_to_datetime = rb_intern("to_datetime");
82
89
 
83
90
  red_arrow::memory_view::init(mArrow);
91
+
92
+ red_arrow::symbols::day = ID2SYM(rb_intern("day"));
93
+ red_arrow::symbols::millisecond = ID2SYM(rb_intern("millisecond"));
94
+ red_arrow::symbols::month = ID2SYM(rb_intern("month"));
95
+ red_arrow::symbols::nanosecond = ID2SYM(rb_intern("nanosecond"));
84
96
  }
@@ -202,6 +202,40 @@ namespace red_arrow {
202
202
  // const int64_t i) {
203
203
  // };
204
204
 
205
+ inline VALUE convert(const arrow::MonthIntervalArray& array,
206
+ const int64_t i) {
207
+ return INT2NUM(array.Value(i));
208
+ }
209
+
210
+ inline VALUE convert(const arrow::DayTimeIntervalArray& array,
211
+ const int64_t i) {
212
+ auto value = rb_hash_new();
213
+ auto arrow_value = array.Value(i);
214
+ rb_hash_aset(value,
215
+ red_arrow::symbols::day,
216
+ INT2NUM(arrow_value.days));
217
+ rb_hash_aset(value,
218
+ red_arrow::symbols::millisecond,
219
+ INT2NUM(arrow_value.milliseconds));
220
+ return value;
221
+ }
222
+
223
+ inline VALUE convert(const arrow::MonthDayNanoIntervalArray& array,
224
+ const int64_t i) {
225
+ auto value = rb_hash_new();
226
+ auto arrow_value = array.Value(i);
227
+ rb_hash_aset(value,
228
+ red_arrow::symbols::month,
229
+ INT2NUM(arrow_value.months));
230
+ rb_hash_aset(value,
231
+ red_arrow::symbols::day,
232
+ INT2NUM(arrow_value.days));
233
+ rb_hash_aset(value,
234
+ red_arrow::symbols::nanosecond,
235
+ INT2NUM(arrow_value.nanoseconds));
236
+ return value;
237
+ }
238
+
205
239
  VALUE convert(const arrow::ListArray& array,
206
240
  const int64_t i);
207
241
 
@@ -298,8 +332,9 @@ namespace red_arrow {
298
332
  VISIT(Time32)
299
333
  VISIT(Time64)
300
334
  VISIT(Timestamp)
301
- // TODO
302
- // VISIT(Interval)
335
+ VISIT(MonthInterval)
336
+ VISIT(DayTimeInterval)
337
+ VISIT(MonthDayNanoInterval)
303
338
  VISIT(List)
304
339
  VISIT(Struct)
305
340
  VISIT(Map)
@@ -404,8 +439,9 @@ namespace red_arrow {
404
439
  VISIT(Time32)
405
440
  VISIT(Time64)
406
441
  VISIT(Timestamp)
407
- // TODO
408
- // VISIT(Interval)
442
+ VISIT(MonthInterval)
443
+ VISIT(DayTimeInterval)
444
+ VISIT(MonthDayNanoInterval)
409
445
  VISIT(List)
410
446
  VISIT(Struct)
411
447
  VISIT(Map)
@@ -506,8 +542,9 @@ namespace red_arrow {
506
542
  VISIT(Time32)
507
543
  VISIT(Time64)
508
544
  VISIT(Timestamp)
509
- // TODO
510
- // VISIT(Interval)
545
+ VISIT(MonthInterval)
546
+ VISIT(DayTimeInterval)
547
+ VISIT(MonthDayNanoInterval)
511
548
  VISIT(List)
512
549
  VISIT(Struct)
513
550
  VISIT(Map)
@@ -609,8 +646,9 @@ namespace red_arrow {
609
646
  VISIT(Time32)
610
647
  VISIT(Time64)
611
648
  VISIT(Timestamp)
612
- // TODO
613
- // VISIT(Interval)
649
+ VISIT(MonthInterval)
650
+ VISIT(DayTimeInterval)
651
+ VISIT(MonthDayNanoInterval)
614
652
  VISIT(List)
615
653
  VISIT(Struct)
616
654
  VISIT(Map)
@@ -735,8 +773,6 @@ namespace red_arrow {
735
773
  VISIT(Time32)
736
774
  VISIT(Time64)
737
775
  VISIT(Timestamp)
738
- // TODO
739
- // VISIT(Interval)
740
776
  VISIT(List)
741
777
  VISIT(Struct)
742
778
  VISIT(Map)
data/ext/arrow/extconf.rb CHANGED
@@ -28,7 +28,7 @@ end
28
28
  checking_for(checking_message("Homebrew")) do
29
29
  platform = NativePackageInstaller::Platform.detect
30
30
  if platform.is_a?(NativePackageInstaller::Platform::Homebrew)
31
- openssl_prefix = `brew --prefix openssl@1.1`.chomp
31
+ openssl_prefix = `brew --prefix openssl`.chomp
32
32
  unless openssl_prefix.empty?
33
33
  PKGConfig.add_path("#{openssl_prefix}/lib/pkgconfig")
34
34
  end
@@ -96,8 +96,9 @@ namespace red_arrow {
96
96
  VISIT(Time32)
97
97
  VISIT(Time64)
98
98
  VISIT(Timestamp)
99
- // TODO
100
- // VISIT(Interval)
99
+ VISIT(MonthInterval)
100
+ VISIT(DayTimeInterval)
101
+ VISIT(MonthDayNanoInterval)
101
102
  VISIT(List)
102
103
  VISIT(Struct)
103
104
  VISIT(Map)
@@ -47,6 +47,13 @@ namespace red_arrow {
47
47
  extern ID id_new;
48
48
  extern ID id_to_datetime;
49
49
 
50
+ namespace symbols {
51
+ extern VALUE day;
52
+ extern VALUE millisecond;
53
+ extern VALUE month;
54
+ extern VALUE nanosecond;
55
+ }
56
+
50
57
  VALUE array_values(VALUE obj);
51
58
  VALUE chunked_array_values(VALUE obj);
52
59
 
data/ext/arrow/values.cpp CHANGED
@@ -77,8 +77,9 @@ namespace red_arrow {
77
77
  VISIT(Time32)
78
78
  VISIT(Time64)
79
79
  VISIT(Timestamp)
80
- // TODO
81
- // VISIT(Interval)
80
+ VISIT(MonthInterval)
81
+ VISIT(DayTimeInterval)
82
+ VISIT(MonthDayNanoInterval)
82
83
  VISIT(List)
83
84
  VISIT(Struct)
84
85
  VISIT(Map)
data/lib/arrow/datum.rb CHANGED
@@ -27,6 +27,8 @@ module Arrow
27
27
  ArrayDatum.new(value)
28
28
  when ChunkedArray
29
29
  ChunkedArrayDatum.new(value)
30
+ when Column
31
+ ChunkedArrayDatum.new(value.data)
30
32
  when Scalar
31
33
  ScalarDatum.new(value)
32
34
  when ::Array
@@ -0,0 +1,29 @@
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 DayTimeIntervalArrayBuilder
20
+ private
21
+ def convert_to_arrow_value(value)
22
+ if value.is_a?(Hash)
23
+ Arrow::DayMillisecond.new(value[:day], value[:millisecond])
24
+ else
25
+ value
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,52 @@
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 Function
20
+ alias_method :execute_raw, :execute
21
+ def execute(args, options=nil, context=nil)
22
+ options = resolve_options(options)
23
+ execute_raw(args, options, context)
24
+ end
25
+ alias_method :call, :execute
26
+
27
+ private
28
+ def resolve_options(options)
29
+ return nil if options.nil?
30
+ return options if options.is_a?(FunctionOptions)
31
+
32
+ arrow_options_class = options_type&.to_class
33
+ if arrow_options_class
34
+ if arrow_options_class.respond_to?(:try_convert)
35
+ arrow_options = arrow_options_class.try_convert(options)
36
+ return arrow_options if arrow_options
37
+ end
38
+ arrow_options = (default_options || arrow_options_class.new)
39
+ else
40
+ arrow_options = default_options
41
+ end
42
+ return arrow_options if arrow_options.nil?
43
+
44
+ options.each do |key, value|
45
+ setter = :"#{key}="
46
+ next unless arrow_options.respond_to?(setter)
47
+ arrow_options.__send__(setter, value)
48
+ end
49
+ arrow_options
50
+ end
51
+ end
52
+ end
data/lib/arrow/loader.rb CHANGED
@@ -30,6 +30,7 @@ module Arrow
30
30
  require_libraries
31
31
  require_extension_library
32
32
  gc_guard
33
+ self.class.start_callback_dispatch_thread
33
34
  end
34
35
 
35
36
  def require_libraries
@@ -58,6 +59,7 @@ module Arrow
58
59
  require "arrow/date64-array"
59
60
  require "arrow/date64-array-builder"
60
61
  require "arrow/datum"
62
+ require "arrow/day-time-interval-array-builder"
61
63
  require "arrow/decimal128"
62
64
  require "arrow/decimal128-array"
63
65
  require "arrow/decimal128-array-builder"
@@ -76,12 +78,14 @@ module Arrow
76
78
  require "arrow/file-system"
77
79
  require "arrow/fixed-size-binary-array"
78
80
  require "arrow/fixed-size-binary-array-builder"
81
+ require "arrow/function"
79
82
  require "arrow/group"
80
83
  require "arrow/list-array-builder"
81
84
  require "arrow/list-data-type"
82
85
  require "arrow/map-array"
83
86
  require "arrow/map-array-builder"
84
87
  require "arrow/map-data-type"
88
+ require "arrow/month-day-nano-interval-array-builder"
85
89
  require "arrow/null-array"
86
90
  require "arrow/null-array-builder"
87
91
  require "arrow/path-extension"
@@ -93,6 +97,7 @@ module Arrow
93
97
  require "arrow/record-batch-reader"
94
98
  require "arrow/record-batch-stream-reader"
95
99
  require "arrow/rolling-window"
100
+ require "arrow/s3-global-options"
96
101
  require "arrow/scalar"
97
102
  require "arrow/schema"
98
103
  require "arrow/slicer"
@@ -212,5 +217,16 @@ module Arrow
212
217
  super
213
218
  end
214
219
  end
220
+
221
+ def prepare_function_info_lock_gvl(function_info, klass)
222
+ super
223
+ case klass.name
224
+ when "Arrow::RecordBatchFileReader"
225
+ case function_info.name
226
+ when "new"
227
+ function_info.lock_gvl_default = false
228
+ end
229
+ end
230
+ end
215
231
  end
216
232
  end
@@ -0,0 +1,29 @@
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 MonthDayNanoIntervalArrayBuilder
20
+ private
21
+ def convert_to_arrow_value(value)
22
+ if value.is_a?(Hash)
23
+ Arrow::MonthDayNano.new(value[:month], value[:day], value[:nanosecond])
24
+ else
25
+ value
26
+ end
27
+ end
28
+ end
29
+ 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 S3GlobalOptions
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
@@ -29,25 +29,26 @@ module Arrow
29
29
  #
30
30
  # @return [Arrow::SortKey] The given sort key itself.
31
31
  #
32
- # @overload resolve(name)
32
+ # @overload resolve(target)
33
33
  #
34
- # Creates a new suitable sort key from column name with
35
- # leading order mark. See {#initialize} for details about
34
+ # Creates a new suitable sort key from column name or dot path
35
+ # with leading order mark. See {#initialize} for details about
36
36
  # order mark.
37
37
  #
38
38
  # @return [Arrow::SortKey] A new suitable sort key.
39
39
  #
40
- # @overload resolve(name, order)
40
+ # @overload resolve(target, order)
41
41
  #
42
- # Creates a new suitable sort key from column name without
43
- # leading order mark and order. See {#initialize} for details.
42
+ # Creates a new suitable sort key from column name or dot path
43
+ # without leading order mark and order. See {#initialize} for
44
+ # details.
44
45
  #
45
46
  # @return [Arrow::SortKey] A new suitable sort key.
46
47
  #
47
48
  # @since 4.0.0
48
- def resolve(name, order=nil)
49
- return name if name.is_a?(self)
50
- new(name, order)
49
+ def resolve(target, order=nil)
50
+ return target if target.is_a?(self)
51
+ new(target, order)
51
52
  end
52
53
 
53
54
  # @api private
@@ -65,47 +66,49 @@ module Arrow
65
66
  private :initialize_raw
66
67
  # Creates a new {Arrow::SortKey}.
67
68
  #
68
- # @overload initialize(name)
69
+ # @overload initialize(target)
69
70
  #
70
- # @param name [Symbol, String] The name of the sort column.
71
+ # @param target [Symbol, String] The name or dot path of the
72
+ # sort column.
71
73
  #
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.
74
+ # If `target` is a String, the first character may be
75
+ # processed as the "leading order mark". If the first
76
+ # character is `"+"` or `"-"`, they are processed as a leading
77
+ # order mark. If the first character is processed as a leading
78
+ # order mark, the first character is removed from sort column
79
+ # target and corresponding order is used. `"+"` uses ascending
80
+ # order and `"-"` uses ascending order.
79
81
  #
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
+ # If `target` is not a String nor `target` doesn't start with the
83
+ # leading order mark, sort column target is `target` as-is and
82
84
  # ascending order is used.
83
85
  #
84
86
  # @example String without the leading order mark
85
87
  # key = Arrow::SortKey.new("count")
86
- # key.name # => "count"
87
- # key.order # => Arrow::SortOrder::ASCENDING
88
+ # key.target # => "count"
89
+ # key.order # => Arrow::SortOrder::ASCENDING
88
90
  #
89
91
  # @example String with the "+" leading order mark
90
92
  # key = Arrow::SortKey.new("+count")
91
- # key.name # => "count"
92
- # key.order # => Arrow::SortOrder::ASCENDING
93
+ # key.target # => "count"
94
+ # key.order # => Arrow::SortOrder::ASCENDING
93
95
  #
94
96
  # @example String with the "-" leading order mark
95
97
  # key = Arrow::SortKey.new("-count")
96
- # key.name # => "count"
97
- # key.order # => Arrow::SortOrder::DESCENDING
98
+ # key.target # => "count"
99
+ # key.order # => Arrow::SortOrder::DESCENDING
98
100
  #
99
101
  # @example Symbol that starts with "-"
100
102
  # key = Arrow::SortKey.new(:"-count")
101
- # key.name # => "-count"
102
- # key.order # => Arrow::SortOrder::ASCENDING
103
+ # key.target # => "-count"
104
+ # key.order # => Arrow::SortOrder::ASCENDING
103
105
  #
104
- # @overload initialize(name, order)
106
+ # @overload initialize(target, order)
105
107
  #
106
- # @param name [Symbol, String] The name of the sort column.
108
+ # @param target [Symbol, String] The name or dot path of the
109
+ # sort column.
107
110
  #
108
- # No leading order mark processing. The given `name` is used
111
+ # No leading order mark processing. The given `target` is used
109
112
  # as-is.
110
113
  #
111
114
  # @param order [Symbol, String, Arrow::SortOrder] How to order
@@ -117,29 +120,29 @@ module Arrow
117
120
  #
118
121
  # @example No leading order mark processing
119
122
  # key = Arrow::SortKey.new("-count", :ascending)
120
- # key.name # => "-count"
121
- # key.order # => Arrow::SortOrder::ASCENDING
123
+ # key.target # => "-count"
124
+ # key.order # => Arrow::SortOrder::ASCENDING
122
125
  #
123
- # @example Order by abbreviated name with Symbol
126
+ # @example Order by abbreviated target with Symbol
124
127
  # key = Arrow::SortKey.new("count", :desc)
125
- # key.name # => "count"
126
- # key.order # => Arrow::SortOrder::DESCENDING
128
+ # key.target # => "count"
129
+ # key.order # => Arrow::SortOrder::DESCENDING
127
130
  #
128
131
  # @example Order by String
129
132
  # key = Arrow::SortKey.new("count", "descending")
130
- # key.name # => "count"
131
- # key.order # => Arrow::SortOrder::DESCENDING
133
+ # key.target # => "count"
134
+ # key.order # => Arrow::SortOrder::DESCENDING
132
135
  #
133
136
  # @example Order by Arrow::SortOrder
134
137
  # key = Arrow::SortKey.new("count", Arrow::SortOrder::DESCENDING)
135
- # key.name # => "count"
136
- # key.order # => Arrow::SortOrder::DESCENDING
138
+ # key.target # => "count"
139
+ # key.order # => Arrow::SortOrder::DESCENDING
137
140
  #
138
141
  # @since 4.0.0
139
- def initialize(name, order=nil)
140
- name, order = normalize_name(name, order)
142
+ def initialize(target, order=nil)
143
+ target, order = normalize_target(target, order)
141
144
  order = normalize_order(order) || :ascending
142
- initialize_raw(name, order)
145
+ initialize_raw(target, order)
143
146
  end
144
147
 
145
148
  # @return [String] The string representation of this sort key. You
@@ -154,28 +157,31 @@ module Arrow
154
157
  # @since 4.0.0
155
158
  def to_s
156
159
  if order == SortOrder::ASCENDING
157
- "+#{name}"
160
+ "+#{target}"
158
161
  else
159
- "-#{name}"
162
+ "-#{target}"
160
163
  end
161
164
  end
162
165
 
166
+ # For backward compatibility
167
+ alias_method :name, :target
168
+
163
169
  private
164
- def normalize_name(name, order)
165
- case name
170
+ def normalize_target(target, order)
171
+ case target
166
172
  when Symbol
167
- return name.to_s, order
173
+ return target.to_s, order
168
174
  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
175
+ return target, order if order
176
+ if target.start_with?("-")
177
+ return target[1..-1], order || :descending
178
+ elsif target.start_with?("+")
179
+ return target[1..-1], order || :ascending
174
180
  else
175
- return name, order
181
+ return target, order
176
182
  end
177
183
  else
178
- return name, order
184
+ return target, order
179
185
  end
180
186
  end
181
187
 
@@ -78,20 +78,20 @@ module Arrow
78
78
  # options.add_sort_key(Arrow::SortKey.new(:price, :descending))
79
79
  # options.sort_keys.collect(&:to_s) # => ["-price"]
80
80
  #
81
- # @overload add_sort_key(name)
81
+ # @overload add_sort_key(target)
82
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.
83
+ # @param target [Symbol, String] The sort key name or dot path
84
+ # to be added. See also {Arrow::SortKey#initialize} for the
85
+ # leading order mark for `String` target.
86
86
  #
87
87
  # @example Add a key to sort by "price" column in descending order
88
88
  # options = Arrow::SortOptions.new
89
89
  # options.add_sort_key("-price")
90
90
  # options.sort_keys.collect(&:to_s) # => ["-price"]
91
91
  #
92
- # @overload add_sort_key(name, order)
92
+ # @overload add_sort_key(target, order)
93
93
  #
94
- # @param name [Symbol, String] The sort key name.
94
+ # @param target [Symbol, String] The sort key name or dot path.
95
95
  #
96
96
  # @param order [Symbol, String, Arrow::SortOrder] The sort
97
97
  # order. See {Arrow::SortKey#initialize} for details.
@@ -102,8 +102,8 @@ module Arrow
102
102
  # options.sort_keys.collect(&:to_s) # => ["-price"]
103
103
  #
104
104
  # @since 4.0.0
105
- def add_sort_key(name, order=nil)
106
- add_sort_key_raw(SortKey.resolve(name, order))
105
+ def add_sort_key(target, order=nil)
106
+ add_sort_key_raw(SortKey.resolve(target, order))
107
107
  end
108
108
  end
109
109
  end