lib/impala/cursor.rb in impala-0.4.1 vs lib/impala/cursor.rb in impala-0.4.2

- old
+ new

@@ -31,12 +31,10 @@ # Returns the next available row as a hash, or nil if there are none left. # @return [Hash, nil] the next available row, or nil if there are none # left # @see #fetch_all def fetch_row - raise CursorError.new("Cursor has expired or been closed") unless @open - if @row_buffer.empty? if @done return nil else fetch_more @@ -83,21 +81,25 @@ def fetch_more fetch_batch until @done || @row_buffer.count >= BUFFER_SIZE end def fetch_batch - return if @done + raise CursorError.new("Cursor has expired or been closed") unless @open begin res = @service.fetch(@handle, false, BUFFER_SIZE) rescue Protocol::Beeswax::BeeswaxException => e - @closed = true + @open = false raise CursorError.new("Cursor has expired or been closed") end rows = res.data.map { |raw| parse_row(raw) } @row_buffer.concat(rows) - @done = true unless res.has_more + + unless res.has_more + @done = true + close + end end def parse_row(raw) row = {} fields = raw.split(metadata.delim)