Class: Impala::Cursor
- Inherits:
-
Object
- Object
- Impala::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/impala/cursor.rb
Overview
Cursors are used to iterate over result sets without loading them all into memory at once. This can be useful if you’re dealing with lots of rows. It implements Enumerable, so you can use each/select/map/etc.
Constant Summary collapse
- BUFFER_SIZE =
1024
Instance Method Summary collapse
-
#close ⇒ Object
Close the cursor on the remote server.
- #each ⇒ Object
-
#fetch_all ⇒ Array<Hash>
Returns all the remaining rows in the result set.
-
#fetch_row ⇒ Hash?
Returns the next available row as a hash, or nil if there are none left.
-
#has_more? ⇒ Boolean
Returns true if there are any more rows to fetch.
-
#initialize(handle, service) ⇒ Cursor
constructor
A new instance of Cursor.
- #inspect ⇒ Object
-
#open? ⇒ Boolean
Returns true if the cursor is still open.
- #runtime_profile ⇒ Object
Constructor Details
#initialize(handle, service) ⇒ Cursor
Returns a new instance of Cursor.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/impala/cursor.rb', line 9 def initialize(handle, service) @handle = handle @service = service @row_buffer = [] @done = false @open = true fetch_more end |
Instance Method Details
#close ⇒ Object
Close the cursor on the remote server. Once a cursor is closed, you can no longer fetch any rows from it.
56 57 58 59 |
# File 'lib/impala/cursor.rb', line 56 def close @open = false @service.close(@handle) end |
#each ⇒ Object
25 26 27 28 29 |
# File 'lib/impala/cursor.rb', line 25 def each while row = fetch_row yield row end end |
#fetch_all ⇒ Array<Hash>
Returns all the remaining rows in the result set.
50 51 52 |
# File 'lib/impala/cursor.rb', line 50 def fetch_all self.to_a end |
#fetch_row ⇒ Hash?
Returns the next available row as a hash, or nil if there are none left.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/impala/cursor.rb', line 35 def fetch_row if @row_buffer.empty? if @done return nil else fetch_more end end @row_buffer.shift end |
#has_more? ⇒ Boolean
Returns true if there are any more rows to fetch.
67 68 69 |
# File 'lib/impala/cursor.rb', line 67 def has_more? !@done || !@row_buffer.empty? end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/impala/cursor.rb', line 21 def inspect "#<#{self.class}#{open? ? '' : ' (CLOSED)'}>" end |
#open? ⇒ Boolean
Returns true if the cursor is still open.
62 63 64 |
# File 'lib/impala/cursor.rb', line 62 def open? @open end |
#runtime_profile ⇒ Object
71 72 73 |
# File 'lib/impala/cursor.rb', line 71 def runtime_profile @service.GetRuntimeProfile(@handle) end |