hbase-stargate 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ module Stargate
11
11
  def open_scanner(table_name, options = {})
12
12
  raise ArgumentError, "options should be given as a Hash" unless options.instance_of? Hash
13
13
  columns = options.delete(:columns)
14
- batch = options.delete(:batch) || "10"
14
+ batch = options.delete(:batch) || "1000"
15
15
  start_time = options.delete(:start_time)
16
16
  end_time = options.delete(:end_time)
17
17
 
@@ -48,27 +48,24 @@ module Stargate
48
48
  end
49
49
  end
50
50
 
51
- def get_rows(scanner, limit = nil)
51
+ def each_row(scanner, &block)
52
52
  begin
53
53
  request = Request::ScannerRequest.new(scanner.table_name)
54
54
  request_url = request.get_rows(scanner) # The url to the scanner is the same for each batch
55
55
 
56
- rows = []
57
56
  begin
58
57
  # Loop until we've reached the limit, or the scanner was exhausted (HTTP 204 returned)
59
- until (limit && rows.size >= limit) || (response = get_response(request_url)).status == 204
60
- rows.concat Response::ScannerResponse.new(response.body, :get_rows).parse
58
+ until (response = get_response(request_url)).status == 204
59
+ rows = Response::ScannerResponse.new(response.body, :get_rows).parse
61
60
 
62
61
  rows.each do |row|
63
62
  row.table_name = scanner.table_name
63
+ block.call(row)
64
64
  end
65
65
  end
66
- rescue Exception => e
67
- raise Stargate::ScannerError, "Scanner failed while getting rows. #{e.message}"
66
+ rescue => e
67
+ raise Stargate::ScannerError, "Scanner iteration failed with the following error:\n#{e.message}"
68
68
  end
69
-
70
- # Prune the last few rows if the limit was passed.
71
- (limit) ? rows.slice(0, limit) : rows
72
69
  rescue => e
73
70
  if e.to_s.include?("TableNotFoundException")
74
71
  raise TableNotFoundError, "Table #{table_name} Not Found!"
@@ -78,6 +75,15 @@ module Stargate
78
75
  end
79
76
  end
80
77
 
78
+ def get_rows(scanner, limit = nil)
79
+ rows = []
80
+ each_row(scanner) do |row|
81
+ break if !limit.nil? && rows.size >= limit
82
+ rows << row
83
+ end
84
+ return rows
85
+ end
86
+
81
87
  def close_scanner(scanner)
82
88
  begin
83
89
  request = Request::ScannerRequest.new(scanner.table_name)
@@ -15,7 +15,7 @@ module Stargate
15
15
  when 201
16
16
  Stargate::Model::Scanner.new(:scanner_url => raw_data.headers["Location"])
17
17
  when 404
18
- raise TableNotFoundError, "Table #{table_name} Not Found!"
18
+ raise TableNotFoundError, "Table Not Found: #{raw_data.to_s}"
19
19
  else
20
20
  raise StandardError, "Unable to open scanner. Received the following message: #{raw_data.status_line}"
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module Stargate
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hbase-stargate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.6.0
5
+ version: 1.6.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Hopper
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-04 00:00:00 Z
13
+ date: 2011-11-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: yajl-ruby
@@ -153,3 +153,4 @@ test_files:
153
153
  - spec/hbase-stargate/response/scanner_response_spec.rb
154
154
  - spec/hbase-stargate/response/table_response_spec.rb
155
155
  - spec/spec_helper.rb
156
+ has_rdoc: