hbase-ruby 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/VERSION +1 -1
- data/lib/hbase/client.rb +18 -17
- data/lib/hbase/operation/meta_operation.rb +11 -1
- data/lib/hbase/operation/row_operation.rb +9 -5
- data/lib/hbase/request/meta_request.rb +8 -0
- data/lib/hbase/response/basic_response.rb +9 -0
- data/lib/hbase/response/row_response.rb +33 -17
- data/lib/hbase/response/scanner_response.rb +1 -1
- data/spec/hbase/operation/row_operation_spec.rb +24 -3
- metadata +2 -2
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/lib/hbase/client.rb
CHANGED
@@ -24,35 +24,36 @@ module HBase
|
|
24
24
|
@connection.read_timeout = opts[:timeout] if opts[:timeout]
|
25
25
|
end
|
26
26
|
|
27
|
-
def get(path)
|
28
|
-
safe_request { @connection.get(@url.path + path, {"Accept" => "application/json"}) }
|
27
|
+
def get(path, options = {})
|
28
|
+
safe_request { @connection.get(@url.path + path, {"Accept" => "application/json"}.merge(options)) }
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
safe_response { @connection.get(@url.path + path, {"Accept" => "application/json"}) }
|
31
|
+
def get_response(path, options = {})
|
32
|
+
safe_response { @connection.get(@url.path + path, {"Accept" => "application/json"}.merge(options)) }
|
34
33
|
end
|
35
34
|
|
36
|
-
def post(path, data = nil)
|
37
|
-
safe_request { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml'}) }
|
35
|
+
def post(path, data = nil, options = {})
|
36
|
+
safe_request { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml'}.merge(options)) }
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
safe_response { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml'}) }
|
39
|
+
def post_response(path, data = nil, options = {})
|
40
|
+
safe_response { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml'}.merge(options)) }
|
43
41
|
end
|
44
42
|
|
45
|
-
def delete(path)
|
46
|
-
safe_request { @connection.delete(@url.path + path) }
|
43
|
+
def delete(path, options = {})
|
44
|
+
safe_request { @connection.delete(@url.path + path, options) }
|
47
45
|
end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
safe_response { @connection.delete(@url.path + path) }
|
47
|
+
def delete_response(path, options = {})
|
48
|
+
safe_response { @connection.delete(@url.path + path, options) }
|
52
49
|
end
|
53
50
|
|
54
|
-
def put(path, data = nil)
|
55
|
-
safe_request { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml'}) }
|
51
|
+
def put(path, data = nil, options = {})
|
52
|
+
safe_request { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml'}.merge(options)) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def put_response(path, data = nil, options = {})
|
56
|
+
safe_response { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml'}.merge(options)) }
|
56
57
|
end
|
57
58
|
|
58
59
|
private
|
@@ -3,7 +3,17 @@ module HBase
|
|
3
3
|
module MetaOperation
|
4
4
|
def list_tables
|
5
5
|
request = Request::MetaRequest.new
|
6
|
-
|
6
|
+
Response::MetaResponse.new(get(request.list_tables), :list_tables).parse
|
7
|
+
end
|
8
|
+
|
9
|
+
def version
|
10
|
+
request = Request::MetaRequest.new
|
11
|
+
get(request.version, {"Accept" => "text/plain"}).strip
|
12
|
+
end
|
13
|
+
|
14
|
+
def cluster_version
|
15
|
+
request = Request::MetaRequest.new
|
16
|
+
get(request.cluster_version, {"Accept" => "text/plain"}).strip
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -16,15 +16,17 @@ module HBase
|
|
16
16
|
def show_row(table_name, name, timestamp = nil, columns = nil, options = { })
|
17
17
|
begin
|
18
18
|
options[:version] ||= 1
|
19
|
+
|
19
20
|
request = Request::RowRequest.new(table_name, name, timestamp)
|
20
|
-
row = Response::RowResponse.new(get(request.show(columns, options))).parse.first
|
21
|
+
row = Response::RowResponse.new(get(request.show(columns, options)), :show_row).parse.first
|
21
22
|
row.table_name = table_name
|
22
23
|
row.timestamp = timestamp
|
23
24
|
row
|
24
25
|
rescue Net::ProtocolError => e
|
26
|
+
# TODO: Use better handling instead of this.
|
25
27
|
if e.to_s.include?("Table")
|
26
28
|
raise TableNotFoundError, "Table '#{table_name}' Not Found"
|
27
|
-
elsif e.to_s.include?("
|
29
|
+
elsif e.to_s.include?("404")
|
28
30
|
raise RowNotFoundError, "Row '#{name}' Not Found"
|
29
31
|
end
|
30
32
|
end
|
@@ -49,19 +51,21 @@ module HBase
|
|
49
51
|
data.each do |d|
|
50
52
|
escape_name = d[:name].gsub(/[&<>'"]/) { |match| Converter[match] }
|
51
53
|
xml_data << "<Cell "
|
52
|
-
xml_data << "timestamp='#{timestamp}'" if timestamp
|
54
|
+
xml_data << "timestamp='#{timestamp}' " if timestamp
|
53
55
|
xml_data << "column='#{[escape_name].pack('m') rescue ''}'>"
|
54
56
|
xml_data << "#{[d[:value]].pack("m") rescue ''}"
|
55
57
|
xml_data << "</Cell>"
|
56
58
|
end
|
57
59
|
xml_data << "</Row></CellSet>"
|
58
60
|
|
59
|
-
|
61
|
+
Response::RowResponse.new(post_response(request.create(data.map{|col| col[:name]}), xml_data), :create_row).parse
|
60
62
|
rescue Net::ProtocolError => e
|
61
63
|
if e.to_s.include?("Table")
|
62
64
|
raise TableNotFoundError, "Table '#{table_name}' Not Found"
|
63
65
|
elsif e.to_s.include?("Row")
|
64
66
|
raise RowNotFoundError, "Row '#{name}' Not Found"
|
67
|
+
else
|
68
|
+
raise StandardError, "Error encountered while trying to create row: #{e.message}"
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
@@ -69,7 +73,7 @@ module HBase
|
|
69
73
|
def delete_row(table_name, name, timestamp = nil, columns = nil)
|
70
74
|
begin
|
71
75
|
request = Request::RowRequest.new(table_name, name, timestamp)
|
72
|
-
Response::RowResponse.new(
|
76
|
+
Response::RowResponse.new(delete_response(request.delete(columns)), :delete_row).parse
|
73
77
|
rescue Net::ProtocolError => e
|
74
78
|
if e.to_s.include?("Table")
|
75
79
|
raise TableNotFoundError, "Table '#{table_name}' Not Found"
|
@@ -1,30 +1,46 @@
|
|
1
1
|
module HBase
|
2
2
|
module Response
|
3
3
|
class RowResponse < BasicResponse
|
4
|
+
attr_reader :method
|
5
|
+
|
6
|
+
def initialize(raw_data, method)
|
7
|
+
@method = method
|
8
|
+
super(raw_data)
|
9
|
+
end
|
10
|
+
|
4
11
|
def parse_content(raw_data)
|
5
|
-
|
6
|
-
|
12
|
+
case @method
|
13
|
+
when :show_row
|
14
|
+
doc = JSON.parse(raw_data)
|
15
|
+
rows = doc["Row"]
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
17
|
+
model_rows = []
|
18
|
+
rows.each do |row|
|
19
|
+
rname = row["key"].strip.unpack("m").first
|
20
|
+
count = row["Cell"].size
|
21
|
+
columns = []
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
row["Cell"].each do |col|
|
24
|
+
name = col["column"].strip.unpack('m').first
|
25
|
+
value = col["$"].strip.unpack('m').first rescue nil
|
26
|
+
timestamp = col["timestamp"].to_i
|
18
27
|
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
columns << HBase::Model::Column.new( :name => name,
|
29
|
+
:value => value,
|
30
|
+
:timestamp => timestamp)
|
31
|
+
end
|
32
|
+
|
33
|
+
model_rows << HBase::Model::Row.new(:name => rname, :total_count => count, :columns => columns)
|
22
34
|
end
|
23
35
|
|
24
|
-
model_rows
|
36
|
+
model_rows
|
37
|
+
when :create_row
|
38
|
+
verify_success(raw_data)
|
39
|
+
when :delete_row
|
40
|
+
verify_success(raw_data)
|
41
|
+
else
|
42
|
+
puts "method '#{@method}' not supported yet"
|
25
43
|
end
|
26
|
-
|
27
|
-
model_rows
|
28
44
|
end
|
29
45
|
end
|
30
46
|
end
|
@@ -24,7 +24,7 @@ module HBase
|
|
24
24
|
when :get_rows
|
25
25
|
# Dispatch it to RowResponse, since that method is made
|
26
26
|
# to deal with rows already.
|
27
|
-
RowResponse.new(raw_data).parse
|
27
|
+
RowResponse.new(raw_data, :show_row).parse
|
28
28
|
when :close_scanner
|
29
29
|
case raw_data
|
30
30
|
when Net::HTTPOK
|
@@ -8,12 +8,29 @@ describe HBase::Operation::RowOperation do
|
|
8
8
|
table = @client.create_table("test-hbase-ruby", "col1")
|
9
9
|
end
|
10
10
|
|
11
|
-
it "should create
|
11
|
+
it "should create a row called 'row1'" do
|
12
12
|
lambda {
|
13
|
-
|
13
|
+
@client.create_row("test-hbase-ruby", "row1", nil, { :name => "col1:", :value => "row1-col1" }).should be_true
|
14
14
|
}.should_not raise_error
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should create a row named 'row2' with timestamp value" do
|
18
|
+
timestamp = (Time.now - (5*60)).to_i
|
19
|
+
lambda {
|
20
|
+
@client.create_row("test-hbase-ruby", "row2", timestamp, { :name => "col1:cell1", :value => "row2-col1-cell1" }).should be_true
|
21
|
+
}.should_not raise_error
|
22
|
+
|
23
|
+
row = @client.show_row("test-hbase-ruby", "row2")
|
24
|
+
row.should be_a_kind_of(HBase::Model::Row)
|
25
|
+
row.name.should == "row2"
|
26
|
+
|
27
|
+
columns = row.columns
|
28
|
+
columns.size.should == 1
|
29
|
+
columns.first.name.should == "col1:cell1"
|
30
|
+
columns.first.value.should == "row2-col1-cell1"
|
31
|
+
columns.first.timestamp.should == timestamp
|
32
|
+
end
|
33
|
+
|
17
34
|
it "should show the rows 'row1'" do
|
18
35
|
row = @client.show_row("test-hbase-ruby", "row1")
|
19
36
|
row.should.is_a? HBase::Model::Row
|
@@ -29,8 +46,12 @@ describe HBase::Operation::RowOperation do
|
|
29
46
|
|
30
47
|
it "should delete the rows 'row1'" do
|
31
48
|
lambda {
|
32
|
-
row1 = @client.delete_row('test-hbase-ruby', 'row1')
|
49
|
+
row1 = @client.delete_row('test-hbase-ruby', 'row1').should be_true
|
33
50
|
}.should_not raise_error
|
51
|
+
|
52
|
+
lambda {
|
53
|
+
row_verify = @client.show_row('test-hbase-ruby', 'row1')
|
54
|
+
}.should raise_error
|
34
55
|
end
|
35
56
|
|
36
57
|
after :all do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hbase-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ye Dingding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-11-
|
13
|
+
date: 2009-11-08 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|