sishen-hbase-ruby 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +30 -0
- data/README.txt +41 -0
- data/Rakefile +11 -0
- data/hbase-ruby.gemspec +32 -0
- data/lib/hbase.rb +44 -0
- data/lib/hbase/client.rb +49 -0
- data/lib/hbase/exception.rb +1 -0
- data/lib/hbase/model.rb +20 -0
- data/lib/hbase/model/column.rb +8 -0
- data/lib/hbase/model/column_descriptor.rb +32 -0
- data/lib/hbase/model/region_descriptor.rb +9 -0
- data/lib/hbase/model/row.rb +10 -0
- data/lib/hbase/model/table_descriptor.rb +8 -0
- data/lib/hbase/operation/meta_operation.rb +10 -0
- data/lib/hbase/operation/row_operation.rb +35 -0
- data/lib/hbase/operation/scanner_operation.rb +6 -0
- data/lib/hbase/operation/table_operation.rb +53 -0
- data/lib/hbase/request.rb +7 -0
- data/lib/hbase/request/basic_request.rb +11 -0
- data/lib/hbase/request/meta_request.rb +17 -0
- data/lib/hbase/request/row_request.rb +42 -0
- data/lib/hbase/request/scanner_request.rb +6 -0
- data/lib/hbase/request/table_request.rb +37 -0
- data/lib/hbase/response.rb +6 -0
- data/lib/hbase/response/basic_response.rb +17 -0
- data/lib/hbase/response/meta_response.rb +33 -0
- data/lib/hbase/response/row_response.rb +18 -0
- data/lib/hbase/response/table_response.rb +28 -0
- metadata +93 -0
data/History.txt
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Dingding Ye
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
History.txt
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
hbase-ruby.gemspec
|
7
|
+
lib/hbase.rb
|
8
|
+
lib/hbase/client.rb
|
9
|
+
lib/hbase/exception.rb
|
10
|
+
lib/hbase/model.rb
|
11
|
+
lib/hbase/model/column.rb
|
12
|
+
lib/hbase/model/column_descriptor.rb
|
13
|
+
lib/hbase/model/region_descriptor.rb
|
14
|
+
lib/hbase/model/row.rb
|
15
|
+
lib/hbase/model/table_descriptor.rb
|
16
|
+
lib/hbase/operation/meta_operation.rb
|
17
|
+
lib/hbase/operation/row_operation.rb
|
18
|
+
lib/hbase/operation/scanner_operation.rb
|
19
|
+
lib/hbase/operation/table_operation.rb
|
20
|
+
lib/hbase/request.rb
|
21
|
+
lib/hbase/request/basic_request.rb
|
22
|
+
lib/hbase/request/meta_request.rb
|
23
|
+
lib/hbase/request/row_request.rb
|
24
|
+
lib/hbase/request/scanner_request.rb
|
25
|
+
lib/hbase/request/table_request.rb
|
26
|
+
lib/hbase/response.rb
|
27
|
+
lib/hbase/response/basic_response.rb
|
28
|
+
lib/hbase/response/meta_response.rb
|
29
|
+
lib/hbase/response/row_response.rb
|
30
|
+
lib/hbase/response/table_response.rb
|
data/README.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
hbase-ruby is a pure ruby client for HBase using REST interface
|
2
|
+
|
3
|
+
== USAGE
|
4
|
+
|
5
|
+
First launch HBase:
|
6
|
+
|
7
|
+
1.
|
8
|
+
{{{
|
9
|
+
bin/start-hbase.sh
|
10
|
+
}}}
|
11
|
+
|
12
|
+
2. ruby code
|
13
|
+
{{{
|
14
|
+
require 'hbase'
|
15
|
+
|
16
|
+
client = HBase::Client.new("http://localhost:60010/api") # this url is the default.
|
17
|
+
tables = client.list_tables # list available tables
|
18
|
+
|
19
|
+
table = client.show_table('users') # show the meta info of table users
|
20
|
+
|
21
|
+
row = client.show_row('users', 'sishen') # show the data of row 'sishen' in table 'users'
|
22
|
+
|
23
|
+
row2 = client.create_row('users', 'sishen', Time.now.to_i, {:name => 'habbit:football', :value => 'i like football'}) # create the row 'sishen' with the data in the table 'users'
|
24
|
+
|
25
|
+
client.delete_row('users', 'sishen', nil, 'habbit:football') # delete the row 'sishen' of table 'users' with the optional column 'habbit:football'
|
26
|
+
}}}
|
27
|
+
|
28
|
+
|
29
|
+
== INSTALLTION
|
30
|
+
build the gem:
|
31
|
+
|
32
|
+
rake gem
|
33
|
+
|
34
|
+
and install the versioned gem:
|
35
|
+
|
36
|
+
gem install pkg/hbase-ruby-x.x.x.gem
|
37
|
+
|
38
|
+
== Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2007 Dingding Ye <yedingding@gmail.com>
|
41
|
+
Distributed under MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
|
4
|
+
Hoe.new('hbase-ruby', '0.1') do |p|
|
5
|
+
p.rubyforge_name = 'hbase-ruby'
|
6
|
+
p.author = 'Ye Dingding'
|
7
|
+
p.email = 'yedingding@gmail.com'
|
8
|
+
p.url = 'http://sishen.lifegoo.com'
|
9
|
+
p.summary = 'a pure ruby client for hbase using REST interface'
|
10
|
+
p.description = 'hbase-ruby is a pure ruby client for hbase and enable the ruby app enjoy the power of HBase'
|
11
|
+
end
|
data/hbase-ruby.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{hbase-ruby}
|
3
|
+
s.version = "0.2"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Ye Dingding"]
|
7
|
+
s.date = %q{2008-08-09}
|
8
|
+
s.description = %q{hbase-ruby is a pure ruby client for hbase and enable the ruby app enjoy the power of HBase}
|
9
|
+
s.email = %q{yedingding@gmail.com}
|
10
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
11
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.txt", "Rakefile", "hbase-ruby.gemspec", "lib/hbase.rb", "lib/hbase/client.rb", "lib/hbase/exception.rb", "lib/hbase/model.rb", "lib/hbase/model/column.rb", "lib/hbase/model/column_descriptor.rb", "lib/hbase/model/region_descriptor.rb", "lib/hbase/model/row.rb", "lib/hbase/model/table_descriptor.rb", "lib/hbase/operation/meta_operation.rb", "lib/hbase/operation/row_operation.rb", "lib/hbase/operation/scanner_operation.rb", "lib/hbase/operation/table_operation.rb", "lib/hbase/request.rb", "lib/hbase/request/basic_request.rb", "lib/hbase/request/meta_request.rb", "lib/hbase/request/row_request.rb", "lib/hbase/request/scanner_request.rb", "lib/hbase/request/table_request.rb", "lib/hbase/response.rb", "lib/hbase/response/basic_response.rb", "lib/hbase/response/meta_response.rb", "lib/hbase/response/row_response.rb", "lib/hbase/response/table_response.rb"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.homepage = %q{http://sishen.lifegoo.com}
|
14
|
+
s.rdoc_options = ["--main", "README.txt"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.rubyforge_project = %q{hbase-ruby}
|
17
|
+
s.rubygems_version = %q{1.2.0}
|
18
|
+
s.summary = %q{a pure ruby client for hbase using REST interface}
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 2
|
23
|
+
|
24
|
+
if current_version >= 3 then
|
25
|
+
s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
|
26
|
+
else
|
27
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
28
|
+
end
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
31
|
+
end
|
32
|
+
end
|
data/lib/hbase.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'hbase/client'
|
5
|
+
require 'hbase/exception'
|
6
|
+
require 'hbase/model'
|
7
|
+
require 'hbase/request'
|
8
|
+
require 'hbase/response'
|
9
|
+
|
10
|
+
module HBase; end
|
11
|
+
|
12
|
+
class Object
|
13
|
+
def to_proc
|
14
|
+
proc { |obj, *args| obj.send(self, *args) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def blank?
|
18
|
+
respond_to?(:empty?) ? empty? : !self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NilClass #:nodoc:
|
23
|
+
def blank?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Array #:nodoc:
|
29
|
+
alias_method :blank?, :empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
class Hash #:nodoc:
|
33
|
+
alias_method :blank?, :empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
class String #:nodoc:
|
37
|
+
def blank?
|
38
|
+
self !~ /\S/
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_b
|
42
|
+
self == "true" ? true : false
|
43
|
+
end
|
44
|
+
end
|
data/lib/hbase/client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'hbase/operation/meta_operation'
|
3
|
+
require 'hbase/operation/table_operation'
|
4
|
+
require 'hbase/operation/row_operation'
|
5
|
+
require 'hbase/operation/scanner_operation'
|
6
|
+
|
7
|
+
module HBase
|
8
|
+
class Client
|
9
|
+
include Operation::MetaOperation
|
10
|
+
include Operation::TableOperation
|
11
|
+
include Operation::RowOperation
|
12
|
+
include Operation::ScannerOperation
|
13
|
+
|
14
|
+
attr_reader :url, :connection
|
15
|
+
|
16
|
+
def initialize(url = "http://localhost:60010/api", opts = {})
|
17
|
+
@url = URI.parse(url)
|
18
|
+
unless @url.kind_of? URI::HTTP
|
19
|
+
raise "invalid http url: #{url}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Not actually opening the connection yet, just setting up the persistent connection.
|
23
|
+
@connection = Net::HTTP.new(@url.host, @url.port)
|
24
|
+
@connection.read_timeout = opts[:timeout] if opts[:timeout]
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(path)
|
28
|
+
safe_request { @connection.get(@url.path + path) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def post(path, data = nil)
|
32
|
+
safe_request { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml'}) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(path)
|
36
|
+
safe_request { @connection.delete(@url.path + path) }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def safe_request(&block)
|
41
|
+
response = yield
|
42
|
+
case response
|
43
|
+
when Net::HTTPSuccess then response.body
|
44
|
+
else
|
45
|
+
response.error!
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class HBase::Exception < Exception; end
|
data/lib/hbase/model.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module HBase
|
2
|
+
module Model
|
3
|
+
class Record
|
4
|
+
def initialize (params)
|
5
|
+
return if params.nil?
|
6
|
+
|
7
|
+
params.each do |key, value|
|
8
|
+
name = key.to_s
|
9
|
+
instance_variable_set("@#{name}", value) if respond_to?(name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'hbase/model/column'
|
17
|
+
require 'hbase/model/column_descriptor'
|
18
|
+
require 'hbase/model/region_descriptor'
|
19
|
+
require 'hbase/model/row'
|
20
|
+
require 'hbase/model/table_descriptor'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HBase
|
2
|
+
module Model
|
3
|
+
module CompressionType
|
4
|
+
NONE = "NONE"
|
5
|
+
RECORD = "RECORD"
|
6
|
+
BLOCK = "BLOCK"
|
7
|
+
|
8
|
+
def to_compression_type(type_string)
|
9
|
+
case type_string
|
10
|
+
when "NONE" then NONE
|
11
|
+
when "RECORD" then RECORD
|
12
|
+
when "BLOCK" then BLOCK
|
13
|
+
else
|
14
|
+
NONE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function :to_compression_type
|
19
|
+
end
|
20
|
+
|
21
|
+
class ColumnDescriptor < Record
|
22
|
+
AVAILABLE_OPTS = { :name => "name", :max_versions => "max-versions", :compression => "compression",
|
23
|
+
:in_memory => "in-memory", :block_cache => "block-cache", :max_cell_size => "max-cell-size",
|
24
|
+
:ttl => "time-to-live", :bloomfilter => "bloomfilter"}
|
25
|
+
attr_accessor :name
|
26
|
+
attr_accessor :compression
|
27
|
+
attr_accessor :bloomfilter
|
28
|
+
attr_accessor :maximum_cell_size
|
29
|
+
attr_accessor :max_versions
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module HBase
|
2
|
+
module Operation
|
3
|
+
module RowOperation
|
4
|
+
def row_timestamps(table_name, name)
|
5
|
+
raise NotImplementedError, "Currently not supported in native hbase client"
|
6
|
+
end
|
7
|
+
|
8
|
+
def show_row(table_name, name, timestamp = nil, columns = nil)
|
9
|
+
request = Request::RowRequest.new(table_name, name, timestamp)
|
10
|
+
row = Response::RowResponse.new(get(request.show(columns))).parse
|
11
|
+
row.table_name = table_name
|
12
|
+
row.name = name
|
13
|
+
row.timestamp = timestamp
|
14
|
+
row
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_row(table_name, name, timestamp = nil, data = { })
|
18
|
+
request = Request::RowRequest.new(table_name, name, timestamp)
|
19
|
+
xml_data =<<EOF
|
20
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
21
|
+
<column>
|
22
|
+
<name>#{data[:name]}</name>
|
23
|
+
<value>#{[data[:value]].pack("m")}</value>
|
24
|
+
</column>
|
25
|
+
EOF
|
26
|
+
Response::RowResponse.new(post(request.create, xml_data))
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_row(table_name, name, timestamp = nil, columns = nil)
|
30
|
+
request = Request::RowRequest.new(table_name, name, timestamp)
|
31
|
+
Response::RowResponse.new(delete(request.delete(columns)))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module HBase
|
2
|
+
module Operation
|
3
|
+
module TableOperation
|
4
|
+
def show_table(name)
|
5
|
+
request = Request::TableRequest.new(name)
|
6
|
+
table_descriptor = Response::TableResponse.new(get(request.show)).parse
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_table(name, *args)
|
10
|
+
request = Request::TableRequest.new(nil)
|
11
|
+
|
12
|
+
raise StandardError, "Table name must be of type String" unless name.instance_of? String
|
13
|
+
|
14
|
+
xml_data = "<?xml version='1.0' encoding='UTF-8'?><table><name>#{name}</name><columnfamilies>"
|
15
|
+
for arg in args
|
16
|
+
if arg.instance_of? String
|
17
|
+
xml_data << "<columnfamily><name>#{arg}</name></columnfamily>"
|
18
|
+
elsif arg.instance_of? Hash
|
19
|
+
xml_data << "<columnfamily>"
|
20
|
+
arg.each do |k,v|
|
21
|
+
if Model::ColumnDescriptor::AVAILABLE_OPTS.include? k
|
22
|
+
xml_data << "<#{Model::ColumnDescriptor::AVAILABLE_OPTS[k]}>#{v}</#{Model::ColumnDescriptor::AVAILABLE_OPTS[k]}>"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
xml_data << "</columnfamily>"
|
26
|
+
else
|
27
|
+
raise StandardError, "#{arg.class.to_s} of #{arg.to_s} is not of Hash Type"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
xml_data << "</columnfamilies></table>"
|
31
|
+
Response::TableResponse.new(post(request.create, xml_data))
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_table(name)
|
35
|
+
request = Request::TableRequest.new(name)
|
36
|
+
Response::TableResponse.new(delete(request.delete))
|
37
|
+
end
|
38
|
+
|
39
|
+
def enalbe_table(name)
|
40
|
+
request = Request::TableRequest.new(name)
|
41
|
+
Response::TableResponse.new(post(request.enable))
|
42
|
+
end
|
43
|
+
|
44
|
+
def disable_table(name)
|
45
|
+
request = Request::TableRequest.new(name)
|
46
|
+
Response::TableResponse.new(post(request.disable))
|
47
|
+
end
|
48
|
+
|
49
|
+
def table_regions(name, start_row = nil, end_row = nil)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module HBase
|
2
|
+
module Request
|
3
|
+
class RowRequest < BasicRequest
|
4
|
+
attr_reader :table_name
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :timestamp
|
7
|
+
|
8
|
+
def initialize(table_name, name, timestamp)
|
9
|
+
@table_name, @name, @timestamp = table_name, name, timestamp
|
10
|
+
path = "/#{table_name}/row/#{name}"
|
11
|
+
path << "/#{timestamp}" if timestamp
|
12
|
+
super(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show(columns = nil)
|
16
|
+
if columns
|
17
|
+
if columns.is_a? String
|
18
|
+
columns = [columns]
|
19
|
+
elsif columns.is_a? Array
|
20
|
+
end
|
21
|
+
@path << "?column=#{columns.join(';')}"
|
22
|
+
end
|
23
|
+
@path
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@path
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(columns = nil)
|
31
|
+
if columns
|
32
|
+
if columns.is_a? String
|
33
|
+
columns = [columns]
|
34
|
+
elsif columns.is_a? Array
|
35
|
+
end
|
36
|
+
@path << "?column=#{columns.join(';')}"
|
37
|
+
end
|
38
|
+
@path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module HBase
|
2
|
+
module Request
|
3
|
+
class TableRequest < BasicRequest
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :body
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
super("")
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@path << "#{name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def regions(start_row = nil, end_row = nil)
|
17
|
+
@path << "/#{name}/regions"
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@path << "/tables"
|
22
|
+
end
|
23
|
+
|
24
|
+
def enable
|
25
|
+
@path << "/tables/#{name}/enable"
|
26
|
+
end
|
27
|
+
|
28
|
+
def disable
|
29
|
+
@path << "/tables/#{name}/disable"
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete
|
33
|
+
@path << "/tables/#{name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module HBase
|
2
|
+
module Response
|
3
|
+
class MetaResponse < BasicResponse
|
4
|
+
attr_reader :method
|
5
|
+
|
6
|
+
def initialize(raw_data, method)
|
7
|
+
@method = method
|
8
|
+
super(raw_data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_content(raw_data)
|
12
|
+
case @method
|
13
|
+
when :list_tables
|
14
|
+
if raw_data.blank?
|
15
|
+
puts "There are no available tables in the HBase"
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
|
19
|
+
doc = REXML::Document.new(raw_data)
|
20
|
+
entry = doc.elements["tables"]
|
21
|
+
tables = []
|
22
|
+
entry.elements.each("table") do |table|
|
23
|
+
t = Model::TableDescriptor.new(:name => table.text.strip)
|
24
|
+
tables << t
|
25
|
+
end
|
26
|
+
tables
|
27
|
+
else
|
28
|
+
puts "method '#{@method}' not supported yet"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HBase
|
2
|
+
module Response
|
3
|
+
class RowResponse < BasicResponse
|
4
|
+
def parse_content(raw_data)
|
5
|
+
doc = REXML::Document.new(raw_data)
|
6
|
+
row = doc.elements["row"]
|
7
|
+
columns = []
|
8
|
+
row.elements.each("column") do |col|
|
9
|
+
name = col.elements["name"].text.strip.unpack("m").first
|
10
|
+
value = col.elements["value"].text.strip.unpack("m").first
|
11
|
+
columns << Model::Column.new(:name => name,
|
12
|
+
:value => value)
|
13
|
+
end
|
14
|
+
Model::Row.new(:columns => columns)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module HBase
|
2
|
+
module Response
|
3
|
+
class TableResponse < BasicResponse
|
4
|
+
def parse_content(raw_data)
|
5
|
+
doc = REXML::Document.new(raw_data)
|
6
|
+
table = doc.elements["table"]
|
7
|
+
|
8
|
+
name = table.elements["name"].text.strip
|
9
|
+
column_families = []
|
10
|
+
table.elements["columnfamilies"].elements.each("columnfamily") do |columnfamily|
|
11
|
+
colname = columnfamily.elements["name"].text.strip
|
12
|
+
compression = columnfamily.elements["compression"].text.strip
|
13
|
+
bloomfilter = columnfamily.elements["bloomfilter"].text.strip.to_b
|
14
|
+
max_versions = columnfamily.elements["max-versions"].text.strip.to_i
|
15
|
+
maximum_cell_size = columnfamily.elements["maximum-cell-size"].text.strip.to_i
|
16
|
+
|
17
|
+
column_descriptor = Model::ColumnDescriptor.new(:name => colname,
|
18
|
+
:compression => Model::CompressionType.to_compression_type(compression),
|
19
|
+
:bloomfilter => bloomfilter,
|
20
|
+
:max_versions => max_versions,
|
21
|
+
:maximum_cell_size => maximum_cell_size)
|
22
|
+
column_families << column_descriptor
|
23
|
+
end
|
24
|
+
Model::TableDescriptor.new(:name => name, :column_families => column_families)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sishen-hbase-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ye Dingding
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-09 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.7.0
|
23
|
+
version:
|
24
|
+
description: hbase-ruby is a pure ruby client for hbase and enable the ruby app enjoy the power of HBase
|
25
|
+
email: yedingding@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- MIT-LICENSE
|
37
|
+
- Manifest.txt
|
38
|
+
- README.txt
|
39
|
+
- Rakefile
|
40
|
+
- hbase-ruby.gemspec
|
41
|
+
- lib/hbase.rb
|
42
|
+
- lib/hbase/client.rb
|
43
|
+
- lib/hbase/exception.rb
|
44
|
+
- lib/hbase/model.rb
|
45
|
+
- lib/hbase/model/column.rb
|
46
|
+
- lib/hbase/model/column_descriptor.rb
|
47
|
+
- lib/hbase/model/region_descriptor.rb
|
48
|
+
- lib/hbase/model/row.rb
|
49
|
+
- lib/hbase/model/table_descriptor.rb
|
50
|
+
- lib/hbase/operation/meta_operation.rb
|
51
|
+
- lib/hbase/operation/row_operation.rb
|
52
|
+
- lib/hbase/operation/scanner_operation.rb
|
53
|
+
- lib/hbase/operation/table_operation.rb
|
54
|
+
- lib/hbase/request.rb
|
55
|
+
- lib/hbase/request/basic_request.rb
|
56
|
+
- lib/hbase/request/meta_request.rb
|
57
|
+
- lib/hbase/request/row_request.rb
|
58
|
+
- lib/hbase/request/scanner_request.rb
|
59
|
+
- lib/hbase/request/table_request.rb
|
60
|
+
- lib/hbase/response.rb
|
61
|
+
- lib/hbase/response/basic_response.rb
|
62
|
+
- lib/hbase/response/meta_response.rb
|
63
|
+
- lib/hbase/response/row_response.rb
|
64
|
+
- lib/hbase/response/table_response.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://sishen.lifegoo.com
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --main
|
70
|
+
- README.txt
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: hbase-ruby
|
88
|
+
rubygems_version: 1.2.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 2
|
91
|
+
summary: a pure ruby client for hbase using REST interface
|
92
|
+
test_files: []
|
93
|
+
|