Class: Arrow::ChunkedArray

Inherits:
Object
  • Object
show all
Includes:
ArrayComputable, GenericFilterable, GenericTakeable, InputReferable, Enumerable
Defined in:
lib/arrow/chunked-array.rb

Instance Method Summary collapse

Methods included from InputReferable

#refer_input, #share_input

Methods included from GenericTakeable

included, #take_generic

Methods included from GenericFilterable

#filter_generic, included

Methods included from ArrayComputable

#index, #max, #min, #uniq

Instance Method Details

#[](i) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/arrow/chunked-array.rb', line 86

def [](i)
  i += length if i < 0
  chunks.each do |array|
    return array[i] if i < array.length
    i -= array.length
  end
  nil
end

#cast(target_data_type, options: nil) ⇒ Object



139
140
141
142
143
144
# File 'lib/arrow/chunked-array.rb', line 139

def cast(target_data_type, options: nil)
  casted_chunks = chunks.collect do |chunk|
    chunk.cast(target_data_type, options)
  end
  self.class.new(casted_chunks)
end

#chunksObject



57
58
59
60
61
62
63
# File 'lib/arrow/chunked-array.rb', line 57

def chunks
  @chunks ||= chunks_raw.tap do |_chunks|
    _chunks.each do |chunk|
      share_input(chunk)
    end
  end
end

#chunks_rawObject



56
# File 'lib/arrow/chunked-array.rb', line 56

alias_method :chunks_raw, :chunks

#count(options: nil) ⇒ Object



127
128
129
# File 'lib/arrow/chunked-array.rb', line 127

def count(options: nil)
  compute("count", options: options).value
end

#each(&block) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/arrow/chunked-array.rb', line 95

def each(&block)
  return to_enum(__method__) unless block_given?

  chunks.each do |array|
    array.each(&block)
  end
end

#each_chunk(&block) ⇒ Object



111
112
113
# File 'lib/arrow/chunked-array.rb', line 111

def each_chunk(&block)
  chunks.each(&block)
end

#freezeObject



27
28
29
30
31
32
33
# File 'lib/arrow/chunked-array.rb', line 27

def freeze
  unless frozen?
    # Ensure caching
    chunks
  end
  super
end

#get_chunk(i) ⇒ Object



66
67
68
# File 'lib/arrow/chunked-array.rb', line 66

def get_chunk(i)
  chunks[i]
end

#get_chunk_rawObject



65
# File 'lib/arrow/chunked-array.rb', line 65

alias_method :get_chunk_raw, :get_chunk

#null?(i) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/arrow/chunked-array.rb', line 70

def null?(i)
  chunks.each do |array|
    return array.null?(i) if i < array.length
    i -= array.length
  end
  nil
end

#packObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/arrow/chunked-array.rb', line 115

def pack
  first_chunk = chunks.first
  data_type = first_chunk.value_data_type
  case data_type
  when TimestampDataType
    builder = TimestampArrayBuilder.new(data_type)
    builder.build(to_a)
  else
    first_chunk.class.new(to_a)
  end
end

#reverse_each(&block) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/arrow/chunked-array.rb', line 103

def reverse_each(&block)
  return to_enum(__method__) unless block_given?

  chunks.reverse_each do |array|
    array.reverse_each(&block)
  end
end

#sum(options: nil) ⇒ Object



131
132
133
# File 'lib/arrow/chunked-array.rb', line 131

def sum(options: nil)
  compute("sum", options: options).value
end

#to_arrowObject



35
36
37
# File 'lib/arrow/chunked-array.rb', line 35

def to_arrow
  self
end

#to_arrow_arrayObject



39
40
41
42
43
44
45
# File 'lib/arrow/chunked-array.rb', line 39

def to_arrow_array
  if n_chunks.zero?
    value_data_type.build_array([])
  else
    combine
  end
end

#to_arrow_chunked_arrayObject



47
48
49
# File 'lib/arrow/chunked-array.rb', line 47

def to_arrow_chunked_array
  self
end

#uniqueObject



135
136
137
# File 'lib/arrow/chunked-array.rb', line 135

def unique
  compute("unique")
end

#valid?(i) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/arrow/chunked-array.rb', line 78

def valid?(i)
  chunks.each do |array|
    return array.valid?(i) if i < array.length
    i -= array.length
  end
  nil
end