Module: Stargate::Operation::ScannerOperation
- Included in:
- Client
- Defined in:
- lib/stargate/operation/scanner_operation.rb
Instance Method Summary collapse
- #close_scanner(scanner) ⇒ Object
- #get_rows(scanner, limit = nil) ⇒ Object
-
#open_scanner(table_name, options = {}) ⇒ Object
Trying to maintain some API stability for now.
Instance Method Details
#close_scanner(scanner) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/stargate/operation/scanner_operation.rb', line 76 def close_scanner(scanner) begin request = Request::ScannerRequest.new(scanner.table_name) Response::ScannerResponse.new(delete_response(request.close(scanner)), :close_scanner).parse rescue StandardError => e if e.to_s.include?("TableNotFoundException") raise TableNotFoundError, "Table #{table_name} Not Found!" else raise StandardError, e.to_s end end end |
#get_rows(scanner, limit = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/stargate/operation/scanner_operation.rb', line 46 def get_rows(scanner, limit = nil) begin request = Request::ScannerRequest.new(scanner.table_name) request_url = request.get_rows(scanner) # The url to the scanner is the same for each batch rows = [] begin # Loop until we've reached the limit, or the scanner was exhausted (HTTP 204 returned) until (limit && rows.size >= limit) || (response = get_response(request_url)).code == "204" rows.concat Response::ScannerResponse.new(response.body, :get_rows).parse rows.each do |row| row.table_name = scanner.table_name end end rescue Exception => e raise Stargate::ScannerError, "Scanner failed while getting rows. #{e.}" end # Prune the last few rows if the limit was passed. (limit) ? rows.slice(0, limit) : rows rescue StandardError => e if e.to_s.include?("TableNotFoundException") raise TableNotFoundError, "Table #{table_name} Not Found!" else raise StandardError, e.to_s end end end |
#open_scanner(table_name, options = {}) ⇒ Object
Trying to maintain some API stability for now
5 6 7 8 9 |
# File 'lib/stargate/operation/scanner_operation.rb', line 5 def open_scanner(table_name, columns, start_row, stop_row = nil, = nil) warn "[DEPRECATION] This method is deprecated. Use #open_scanner(table_name, options = {}) instead." open_scanner(table_name, {:columns => columns, :start_row => start_row, :stop_row => stop_row, :timestamp => }) end |