red-arrow 6.0.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/ext/arrow/arrow.cpp +12 -0
- data/ext/arrow/converters.hpp +46 -10
- data/ext/arrow/extconf.rb +1 -1
- data/ext/arrow/raw-records.cpp +3 -2
- data/ext/arrow/red-arrow.hpp +7 -0
- data/ext/arrow/values.cpp +3 -2
- data/lib/arrow/datum.rb +2 -0
- data/lib/arrow/day-time-interval-array-builder.rb +29 -0
- data/lib/arrow/function.rb +52 -0
- data/lib/arrow/loader.rb +16 -0
- data/lib/arrow/month-day-nano-interval-array-builder.rb +29 -0
- data/lib/arrow/s3-global-options.rb +38 -0
- data/lib/arrow/sort-key.rb +61 -55
- data/lib/arrow/sort-options.rb +8 -8
- data/lib/arrow/table-loader.rb +99 -62
- data/lib/arrow/table-saver.rb +7 -2
- data/lib/arrow/table.rb +78 -0
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +1 -10
- data/test/helper.rb +2 -0
- data/test/raw-records/test-basic-arrays.rb +30 -0
- data/test/raw-records/test-dense-union-array.rb +27 -0
- data/test/raw-records/test-list-array.rb +39 -0
- data/test/raw-records/test-map-array.rb +37 -0
- data/test/raw-records/test-sparse-union-array.rb +27 -0
- data/test/raw-records/test-struct-array.rb +30 -0
- data/test/test-function.rb +48 -14
- data/test/test-table.rb +204 -6
- data/test/values/test-basic-arrays.rb +30 -0
- data/test/values/test-dense-union-array.rb +27 -0
- data/test/values/test-dictionary-array.rb +295 -0
- data/test/values/test-list-array.rb +39 -0
- data/test/values/test-map-array.rb +33 -0
- data/test/values/test-sparse-union-array.rb +27 -0
- data/test/values/test-struct-array.rb +30 -0
- metadata +88 -194
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f43d3875f2e48876cd47533124a9fcf9559e263e63e3954c65fedd36b4e59744
|
4
|
+
data.tar.gz: 2548f661536d3288f4ad8bb25d6587a78ee51d810a85a7d533ccdaf595439a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caeffbc164f14db7b056263f1ecd449afe2feec3ccbf7b883c147d415199c9ddc6c20398b00c34884248c103fbb7c55aa225719d8b8e75ac7f49337ee89d557e
|
7
|
+
data.tar.gz: ae5a793e06b63bd80e3499f794193f47f72ff7510a558d2d0e61314068d5bd3a1986e5083bda749b00b73a4615901beb320521eeb360576b93fcb9a1e9d9510a
|
data/Gemfile
CHANGED
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
|
}
|
data/ext/arrow/converters.hpp
CHANGED
@@ -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
|
-
|
302
|
-
|
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
|
-
|
408
|
-
|
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
|
-
|
510
|
-
|
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
|
-
|
613
|
-
|
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
|
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
|
data/ext/arrow/raw-records.cpp
CHANGED
data/ext/arrow/red-arrow.hpp
CHANGED
@@ -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
data/lib/arrow/datum.rb
CHANGED
@@ -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
|
data/lib/arrow/sort-key.rb
CHANGED
@@ -29,25 +29,26 @@ module Arrow
|
|
29
29
|
#
|
30
30
|
# @return [Arrow::SortKey] The given sort key itself.
|
31
31
|
#
|
32
|
-
# @overload resolve(
|
32
|
+
# @overload resolve(target)
|
33
33
|
#
|
34
|
-
# Creates a new suitable sort key from column name
|
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(
|
40
|
+
# @overload resolve(target, order)
|
41
41
|
#
|
42
|
-
# Creates a new suitable sort key from column name
|
43
|
-
# leading order mark and order. See {#initialize} for
|
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(
|
49
|
-
return
|
50
|
-
new(
|
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(
|
69
|
+
# @overload initialize(target)
|
69
70
|
#
|
70
|
-
# @param
|
71
|
+
# @param target [Symbol, String] The name or dot path of the
|
72
|
+
# sort column.
|
71
73
|
#
|
72
|
-
# If `
|
73
|
-
# as the "leading order mark". If the first
|
74
|
-
# or `"-"`, they are processed as a leading
|
75
|
-
# first character is processed as a leading
|
76
|
-
# first character is removed from sort column
|
77
|
-
# corresponding order is used. `"+"` uses ascending
|
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 `
|
81
|
-
# leading order mark, sort column
|
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.
|
87
|
-
# key.order
|
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.
|
92
|
-
# key.order
|
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.
|
97
|
-
# key.order
|
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.
|
102
|
-
# key.order
|
103
|
+
# key.target # => "-count"
|
104
|
+
# key.order # => Arrow::SortOrder::ASCENDING
|
103
105
|
#
|
104
|
-
# @overload initialize(
|
106
|
+
# @overload initialize(target, order)
|
105
107
|
#
|
106
|
-
# @param
|
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 `
|
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.
|
121
|
-
# key.order
|
123
|
+
# key.target # => "-count"
|
124
|
+
# key.order # => Arrow::SortOrder::ASCENDING
|
122
125
|
#
|
123
|
-
# @example Order by abbreviated
|
126
|
+
# @example Order by abbreviated target with Symbol
|
124
127
|
# key = Arrow::SortKey.new("count", :desc)
|
125
|
-
# key.
|
126
|
-
# key.order
|
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.
|
131
|
-
# key.order
|
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.
|
136
|
-
# key.order
|
138
|
+
# key.target # => "count"
|
139
|
+
# key.order # => Arrow::SortOrder::DESCENDING
|
137
140
|
#
|
138
141
|
# @since 4.0.0
|
139
|
-
def initialize(
|
140
|
-
|
142
|
+
def initialize(target, order=nil)
|
143
|
+
target, order = normalize_target(target, order)
|
141
144
|
order = normalize_order(order) || :ascending
|
142
|
-
initialize_raw(
|
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
|
-
"+#{
|
160
|
+
"+#{target}"
|
158
161
|
else
|
159
|
-
"-#{
|
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
|
165
|
-
case
|
170
|
+
def normalize_target(target, order)
|
171
|
+
case target
|
166
172
|
when Symbol
|
167
|
-
return
|
173
|
+
return target.to_s, order
|
168
174
|
when String
|
169
|
-
return
|
170
|
-
if
|
171
|
-
return
|
172
|
-
elsif
|
173
|
-
return
|
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
|
181
|
+
return target, order
|
176
182
|
end
|
177
183
|
else
|
178
|
-
return
|
184
|
+
return target, order
|
179
185
|
end
|
180
186
|
end
|
181
187
|
|
data/lib/arrow/sort-options.rb
CHANGED
@@ -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(
|
81
|
+
# @overload add_sort_key(target)
|
82
82
|
#
|
83
|
-
# @param
|
84
|
-
# added. See also {Arrow::SortKey#initialize} for the
|
85
|
-
# order mark for String
|
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(
|
92
|
+
# @overload add_sort_key(target, order)
|
93
93
|
#
|
94
|
-
# @param
|
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(
|
106
|
-
add_sort_key_raw(SortKey.resolve(
|
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
|