red-arrow 4.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +100 -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/group.rb +116 -124
- data/lib/arrow/loader.rb +44 -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/scalar.rb +32 -0
- data/lib/arrow/slicer.rb +44 -143
- 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 +41 -3
- data/lib/arrow/table-saver.rb +29 -3
- data/lib/arrow/table-table-formatter.rb +7 -31
- data/lib/arrow/table.rb +34 -40
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +2 -1
- data/test/helper.rb +1 -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 +176 -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 +190 -53
- 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 +132 -73
data/lib/arrow/group.rb
CHANGED
@@ -16,157 +16,149 @@
|
|
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 Group
|
23
20
|
def initialize(table, keys)
|
24
21
|
@table = table
|
25
22
|
@keys = keys
|
26
23
|
end
|
27
24
|
|
28
|
-
def count
|
29
|
-
|
30
|
-
target_columns = @table.columns.reject do |column|
|
31
|
-
key_names.include?(column.name)
|
32
|
-
end
|
33
|
-
aggregate(target_columns) do |column, indexes|
|
34
|
-
n = 0
|
35
|
-
indexes.each do |index|
|
36
|
-
n += 1 unless column.null?(index)
|
37
|
-
end
|
38
|
-
n
|
39
|
-
end
|
25
|
+
def count(*target_names)
|
26
|
+
aggregate(*build_aggregations("hash_count", target_names))
|
40
27
|
end
|
41
28
|
|
42
|
-
def sum
|
43
|
-
|
44
|
-
target_columns = @table.columns.reject do |column|
|
45
|
-
key_names.include?(column.name) or
|
46
|
-
not column.data_type.is_a?(NumericDataType)
|
47
|
-
end
|
48
|
-
aggregate(target_columns) do |column, indexes|
|
49
|
-
n = 0
|
50
|
-
indexes.each do |index|
|
51
|
-
value = column[index]
|
52
|
-
n += value unless value.nil?
|
53
|
-
end
|
54
|
-
n
|
55
|
-
end
|
29
|
+
def sum(*target_names)
|
30
|
+
aggregate(*build_aggregations("hash_sum", target_names))
|
56
31
|
end
|
57
32
|
|
58
|
-
def
|
59
|
-
|
60
|
-
target_columns = @table.columns.reject do |column|
|
61
|
-
key_names.include?(column.name) or
|
62
|
-
not column.data_type.is_a?(NumericDataType)
|
63
|
-
end
|
64
|
-
aggregate(target_columns) do |column, indexes|
|
65
|
-
average = 0.0
|
66
|
-
n = 0
|
67
|
-
indexes.each do |index|
|
68
|
-
value = column[index]
|
69
|
-
unless value.nil?
|
70
|
-
n += 1
|
71
|
-
average += (value - average) / n
|
72
|
-
end
|
73
|
-
end
|
74
|
-
average
|
75
|
-
end
|
33
|
+
def product(*target_names)
|
34
|
+
aggregate(*build_aggregations("hash_product", target_names))
|
76
35
|
end
|
77
36
|
|
78
|
-
def
|
79
|
-
|
80
|
-
target_columns = @table.columns.reject do |column|
|
81
|
-
key_names.include?(column.name) or
|
82
|
-
not column.data_type.is_a?(NumericDataType)
|
83
|
-
end
|
84
|
-
aggregate(target_columns) do |column, indexes|
|
85
|
-
n = nil
|
86
|
-
indexes.each do |index|
|
87
|
-
value = column[index]
|
88
|
-
next if value.nil?
|
89
|
-
n ||= value
|
90
|
-
n = value if value < n
|
91
|
-
end
|
92
|
-
n
|
93
|
-
end
|
37
|
+
def mean(*target_names)
|
38
|
+
aggregate(*build_aggregations("hash_mean", target_names))
|
94
39
|
end
|
95
40
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
41
|
+
def min(*target_names)
|
42
|
+
aggregate(*build_aggregations("hash_min", target_names))
|
43
|
+
end
|
44
|
+
|
45
|
+
def max(*target_names)
|
46
|
+
aggregate(*build_aggregations("hash_max", target_names))
|
47
|
+
end
|
48
|
+
|
49
|
+
def stddev(*target_names)
|
50
|
+
aggregate(*build_aggregations("hash_stddev", target_names))
|
51
|
+
end
|
52
|
+
|
53
|
+
def variance(*target_names)
|
54
|
+
aggregate(*build_aggregations("hash_variance", target_names))
|
55
|
+
end
|
56
|
+
|
57
|
+
def aggregate(aggregation, *more_aggregations)
|
58
|
+
aggregations = [aggregation] + more_aggregations
|
59
|
+
normalized_aggregations = normalize_aggregations(aggregations)
|
60
|
+
plan = ExecutePlan.new
|
61
|
+
source_node = plan.build_source_node(@table)
|
62
|
+
aggregate_node =
|
63
|
+
plan.build_aggregate_node(source_node,
|
64
|
+
{
|
65
|
+
aggregations: normalized_aggregations,
|
66
|
+
keys: @keys
|
67
|
+
})
|
68
|
+
sink_node_options = SinkNodeOptions.new
|
69
|
+
plan.build_sink_node(aggregate_node, sink_node_options)
|
70
|
+
plan.validate
|
71
|
+
plan.start
|
72
|
+
plan.wait
|
73
|
+
reader = sink_node_options.get_reader(aggregate_node.output_schema)
|
74
|
+
reader.read_all
|
112
75
|
end
|
113
76
|
|
114
77
|
private
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
78
|
+
def build_aggregations(function_name, target_names)
|
79
|
+
if target_names.empty?
|
80
|
+
[function_name]
|
81
|
+
else
|
82
|
+
target_names.collect do |name|
|
83
|
+
"#{function_name}(#{name})"
|
119
84
|
end
|
120
|
-
[key_values, i]
|
121
|
-
end
|
122
|
-
sorted = sort_values.sort_by do |key_values, i|
|
123
|
-
key_values
|
124
85
|
end
|
86
|
+
end
|
125
87
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
88
|
+
def normalize_aggregations(aggregations)
|
89
|
+
normalized_aggregations = []
|
90
|
+
aggregations.each do |aggregation|
|
91
|
+
case aggregation
|
92
|
+
when :all
|
93
|
+
all_functions = [
|
94
|
+
"hash_count",
|
95
|
+
"hash_sum",
|
96
|
+
"hash_product",
|
97
|
+
"hash_mean",
|
98
|
+
"hash_stddev",
|
99
|
+
"hash_variance",
|
100
|
+
# "hash_tdigest",
|
101
|
+
"hash_min",
|
102
|
+
"hash_max",
|
103
|
+
"hash_any",
|
104
|
+
"hash_all",
|
105
|
+
]
|
106
|
+
normalized_aggregations.concat(normalize_aggregations(all_functions))
|
107
|
+
when /\A([a-zA-Z0-9_].+?)\((.+?)\)\z/
|
108
|
+
function = $1
|
109
|
+
input = $2.strip
|
110
|
+
normalized_aggregations << {function: function, input: input}
|
111
|
+
when "count", "hash_count"
|
112
|
+
function = aggregation
|
113
|
+
target_columns.each do |column|
|
114
|
+
normalized_aggregations << {function: function, input: column.name}
|
147
115
|
end
|
116
|
+
when "any", "hash_any", "all", "hash_all"
|
117
|
+
function = aggregation
|
118
|
+
boolean_target_columns.each do |column|
|
119
|
+
normalized_aggregations << {function: function, input: column.name}
|
120
|
+
end
|
121
|
+
when String
|
122
|
+
function = aggregation
|
123
|
+
numeric_target_columns.each do |column|
|
124
|
+
normalized_aggregations << {function: function, input: column.name}
|
125
|
+
end
|
126
|
+
else
|
127
|
+
normalized_aggregations << aggregation
|
148
128
|
end
|
149
129
|
end
|
150
|
-
|
151
|
-
|
130
|
+
normalized_aggregations
|
131
|
+
end
|
132
|
+
|
133
|
+
def target_columns
|
134
|
+
@target_columns ||= find_target_columns
|
135
|
+
end
|
136
|
+
|
137
|
+
def find_target_columns
|
138
|
+
key_names = @keys.collect(&:to_s)
|
139
|
+
@table.columns.find_all do |column|
|
140
|
+
not key_names.include?(column.name)
|
152
141
|
end
|
142
|
+
end
|
153
143
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
fields << key_column.field
|
162
|
-
arrays << key_column_array
|
144
|
+
def boolean_target_columns
|
145
|
+
@boolean_target_columns ||= find_boolean_target_columns
|
146
|
+
end
|
147
|
+
|
148
|
+
def find_boolean_target_columns
|
149
|
+
target_columns.find_all do |column|
|
150
|
+
column.data_type.is_a?(BooleanDataType)
|
163
151
|
end
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
152
|
+
end
|
153
|
+
|
154
|
+
def numeric_target_columns
|
155
|
+
@numeric_target_columns ||= find_numeric_target_columns
|
156
|
+
end
|
157
|
+
|
158
|
+
def find_numeric_target_columns
|
159
|
+
target_columns.find_all do |column|
|
160
|
+
column.data_type.is_a?(NumericDataType)
|
168
161
|
end
|
169
|
-
Table.new(fields, arrays)
|
170
162
|
end
|
171
163
|
end
|
172
164
|
end
|
data/lib/arrow/loader.rb
CHANGED
@@ -29,6 +29,7 @@ module Arrow
|
|
29
29
|
def post_load(repository, namespace)
|
30
30
|
require_libraries
|
31
31
|
require_extension_library
|
32
|
+
gc_guard
|
32
33
|
end
|
33
34
|
|
34
35
|
def require_libraries
|
@@ -37,10 +38,14 @@ module Arrow
|
|
37
38
|
require "arrow/generic-filterable"
|
38
39
|
require "arrow/generic-takeable"
|
39
40
|
require "arrow/record-containable"
|
41
|
+
require "arrow/symbol-values-appendable"
|
40
42
|
|
43
|
+
require "arrow/aggregate-node-options"
|
44
|
+
require "arrow/aggregation"
|
41
45
|
require "arrow/array"
|
42
46
|
require "arrow/array-builder"
|
43
47
|
require "arrow/bigdecimal-extension"
|
48
|
+
require "arrow/binary-dictionary-array-builder"
|
44
49
|
require "arrow/buffer"
|
45
50
|
require "arrow/chunked-array"
|
46
51
|
require "arrow/column"
|
@@ -52,6 +57,7 @@ module Arrow
|
|
52
57
|
require "arrow/date32-array-builder"
|
53
58
|
require "arrow/date64-array"
|
54
59
|
require "arrow/date64-array-builder"
|
60
|
+
require "arrow/datum"
|
55
61
|
require "arrow/decimal128"
|
56
62
|
require "arrow/decimal128-array"
|
57
63
|
require "arrow/decimal128-array-builder"
|
@@ -63,13 +69,19 @@ module Arrow
|
|
63
69
|
require "arrow/dense-union-data-type"
|
64
70
|
require "arrow/dictionary-array"
|
65
71
|
require "arrow/dictionary-data-type"
|
72
|
+
require "arrow/equal-options"
|
73
|
+
require "arrow/expression"
|
66
74
|
require "arrow/field"
|
67
75
|
require "arrow/file-output-stream"
|
76
|
+
require "arrow/file-system"
|
68
77
|
require "arrow/fixed-size-binary-array"
|
69
78
|
require "arrow/fixed-size-binary-array-builder"
|
70
79
|
require "arrow/group"
|
71
80
|
require "arrow/list-array-builder"
|
72
81
|
require "arrow/list-data-type"
|
82
|
+
require "arrow/map-array"
|
83
|
+
require "arrow/map-array-builder"
|
84
|
+
require "arrow/map-data-type"
|
73
85
|
require "arrow/null-array"
|
74
86
|
require "arrow/null-array-builder"
|
75
87
|
require "arrow/path-extension"
|
@@ -78,17 +90,22 @@ module Arrow
|
|
78
90
|
require "arrow/record-batch-builder"
|
79
91
|
require "arrow/record-batch-file-reader"
|
80
92
|
require "arrow/record-batch-iterator"
|
93
|
+
require "arrow/record-batch-reader"
|
81
94
|
require "arrow/record-batch-stream-reader"
|
82
95
|
require "arrow/rolling-window"
|
96
|
+
require "arrow/scalar"
|
83
97
|
require "arrow/schema"
|
84
98
|
require "arrow/slicer"
|
85
99
|
require "arrow/sort-key"
|
86
100
|
require "arrow/sort-options"
|
101
|
+
require "arrow/source-node-options"
|
87
102
|
require "arrow/sparse-union-data-type"
|
103
|
+
require "arrow/string-dictionary-array-builder"
|
88
104
|
require "arrow/struct-array"
|
89
105
|
require "arrow/struct-array-builder"
|
90
106
|
require "arrow/struct-data-type"
|
91
107
|
require "arrow/table"
|
108
|
+
require "arrow/table-concatenate-options"
|
92
109
|
require "arrow/table-formatter"
|
93
110
|
require "arrow/table-list-formatter"
|
94
111
|
require "arrow/table-table-formatter"
|
@@ -112,6 +129,27 @@ module Arrow
|
|
112
129
|
require "arrow.so"
|
113
130
|
end
|
114
131
|
|
132
|
+
def gc_guard
|
133
|
+
require "arrow/constructor-arguments-gc-guardable"
|
134
|
+
|
135
|
+
[
|
136
|
+
@base_module::BinaryScalar,
|
137
|
+
@base_module::Buffer,
|
138
|
+
@base_module::DenseUnionScalar,
|
139
|
+
@base_module::FixedSizeBinaryScalar,
|
140
|
+
@base_module::LargeBinaryScalar,
|
141
|
+
@base_module::LargeListScalar,
|
142
|
+
@base_module::LargeStringScalar,
|
143
|
+
@base_module::ListScalar,
|
144
|
+
@base_module::MapScalar,
|
145
|
+
@base_module::SparseUnionScalar,
|
146
|
+
@base_module::StringScalar,
|
147
|
+
@base_module::StructScalar,
|
148
|
+
].each do |klass|
|
149
|
+
klass.prepend(ConstructorArgumentsGCGuardable)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
115
153
|
def load_object_info(info)
|
116
154
|
super
|
117
155
|
|
@@ -164,6 +202,12 @@ module Arrow
|
|
164
202
|
method_name = "dup"
|
165
203
|
end
|
166
204
|
super(info, klass, method_name)
|
205
|
+
when "Arrow::BooleanScalar"
|
206
|
+
case method_name
|
207
|
+
when "value?"
|
208
|
+
method_name = "value"
|
209
|
+
end
|
210
|
+
super(info, klass, method_name)
|
167
211
|
else
|
168
212
|
super
|
169
213
|
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 MapArrayBuilder
|
20
|
+
class << self
|
21
|
+
def build(data_type, values)
|
22
|
+
builder = new(data_type)
|
23
|
+
builder.build(values)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :append_value_raw, :append_value
|
28
|
+
|
29
|
+
# @overload append_value
|
30
|
+
#
|
31
|
+
# Starts appending a map record. You need to append
|
32
|
+
# values of map by {#key_builder} and {#item_builder}.
|
33
|
+
#
|
34
|
+
# @overload append_value(value)
|
35
|
+
#
|
36
|
+
# Appends a map record including key and item values.
|
37
|
+
#
|
38
|
+
# @param value [nil, #each] The map record.
|
39
|
+
#
|
40
|
+
# If this is `nil`, the map record is null.
|
41
|
+
#
|
42
|
+
# If this is an `Object` that has `#each`, each value is a pair of key and item.
|
43
|
+
#
|
44
|
+
# @since 6.0.0
|
45
|
+
def append_value(*args)
|
46
|
+
n_args = args.size
|
47
|
+
|
48
|
+
case n_args
|
49
|
+
when 0
|
50
|
+
append_value_raw
|
51
|
+
when 1
|
52
|
+
value = args[0]
|
53
|
+
case value
|
54
|
+
when nil
|
55
|
+
append_null
|
56
|
+
else
|
57
|
+
unless value.respond_to?(:each)
|
58
|
+
message = "map value must be nil, Hash or Object that has #each: #{value.inspect}"
|
59
|
+
raise ArgumentError, message
|
60
|
+
end
|
61
|
+
append_value_raw
|
62
|
+
@key_builder ||= key_builder
|
63
|
+
@item_builder ||= item_builder
|
64
|
+
case value
|
65
|
+
when Hash
|
66
|
+
keys = value.keys
|
67
|
+
values = value.values
|
68
|
+
else
|
69
|
+
keys = []
|
70
|
+
values = []
|
71
|
+
value.each do |key, item|
|
72
|
+
keys << key
|
73
|
+
values << item
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@key_builder.append(*keys)
|
77
|
+
@item_builder.append(*values)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
message = "wrong number of arguments (given #{n_args}, expected 0..1)"
|
81
|
+
raise ArgumentError, message
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
alias_method :append_values_raw, :append_values
|
86
|
+
|
87
|
+
def append_values(values, is_valids=nil)
|
88
|
+
value = values[0]
|
89
|
+
case value
|
90
|
+
when Integer
|
91
|
+
append_values_raw(values, is_valids)
|
92
|
+
else
|
93
|
+
if is_valids
|
94
|
+
is_valids.each_with_index do |is_valid, i|
|
95
|
+
if is_valid
|
96
|
+
append_value(values[i])
|
97
|
+
else
|
98
|
+
append_null
|
99
|
+
end
|
100
|
+
end
|
101
|
+
else
|
102
|
+
values.each do |value|
|
103
|
+
append_value(value)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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 MapArray
|
20
|
+
def get_value(i)
|
21
|
+
super.each_with_object({}) do |item, result|
|
22
|
+
result[item["key"]] = item["value"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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 MapDataType
|
20
|
+
alias_method :initialize_raw, :initialize
|
21
|
+
private :initialize_raw
|
22
|
+
|
23
|
+
# Creates a new {Arrow::MapDataType}.
|
24
|
+
#
|
25
|
+
# @overload initialize(key, item)
|
26
|
+
#
|
27
|
+
# @param key [Arrow::DataType, Hash, String, Symbol]
|
28
|
+
# The key data type of the map data type.
|
29
|
+
#
|
30
|
+
# You can specify data type as a description by `Hash`.
|
31
|
+
#
|
32
|
+
# See {Arrow::DataType.resolve} how to specify data type
|
33
|
+
# description.
|
34
|
+
#
|
35
|
+
# @param item [Arrow::DataType, Hash, String, Symbol]
|
36
|
+
# The item data type of the map data type.
|
37
|
+
#
|
38
|
+
# You can specify data type as a description by `Hash`.
|
39
|
+
#
|
40
|
+
# See {Arrow::DataType.resolve} how to specify data type
|
41
|
+
# description.
|
42
|
+
#
|
43
|
+
# @example Create a map data type for `{0: "Hello", 1: "World"}`
|
44
|
+
# key = :int8
|
45
|
+
# item = :string
|
46
|
+
# Arrow::MapDataType.new(key, item)
|
47
|
+
#
|
48
|
+
# @overload initialize(description)
|
49
|
+
#
|
50
|
+
# @param description [Hash] The description of the map data
|
51
|
+
# type. It must have `:key`, `:item` values.
|
52
|
+
#
|
53
|
+
# @option description [Arrow::DataType, Hash, String, Symbol]
|
54
|
+
# :key The key data type of the map data type.
|
55
|
+
#
|
56
|
+
# You can specify data type as a description by `Hash`.
|
57
|
+
#
|
58
|
+
# See {Arrow::DataType.resolve} how to specify data type
|
59
|
+
# description.
|
60
|
+
#
|
61
|
+
# @option description [Arrow::DataType, Hash, String, Symbol]
|
62
|
+
# :item The item data type of the map data type.
|
63
|
+
#
|
64
|
+
# You can specify data type as a description by `Hash`.
|
65
|
+
#
|
66
|
+
# See {Arrow::DataType.resolve} how to specify data type
|
67
|
+
# description.
|
68
|
+
#
|
69
|
+
# @example Create a map data type for `{0: "Hello", 1: "World"}`
|
70
|
+
# Arrow::MapDataType.new(key: :int8, item: :string)
|
71
|
+
def initialize(*args)
|
72
|
+
n_args = args.size
|
73
|
+
case n_args
|
74
|
+
when 1
|
75
|
+
description = args[0]
|
76
|
+
key = description[:key]
|
77
|
+
item = description[:item]
|
78
|
+
when 2
|
79
|
+
key, item = args
|
80
|
+
else
|
81
|
+
message = "wrong number of arguments (given, #{n_args}, expected 1..2)"
|
82
|
+
raise ArgumentError, message
|
83
|
+
end
|
84
|
+
key = DataType.resolve(key)
|
85
|
+
item = DataType.resolve(item)
|
86
|
+
initialize_raw(key, item)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/arrow/path-extension.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
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 RecordBatchReader
|
20
|
+
class << self
|
21
|
+
# @api private
|
22
|
+
def try_convert(value)
|
23
|
+
case value
|
24
|
+
when ::Array
|
25
|
+
return nil if value.empty?
|
26
|
+
if value.all? {|v| v.is_a?(RecordBatch)}
|
27
|
+
new(value)
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
when RecordBatch
|
32
|
+
new([value])
|
33
|
+
when Table
|
34
|
+
TableBatchReader.new(value)
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|