]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/lib/arrow/array.rb
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
21 include GenericFilterable
22 include GenericTakeable
26 _builder_class
= builder_class
27 return super if _builder_class
.nil?
28 return super unless _builder_class
.buildable
?(args
)
29 _builder_class
.build(*args
)
33 builder_class_name
= "#{name}Builder"
34 return nil unless const_defined
?(builder_class_name
)
35 const_get(builder_class_name
)
40 # The index of the value to be gotten.
42 # You can specify negative index like for `::Array#[]`.
44 # @return [Object, nil]
47 # `nil` for NULL value or out of range `i`.
50 return nil if i
< 0 or i
>= length
58 # @param other [Arrow::Array] The array to be compared.
59 # @param options [Arrow::EqualOptions, Hash] (nil)
60 # The options to custom how to compare.
63 # `true` if both of them have the same data, `false` otherwise.
66 def equal_array
?(other
, options
=nil)
67 equal_options(other
, options
)
71 return to_enum(__method__
) unless block_given
?
79 return to_enum(__method__
) unless block_given
?
81 (length
- 1).downto(0) do |i
|
90 alias_method
:value_data_type_raw, :value_data_type
92 @value_data_type ||= value_data_type_raw
99 alias_method
:is_in_raw, :is_in
103 if self.class.builder_class
.buildable
?([values
])
104 values
= self.class.new(values
)
106 values
= self.class.new(value_data_type
, values
)
110 is_in_chunked_array(values
)
117 alias_method
:concatenate_raw, :concatenate
118 # Concatenates the given other arrays to the array.
120 # @param other_arrays [::Array, Arrow::Array] The arrays to be
123 # Each other array is processed by {#resolve} before they're
126 # @example Raw Ruby Array
127 # array = Arrow::Int32Array.new([1])
128 # array.concatenate([2, 3], [4]) # => Arrow::Int32Array.new([1, 2, 3, 4])
130 # @example Arrow::Array
131 # array = Arrow::Int32Array.new([1])
132 # array.concatenate(Arrow::Int32Array.new([2, 3]),
133 # Arrow::Int8Array.new([4])) # => Arrow::Int32Array.new([1, 2, 3, 4])
136 def concatenate(*other_arrays
)
137 other_arrays
= other_arrays
.collect
do |other_array
|
140 concatenate_raw(other_arrays
)
143 # Concatenates the given other array to the array.
145 # If you have multiple arrays to be concatenated, you should use
146 # {#concatenate} to concatenate multiple arrays at once.
148 # @param other_array [::Array, Arrow::Array] The array to be concatenated.
150 # `@other_array` is processed by {#resolve} before it's
153 # @example Raw Ruby Array
154 # Arrow::Int32Array.new([1]) + [2, 3] # => Arrow::Int32Array.new([1, 2, 3])
156 # @example Arrow::Array
157 # Arrow::Int32Array.new([1]) +
158 # Arrow::Int32Array.new([2, 3]) # => Arrow::Int32Array.new([1, 2, 3])
162 concatenate(other_array
)
165 # Ensures returning the same data type array from the given array.
167 # @return [Arrow::Array]
169 # @overload resolve(other_raw_array)
171 # @param other_raw_array [::Array] A raw Ruby Array. A new Arrow::Array
172 # is built by `self.class.new`.
174 # @example Raw Ruby Array
175 # int32_array = Arrow::Int32Array.new([1])
176 # other_array = int32_array.resolve([2, 3, 4])
177 # other_array # => Arrow::Int32Array.new([2, 3, 4])
179 # @overload resolve(other_array)
181 # @param other_array [Arrow::Array] Another Arrow::Array.
183 # If the given other array is an same data type array of
184 # `self`, the given other array is returned as-is.
186 # If the given other array isn't an same data type array of
187 # `self`, the given other array is casted.
189 # @example Same data type
190 # int32_array = Arrow::Int32Array.new([1])
191 # other_int32_array = Arrow::Int32Array.new([2, 3, 4])
192 # other_array = int32_array.resolve(other_int32_array)
193 # other_array.object_id == other_int32_array.object_id
195 # @example Other data type
196 # int32_array = Arrow::Int32Array.new([1])
197 # other_int8_array = Arrow::Int8Array.new([2, 3, 4])
198 # other_array = int32_array.resolve(other_int32_array)
199 # other_array #=> Arrow::Int32Array.new([2, 3, 4])
202 def resolve(other_array
)
203 if other_array
.is_a
?(::Array)
204 builder_class
= self.class.builder_class
205 if builder_class
.nil?
207 "[array][resolve] can't build #{value_data_type} array " +
208 "from raw Ruby Array"
209 raise ArgumentError
, message
211 if builder_class
.buildable
?([other_array
])
212 other_array
= builder_class
.build(other_array
)
213 elsif builder_class
.buildable
?([value_data_type
, other_array
])
214 other_array
= builder_class
.build(value_data_type
, other_array
)
217 "[array][resolve] need to implement " +
218 "a feature that building #{value_data_type} array " +
219 "from raw Ruby Array"
220 raise NotImpelemented
, message
223 elsif other_array
.respond_to
?(:value_data_type)
224 return other_array
if value_data_type
== other_array
.value_data_type
225 other_array
.cast(value_data_type
)
228 "[array][resolve] can't build #{value_data_type} array: " +
229 "#{other_array.inspect}"
230 raise ArgumentError
, message