red-arrow 4.0.1 → 7.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.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/README.md +23 -0
- data/ext/arrow/arrow.cpp +3 -0
- data/ext/arrow/converters.cpp +5 -0
- data/ext/arrow/converters.hpp +126 -0
- data/ext/arrow/extconf.rb +13 -0
- data/ext/arrow/memory-view.cpp +311 -0
- data/ext/arrow/memory-view.hpp +26 -0
- data/ext/arrow/raw-records.cpp +1 -0
- data/ext/arrow/values.cpp +1 -0
- data/lib/arrow/aggregate-node-options.rb +35 -0
- data/lib/arrow/aggregation.rb +46 -0
- data/lib/arrow/array-builder.rb +5 -0
- data/lib/arrow/array.rb +12 -0
- data/lib/arrow/binary-dictionary-array-builder.rb +27 -0
- data/lib/arrow/buffer.rb +10 -6
- data/lib/arrow/column-containable.rb +100 -1
- data/lib/arrow/constructor-arguments-gc-guardable.rb +25 -0
- data/lib/arrow/datum.rb +102 -0
- data/lib/arrow/equal-options.rb +38 -0
- data/lib/arrow/expression.rb +48 -0
- data/lib/arrow/file-system.rb +34 -0
- data/lib/arrow/function.rb +52 -0
- data/lib/arrow/group.rb +116 -124
- data/lib/arrow/loader.rb +58 -0
- data/lib/arrow/map-array-builder.rb +109 -0
- data/lib/arrow/map-array.rb +26 -0
- data/lib/arrow/map-data-type.rb +89 -0
- data/lib/arrow/path-extension.rb +1 -1
- data/lib/arrow/record-batch-reader.rb +41 -0
- data/lib/arrow/record-batch.rb +0 -2
- data/lib/arrow/s3-global-options.rb +38 -0
- data/lib/arrow/scalar.rb +32 -0
- data/lib/arrow/slicer.rb +44 -143
- data/lib/arrow/sort-key.rb +61 -55
- data/lib/arrow/sort-options.rb +8 -8
- data/lib/arrow/source-node-options.rb +32 -0
- data/lib/arrow/string-dictionary-array-builder.rb +27 -0
- data/lib/arrow/symbol-values-appendable.rb +34 -0
- data/lib/arrow/table-concatenate-options.rb +36 -0
- data/lib/arrow/table-formatter.rb +141 -17
- data/lib/arrow/table-list-formatter.rb +5 -3
- data/lib/arrow/table-loader.rb +119 -44
- data/lib/arrow/table-saver.rb +36 -5
- data/lib/arrow/table-table-formatter.rb +7 -31
- data/lib/arrow/table.rb +112 -40
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +1 -9
- data/test/helper.rb +3 -0
- data/test/raw-records/test-dense-union-array.rb +14 -0
- data/test/raw-records/test-list-array.rb +19 -0
- data/test/raw-records/test-map-array.rb +441 -0
- data/test/raw-records/test-sparse-union-array.rb +14 -0
- data/test/raw-records/test-struct-array.rb +15 -0
- data/test/test-array-builder.rb +7 -0
- data/test/test-array.rb +34 -0
- data/test/test-binary-dictionary-array-builder.rb +103 -0
- data/test/test-boolean-scalar.rb +26 -0
- data/test/test-csv-loader.rb +8 -8
- data/test/test-expression.rb +40 -0
- data/test/test-float-scalar.rb +46 -0
- data/test/test-function.rb +210 -0
- data/test/test-group.rb +75 -51
- data/test/test-map-array-builder.rb +110 -0
- data/test/test-map-array.rb +33 -0
- data/test/test-map-data-type.rb +36 -0
- data/test/test-memory-view.rb +434 -0
- data/test/test-record-batch-reader.rb +46 -0
- data/test/test-record-batch.rb +42 -0
- data/test/test-slicer.rb +166 -167
- data/test/test-string-dictionary-array-builder.rb +103 -0
- data/test/test-table.rb +376 -56
- data/test/values/test-dense-union-array.rb +14 -0
- data/test/values/test-list-array.rb +17 -0
- data/test/values/test-map-array.rb +433 -0
- data/test/values/test-sparse-union-array.rb +14 -0
- data/test/values/test-struct-array.rb +15 -0
- metadata +117 -168
@@ -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/scalar.rb
ADDED
@@ -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
|
data/lib/arrow/slicer.rb
CHANGED
@@ -16,9 +16,6 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
module Arrow
|
19
|
-
# Experimental
|
20
|
-
#
|
21
|
-
# TODO: Almost codes should be implemented in Apache Arrow C++.
|
22
19
|
class Slicer
|
23
20
|
def initialize(table)
|
24
21
|
@table = table
|
@@ -43,6 +40,21 @@ module Arrow
|
|
43
40
|
super
|
44
41
|
end
|
45
42
|
|
43
|
+
module Helper
|
44
|
+
class << self
|
45
|
+
def ensure_boolean(column)
|
46
|
+
case column.data_type
|
47
|
+
when Arrow::BooleanDataType
|
48
|
+
column.data
|
49
|
+
else
|
50
|
+
options = CastOptions.new
|
51
|
+
options.to_data_type = Arrow::BooleanDataType.new
|
52
|
+
Function.find("cast").execute([column.data], options).value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
class Condition
|
47
59
|
def evaluate
|
48
60
|
message = "Slicer::Condition must define \#evaluate: #{inspect}"
|
@@ -69,43 +81,28 @@ module Arrow
|
|
69
81
|
end
|
70
82
|
|
71
83
|
def evaluate
|
72
|
-
|
73
|
-
values2 = @condition2.evaluate.each
|
74
|
-
raw_array = []
|
75
|
-
begin
|
76
|
-
loop do
|
77
|
-
value1 = values1.next
|
78
|
-
value2 = values2.next
|
79
|
-
if value1.nil? or value2.nil?
|
80
|
-
raw_array << nil
|
81
|
-
else
|
82
|
-
raw_array << evaluate_value(value1, value2)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
rescue StopIteration
|
86
|
-
end
|
87
|
-
BooleanArray.new(raw_array)
|
84
|
+
function.execute([@condition1.evaluate, @condition2.evaluate]).value
|
88
85
|
end
|
89
86
|
end
|
90
87
|
|
91
88
|
class AndCondition < LogicalCondition
|
92
89
|
private
|
93
|
-
def
|
94
|
-
|
90
|
+
def function
|
91
|
+
Function.find("and")
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
98
95
|
class OrCondition < LogicalCondition
|
99
96
|
private
|
100
|
-
def
|
101
|
-
|
97
|
+
def function
|
98
|
+
Function.find("or")
|
102
99
|
end
|
103
100
|
end
|
104
101
|
|
105
102
|
class XorCondition < LogicalCondition
|
106
103
|
private
|
107
|
-
def
|
108
|
-
|
104
|
+
def function
|
105
|
+
Function.find("xor")
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
@@ -115,21 +112,7 @@ module Arrow
|
|
115
112
|
end
|
116
113
|
|
117
114
|
def evaluate
|
118
|
-
|
119
|
-
|
120
|
-
case @column.data_type
|
121
|
-
when BooleanDataType
|
122
|
-
data
|
123
|
-
else
|
124
|
-
if data.n_chunks == 1
|
125
|
-
data.get_chunk(0).cast(BooleanDataType.new, nil)
|
126
|
-
else
|
127
|
-
arrays = data.each_chunk.collect do |chunk|
|
128
|
-
chunk.cast(BooleanDataType.new, nil)
|
129
|
-
end
|
130
|
-
ChunkedArray.new(arrays)
|
131
|
-
end
|
132
|
-
end
|
115
|
+
Helper.ensure_boolean(@column)
|
133
116
|
end
|
134
117
|
|
135
118
|
def !@
|
@@ -187,23 +170,8 @@ module Arrow
|
|
187
170
|
end
|
188
171
|
|
189
172
|
def evaluate
|
190
|
-
data = @column
|
191
|
-
|
192
|
-
data.each_chunk do |chunk|
|
193
|
-
if chunk.is_a?(BooleanArray)
|
194
|
-
boolean_array = chunk
|
195
|
-
else
|
196
|
-
boolean_array = chunk.cast(BooleanDataType.new, nil)
|
197
|
-
end
|
198
|
-
boolean_array.each do |value|
|
199
|
-
if value.nil?
|
200
|
-
raw_array << value
|
201
|
-
else
|
202
|
-
raw_array << !value
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
BooleanArray.new(raw_array)
|
173
|
+
data = Helper.ensure_boolean(@column)
|
174
|
+
Function.find("invert").execute([data]).value
|
207
175
|
end
|
208
176
|
|
209
177
|
def !@
|
@@ -222,19 +190,10 @@ module Arrow
|
|
222
190
|
end
|
223
191
|
|
224
192
|
def evaluate
|
225
|
-
|
226
|
-
|
227
|
-
raw_array = @column.collect(&:nil?)
|
228
|
-
BooleanArray.new(raw_array)
|
193
|
+
if @value.nil?
|
194
|
+
Function.find("is_null").execute([@column.data]).value
|
229
195
|
else
|
230
|
-
|
231
|
-
if value.nil?
|
232
|
-
nil
|
233
|
-
else
|
234
|
-
@value == value
|
235
|
-
end
|
236
|
-
end
|
237
|
-
BooleanArray.new(raw_array)
|
196
|
+
Function.find("equal").execute([@column.data, @value]).value
|
238
197
|
end
|
239
198
|
end
|
240
199
|
end
|
@@ -250,25 +209,10 @@ module Arrow
|
|
250
209
|
end
|
251
210
|
|
252
211
|
def evaluate
|
253
|
-
|
254
|
-
|
255
|
-
if @column.n_nulls.zero?
|
256
|
-
raw_array = [true] * @column.n_rows
|
257
|
-
else
|
258
|
-
raw_array = @column.n_rows.times.collect do |i|
|
259
|
-
@column.valid?(i)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
BooleanArray.new(raw_array)
|
212
|
+
if @value.nil?
|
213
|
+
Function.find("is_valid").execute([@column.data]).value
|
263
214
|
else
|
264
|
-
|
265
|
-
if value.nil?
|
266
|
-
nil
|
267
|
-
else
|
268
|
-
@value != value
|
269
|
-
end
|
270
|
-
end
|
271
|
-
BooleanArray.new(raw_array)
|
215
|
+
Function.find("not_equal").execute([@column.data, @value]).value
|
272
216
|
end
|
273
217
|
end
|
274
218
|
end
|
@@ -284,14 +228,7 @@ module Arrow
|
|
284
228
|
end
|
285
229
|
|
286
230
|
def evaluate
|
287
|
-
|
288
|
-
if value.nil?
|
289
|
-
nil
|
290
|
-
else
|
291
|
-
@value > value
|
292
|
-
end
|
293
|
-
end
|
294
|
-
BooleanArray.new(raw_array)
|
231
|
+
Function.find("less").execute([@column.data, @value]).value
|
295
232
|
end
|
296
233
|
end
|
297
234
|
|
@@ -306,14 +243,7 @@ module Arrow
|
|
306
243
|
end
|
307
244
|
|
308
245
|
def evaluate
|
309
|
-
|
310
|
-
if value.nil?
|
311
|
-
nil
|
312
|
-
else
|
313
|
-
@value >= value
|
314
|
-
end
|
315
|
-
end
|
316
|
-
BooleanArray.new(raw_array)
|
246
|
+
Function.find("less_equal").execute([@column.data, @value]).value
|
317
247
|
end
|
318
248
|
end
|
319
249
|
|
@@ -328,14 +258,7 @@ module Arrow
|
|
328
258
|
end
|
329
259
|
|
330
260
|
def evaluate
|
331
|
-
|
332
|
-
if value.nil?
|
333
|
-
nil
|
334
|
-
else
|
335
|
-
@value < value
|
336
|
-
end
|
337
|
-
end
|
338
|
-
BooleanArray.new(raw_array)
|
261
|
+
Function.find("greater").execute([@column.data, @value]).value
|
339
262
|
end
|
340
263
|
end
|
341
264
|
|
@@ -350,14 +273,7 @@ module Arrow
|
|
350
273
|
end
|
351
274
|
|
352
275
|
def evaluate
|
353
|
-
|
354
|
-
if value.nil?
|
355
|
-
nil
|
356
|
-
else
|
357
|
-
@value <= value
|
358
|
-
end
|
359
|
-
end
|
360
|
-
BooleanArray.new(raw_array)
|
276
|
+
Function.find("greater_equal").execute([@column.data, @value]).value
|
361
277
|
end
|
362
278
|
end
|
363
279
|
|
@@ -372,18 +288,10 @@ module Arrow
|
|
372
288
|
end
|
373
289
|
|
374
290
|
def evaluate
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
raw_array = @column.collect do |value|
|
380
|
-
if value.nil?
|
381
|
-
nil
|
382
|
-
else
|
383
|
-
values_index.key?(value)
|
384
|
-
end
|
385
|
-
end
|
386
|
-
BooleanArray.new(raw_array)
|
291
|
+
values = @values
|
292
|
+
values = Array.new(values) unless values.is_a?(Array)
|
293
|
+
options = SetLookupOptions.new(values)
|
294
|
+
Function.find("is_in").execute([@column.data], options).value
|
387
295
|
end
|
388
296
|
end
|
389
297
|
|
@@ -398,18 +306,11 @@ module Arrow
|
|
398
306
|
end
|
399
307
|
|
400
308
|
def evaluate
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
if value.nil?
|
407
|
-
nil
|
408
|
-
else
|
409
|
-
not values_index.key?(value)
|
410
|
-
end
|
411
|
-
end
|
412
|
-
BooleanArray.new(raw_array)
|
309
|
+
values = @values
|
310
|
+
values = Array.new(values) unless values.is_a?(Array)
|
311
|
+
options = SetLookupOptions.new(values)
|
312
|
+
booleans = Function.find("is_in").execute([@column.data], options).value
|
313
|
+
Function.find("invert").execute([booleans]).value
|
413
314
|
end
|
414
315
|
end
|
415
316
|
|
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
|
@@ -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 SourceNodeOptions
|
20
|
+
class << self
|
21
|
+
# @api private
|
22
|
+
def try_convert(value)
|
23
|
+
case value
|
24
|
+
when RecordBatchReader, RecordBatch, Table
|
25
|
+
new(value)
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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 StringDictionaryArrayBuilder
|
20
|
+
include SymbolValuesAppendable
|
21
|
+
|
22
|
+
private
|
23
|
+
def create_values_array_builder
|
24
|
+
StringArrayBuilder.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
module SymbolValuesAppendable
|
20
|
+
def append_values(values, is_valids=nil)
|
21
|
+
builder = create_values_array_builder
|
22
|
+
values = values.collect do |value|
|
23
|
+
case value
|
24
|
+
when Symbol
|
25
|
+
value.to_s
|
26
|
+
else
|
27
|
+
value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
builder.append_values(values, is_valids)
|
31
|
+
append_array(builder.finish)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|