Class: Impala::Cursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/impala/cursor.rb

Instance Method Summary collapse

Constructor Details

#initialize(handle, service, buffer_length = 1024) ⇒ Cursor

Returns a new instance of Cursor.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/impala/cursor.rb', line 5

def initialize(handle, service, buffer_length=1024)
  @handle = handle
  @service = service
  @metadata = @service.(@handle)

  @buffer_length = buffer_length
  @row_buffer = []

  @done = false
  @closed = false
end

Instance Method Details

#closeObject



41
42
43
44
# File 'lib/impala/cursor.rb', line 41

def close
  @closed = true
  @service.close(@handle)
end

#eachObject



17
18
19
20
21
# File 'lib/impala/cursor.rb', line 17

def each
  while row = fetch_row
    yield row
  end
end

#fetch_allObject



37
38
39
# File 'lib/impala/cursor.rb', line 37

def fetch_all
  self.to_a
end

#fetch_rowObject

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/impala/cursor.rb', line 23

def fetch_row
  raise CursorError.new("Cursor has expired or been closed") if @closed

  if @row_buffer.empty?
    if @done
      return nil
    else
      fetch_more
    end
  end

  @row_buffer.shift
end