sishen-hbase-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/hbase-ruby.gemspec +1 -1
- data/lib/hbase/client.rb +2 -1
- data/lib/hbase/model.rb +1 -2
- data/lib/hbase/model/column_descriptor.rb +3 -7
- data/lib/hbase/operation/scanner_operation.rb +42 -0
- data/lib/hbase/request/meta_request.rb +1 -1
- data/lib/hbase/request/scanner_request.rb +32 -0
- data/lib/hbase/response.rb +1 -0
- metadata +1 -1
data/Rakefile
CHANGED
data/hbase-ruby.gemspec
CHANGED
data/lib/hbase/client.rb
CHANGED
data/lib/hbase/model.rb
CHANGED
@@ -2,8 +2,6 @@ module HBase
|
|
2
2
|
module Model
|
3
3
|
class Record
|
4
4
|
def initialize (params)
|
5
|
-
return if params.nil?
|
6
|
-
|
7
5
|
params.each do |key, value|
|
8
6
|
name = key.to_s
|
9
7
|
instance_variable_set("@#{name}", value) if respond_to?(name)
|
@@ -18,3 +16,4 @@ require 'hbase/model/column_descriptor'
|
|
18
16
|
require 'hbase/model/region_descriptor'
|
19
17
|
require 'hbase/model/row'
|
20
18
|
require 'hbase/model/table_descriptor'
|
19
|
+
require 'hbase/model/scanner'
|
@@ -4,15 +4,11 @@ module HBase
|
|
4
4
|
NONE = "NONE"
|
5
5
|
RECORD = "RECORD"
|
6
6
|
BLOCK = "BLOCK"
|
7
|
+
|
8
|
+
CTYPES = [NONE, RECORD, BLOCK]
|
7
9
|
|
8
10
|
def to_compression_type(type_string)
|
9
|
-
|
10
|
-
when "NONE" then NONE
|
11
|
-
when "RECORD" then RECORD
|
12
|
-
when "BLOCK" then BLOCK
|
13
|
-
else
|
14
|
-
NONE
|
15
|
-
end
|
11
|
+
CTYPES.include?(type_string) ? type_string : NONE
|
16
12
|
end
|
17
13
|
|
18
14
|
module_function :to_compression_type
|
@@ -1,6 +1,48 @@
|
|
1
1
|
module HBase
|
2
2
|
module Operation
|
3
3
|
module ScannerOperation
|
4
|
+
def open_scanner(table_name, columns, start_row = nil, end_row = nil, timestamp = nil)
|
5
|
+
begin
|
6
|
+
request = Request::ScannerRequest.new(table_name)
|
7
|
+
scanner_id = Response::ScannerResponse.new(post(request.open(columns, start_row, end_row, timestamp))).get_scanner_id
|
8
|
+
rescue Net::ProtocolError => e
|
9
|
+
if e.to_s.include?("TableNotFoundException")
|
10
|
+
raise TableNotFoundError, "Table #{table_name} Not Found!"
|
11
|
+
else
|
12
|
+
raise StandardError, e.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_rows(scanner, limit = 1)
|
18
|
+
begin
|
19
|
+
request = Request::ScannerRequest.new(scanner.table_name)
|
20
|
+
rows = Response::ScannerResponse.new(post(request.get_rows(scanner.scanner_id, limit))).parse
|
21
|
+
rows.each do |row|
|
22
|
+
row.table_name = scanner.table_name
|
23
|
+
end
|
24
|
+
rows
|
25
|
+
rescue StandardError => e
|
26
|
+
if e.to_s.include?("TableNotFoundException")
|
27
|
+
raise TableNotFoundError, "Table #{table_name} Not Found!"
|
28
|
+
else
|
29
|
+
raise StandardError, e.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def close_scanner(scanner)
|
35
|
+
begin
|
36
|
+
request = Request::ScannerRequest.new(scanner.table_name)
|
37
|
+
Response::ScannerResponse.new(delete(request.close(scanner.scanner_id)))
|
38
|
+
rescue StandardError => e
|
39
|
+
if e.to_s.include?("TableNotFoundException")
|
40
|
+
raise TableNotFoundError, "Table #{table_name} Not Found!"
|
41
|
+
else
|
42
|
+
raise StandardError, e.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
4
46
|
end
|
5
47
|
end
|
6
48
|
end
|
@@ -1,6 +1,38 @@
|
|
1
1
|
module HBase
|
2
2
|
module Request
|
3
3
|
class ScannerRequest < BasicRequest
|
4
|
+
attr_reader :table_name
|
5
|
+
|
6
|
+
def initialize(table_name)
|
7
|
+
@table_name = CGI.escape(table_name)
|
8
|
+
path = "/#{@table_name}/scanner"
|
9
|
+
super(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def open(columns, start_row = nil, end_row = nil, timestamp = nil)
|
13
|
+
search = []
|
14
|
+
if columns.is_a? String
|
15
|
+
search << "column=#{columns}"
|
16
|
+
elsif columns.is_a? Array
|
17
|
+
search << columns.collect { |col| "column=#{col}" }.join("&")
|
18
|
+
else
|
19
|
+
raise StandardError, "Only string or array type allowed for columns attr."
|
20
|
+
end
|
21
|
+
|
22
|
+
search << "start_row=#{CGI.escape(start_row)}" if start_row
|
23
|
+
search << "end_row=#{CGI.escape(end_row)}" if end_row
|
24
|
+
search << "timestamp=#{CGI.escape(timestamp)}" if timestamp
|
25
|
+
|
26
|
+
@path << "?" << search.join('&')
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_rows(scanner_id, limit = 1)
|
30
|
+
@path << "/#{scanner_id}?limit=#{limit}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def close(scanner_id)
|
34
|
+
@path << "/#{scanner_id}"
|
35
|
+
end
|
4
36
|
end
|
5
37
|
end
|
6
38
|
end
|
data/lib/hbase/response.rb
CHANGED