Class: Arrow::Array
Constant Summary
collapse
- VectorAppender =
org.apache.arrow.vector.util.VectorAppender
- VectorEqualsVisitor =
org.apache.arrow.vector.compare.VectorEqualsVisitor
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#refer_input, #share_input
included, #take_generic
#filter_generic, included
#index, #max, #min, #uniq
Constructor Details
#initialize(vector) ⇒ Array
Returns a new instance of Array.
27
28
29
|
# File 'lib/arrow/jruby/array.rb', line 27
def initialize(vector)
@vector = vector
end
|
Instance Attribute Details
#vector ⇒ Object
Returns the value of attribute vector.
25
26
27
|
# File 'lib/arrow/jruby/array.rb', line 25
def vector
@vector
end
|
Class Method Details
.builder_class ⇒ Object
35
36
37
38
39
40
|
# File 'lib/arrow/array.rb', line 35
def builder_class
local_name = name.split("::").last
builder_class_name = "#{local_name}Builder"
return nil unless Arrow.const_defined?(builder_class_name)
Arrow.const_get(builder_class_name)
end
|
.new(*args) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/arrow/array.rb', line 28
def new(*args)
_builder_class = builder_class
return super if _builder_class.nil?
return super unless _builder_class.buildable?(args)
_builder_class.build(*args)
end
|
.try_convert(value) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/arrow/array.rb', line 43
def try_convert(value)
case value
when ::Array
begin
new(value)
rescue ArgumentError
nil
end
else
if value.respond_to?(:to_arrow_array)
begin
value.to_arrow_array
rescue RangeError
nil
end
else
nil
end
end
end
|
Instance Method Details
#+(other_array) ⇒ Object
Concatenates the given other array to the array.
If you have multiple arrays to be concatenated, you should use #concatenate to concatenate multiple arrays at once.
197
198
199
|
# File 'lib/arrow/array.rb', line 197
def +(other_array)
concatenate(other_array)
end
|
#==(other_array) ⇒ Object
31
32
33
34
|
# File 'lib/arrow/jruby/array.rb', line 31
def ==(other_array)
return false unless other_array.is_a?(self.class)
VectorEqualsVisitor.vector_equals(@vector, other_array.vector)
end
|
#[](i) ⇒ Object?
Returns The ‘i`-th value.
‘nil` for NULL value or out of range `i`.
74
75
76
77
78
79
80
81
82
|
# File 'lib/arrow/array.rb', line 74
def [](i)
i += length if i < 0
return nil if i < 0 or i >= length
if null?(i)
nil
else
get_value(i)
end
end
|
#cast(other_value_data_type) ⇒ Object
70
71
72
|
# File 'lib/arrow/jruby/array.rb', line 70
def cast(other_value_data_type)
other_value_data_type.build_array(to_a)
end
|
#close ⇒ Object
54
55
56
|
# File 'lib/arrow/jruby/array.rb', line 54
def close
@vector.close
end
|
#concatenate(other_arrays) ⇒ Object
Concatenates the given other arrays to the array.
172
173
174
175
176
177
|
# File 'lib/arrow/array.rb', line 172
def concatenate(*other_arrays)
other_arrays = other_arrays.collect do |other_array|
resolve(other_array)
end
concatenate_raw(other_arrays)
end
|
#concatenate_raw ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
153
|
# File 'lib/arrow/array.rb', line 153
alias_method :concatenate_raw, :concatenate
|
#each ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/arrow/array.rb', line 98
def each
return to_enum(__method__) unless block_given?
length.times do |i|
yield(self[i])
end
end
|
#equal_array?(other, options = nil) ⇒ Boolean
Returns ‘true` if both of them have the same data, `false` otherwise.
92
93
94
|
# File 'lib/arrow/array.rb', line 92
def equal_array?(other, options=nil)
equal_options(other, options)
end
|
#get_value(i) ⇒ Object
40
41
42
|
# File 'lib/arrow/jruby/array.rb', line 40
def get_value(i)
@vector.get_object(i)
end
|
#inspect ⇒ Object
48
49
50
51
52
|
# File 'lib/arrow/jruby/array.rb', line 48
def inspect
super.sub(/>\z/) do
" #{to_s}>"
end
end
|
#is_in(values) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/arrow/array.rb', line 136
def is_in(values)
case values
when ::Array
if self.class.builder_class.buildable?([values])
values = self.class.new(values)
else
values = self.class.new(value_data_type, values)
end
is_in_raw(values)
when ChunkedArray
is_in_chunked_array(values)
else
is_in_raw(values)
end
end
|
#is_in_raw ⇒ Object
135
|
# File 'lib/arrow/array.rb', line 135
alias_method :is_in_raw, :is_in
|
#length ⇒ Object
58
59
60
|
# File 'lib/arrow/jruby/array.rb', line 58
def length
@vector.value_count
end
|
#null?(i) ⇒ Boolean
36
37
38
|
# File 'lib/arrow/jruby/array.rb', line 36
def null?(i)
@vector.null?(i)
end
|
#resolve(other_raw_array) ⇒ Arrow::Array
#resolve(other_array) ⇒ Arrow::Array
Ensures returning the same data type array from the given array.
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/arrow/array.rb', line 238
def resolve(other_array)
if other_array.is_a?(::Array)
builder_class = self.class.builder_class
if builder_class.nil?
message =
"[array][resolve] can't build #{value_data_type} array " +
"from raw Ruby Array"
raise ArgumentError, message
end
if builder_class.buildable?([other_array])
other_array = builder_class.build(other_array)
elsif builder_class.buildable?([value_data_type, other_array])
other_array = builder_class.build(value_data_type, other_array)
else
message =
"[array][resolve] need to implement " +
"a feature that building #{value_data_type} array " +
"from raw Ruby Array"
raise NotImplementedError, message
end
other_array
elsif other_array.respond_to?(:value_data_type)
return other_array if value_data_type == other_array.value_data_type
other_array.cast(value_data_type)
else
message =
"[array][resolve] can't build #{value_data_type} array: " +
"#{other_array.inspect}"
raise ArgumentError, message
end
end
|
#reverse_each ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/arrow/array.rb', line 106
def reverse_each
return to_enum(__method__) unless block_given?
(length - 1).downto(0) do |i|
yield(self[i])
end
end
|
#size ⇒ Object
96
|
# File 'lib/arrow/array.rb', line 96
alias_method :size, :length
|
#to_a ⇒ Object
131
132
133
|
# File 'lib/arrow/array.rb', line 131
def to_a
values
end
|
#to_arrow ⇒ Object
114
115
116
|
# File 'lib/arrow/array.rb', line 114
def to_arrow
self
end
|
#to_arrow_array ⇒ Object
118
119
120
|
# File 'lib/arrow/array.rb', line 118
def to_arrow_array
self
end
|
#to_arrow_chunked_array ⇒ Object
122
123
124
|
# File 'lib/arrow/array.rb', line 122
def to_arrow_chunked_array
ChunkedArray.new([self])
end
|
#to_s ⇒ Object
44
45
46
|
# File 'lib/arrow/jruby/array.rb', line 44
def to_s
@vector.to_s
end
|
#value_data_type ⇒ Object
127
128
129
|
# File 'lib/arrow/array.rb', line 127
def value_data_type
@value_data_type ||= value_data_type_raw
end
|
#value_data_type_raw ⇒ Object
126
|
# File 'lib/arrow/array.rb', line 126
alias_method :value_data_type_raw, :value_data_type
|
#values ⇒ Object
66
67
68
|
# File 'lib/arrow/jruby/array.rb', line 66
def values
each.to_a
end
|