Class: Nanoarrow::RbIterator

Inherits:
ArrayViewBaseIterator show all
Defined in:
lib/nanoarrow/iterator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ArrayViewBaseIterator

#set_array

Constructor Details

#initialize(schema, array_view: nil) ⇒ RbIterator

Returns a new instance of RbIterator.



31
32
33
34
35
# File 'lib/nanoarrow/iterator.rb', line 31

def initialize(schema, array_view: nil)
  super(schema, array_view: array_view)

  @children = @schema.children.zip(@array_view.children).map { |s, v| make_child(s, v) }
end

Class Method Details

.get_iterator(obj, schema = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/nanoarrow/iterator.rb', line 20

def self.get_iterator(obj, schema = nil)
  stream = Utils.c_array_stream(obj, schema)
  iterator = new(stream.get_cached_schema)
  Enumerator.new do |yielder|
    while (array = stream.get_next)
      iterator.set_array(array)
      iterator.each(&yielder)
    end
  end
end

Instance Method Details

#each(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoarrow/iterator.rb', line 37

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

  type_id = @schema_view.type_id
  if !ITEMS_ITER_LOOKUP.include?(type_id)
    raise KeyError, "Can't resolve iterator for type #{@schema_view.type.inspect}"
  end

  factory = method(ITEMS_ITER_LOOKUP.fetch(type_id))
  factory.(&block)
end