sishen-hbase-ruby 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sishen-hbase-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ye Dingding
data/History.txt DELETED
@@ -1,2 +0,0 @@
1
- v0.1 Jul 29, 2008
2
- * initial version
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
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 DELETED
@@ -1,30 +0,0 @@
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 DELETED
@@ -1,49 +0,0 @@
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
- 3. rails config
29
-
30
- For those who wants to use hbase in their rails application, can add this line to the environment.rb
31
-
32
- {{{
33
- config.gem 'sishen-hbase-ruby', :lib => "hbase", :source => "http://gems.github.com"
34
- }}}
35
-
36
-
37
- == INSTALLTION
38
- build the gem:
39
-
40
- rake gem
41
-
42
- and install the versioned gem:
43
-
44
- gem install pkg/hbase-ruby-x.x.x.gem
45
-
46
- == Copyright
47
-
48
- Copyright (c) 2007 Dingding Ye <yedingding@gmail.com>
49
- Distributed under MIT License
data/Rakefile DELETED
@@ -1,11 +0,0 @@
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 DELETED
@@ -1,31 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{hbase-ruby}
3
- s.version = "0.2.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.rubygems_version = %q{1.2.0}
17
- s.summary = %q{a pure ruby client for hbase using REST interface}
18
-
19
- if s.respond_to? :specification_version then
20
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
21
- s.specification_version = 2
22
-
23
- if current_version >= 3 then
24
- s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
25
- else
26
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
27
- end
28
- else
29
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
30
- end
31
- end
data/lib/hbase/client.rb DELETED
@@ -1,49 +0,0 @@
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
@@ -1 +0,0 @@
1
- class HBase::Exception < Exception; end
@@ -1,8 +0,0 @@
1
- module HBase
2
- module Model
3
- class Column < Record
4
- attr_accessor :name
5
- attr_accessor :value
6
- end
7
- end
8
- end
@@ -1,32 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- module HBase
2
- module Model
3
- class Region < Record
4
- end
5
-
6
- class RegionDescriptor < Record
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- module HBase
2
- module Model
3
- class Row < Record
4
- attr_accessor :table_name
5
- attr_accessor :name
6
- attr_accessor :timestamp
7
- attr_accessor :columns
8
- end
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- module HBase
2
- module Model
3
- class TableDescriptor < Record
4
- attr_accessor :name
5
- attr_accessor :column_families
6
- end
7
- end
8
- end
data/lib/hbase/model.rb DELETED
@@ -1,20 +0,0 @@
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'
@@ -1,10 +0,0 @@
1
- module HBase
2
- module Operation
3
- module MetaOperation
4
- def list_tables
5
- request = Request::MetaRequest.new
6
- tables = Response::MetaResponse.new(get(request.list_tables), :list_tables).parse
7
- end
8
- end
9
- end
10
- end
@@ -1,43 +0,0 @@
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, *args)
18
- request = Request::RowRequest.new(table_name, name, timestamp)
19
- data = []
20
- if args.instance_of? Array
21
- data = args
22
- elsif args.instance_of? Hash
23
- data = [args]
24
- else
25
- raise StandardError, "Only Array or Hash data accepted"
26
- end
27
- xml_data ="<?xml version='1.0' encoding='UTF-8'?><columns>"
28
- data.each do |d|
29
- xml_data << "<column><name>#{d[:name]}</name>"
30
- xml_data << "<value>#{[d[:value]].pack("m") rescue ''}</value></column>"
31
- end
32
- xml_data << "</columns>"
33
-
34
- Response::RowResponse.new(post(request.create, xml_data))
35
- end
36
-
37
- def delete_row(table_name, name, timestamp = nil, columns = nil)
38
- request = Request::RowRequest.new(table_name, name, timestamp)
39
- Response::RowResponse.new(delete(request.delete(columns)))
40
- end
41
- end
42
- end
43
- end
@@ -1,6 +0,0 @@
1
- module HBase
2
- module Operation
3
- module ScannerOperation
4
- end
5
- end
6
- end
@@ -1,53 +0,0 @@
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
@@ -1,13 +0,0 @@
1
- require 'cgi'
2
-
3
- module HBase
4
- module Request
5
- class BasicRequest
6
- attr_reader :path
7
-
8
- def initialize(path)
9
- @path = path
10
- end
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- module HBase
2
- module Request
3
- class MetaRequest < BasicRequest
4
- def initialize
5
- super("/")
6
- end
7
-
8
- def list_tables
9
- @path
10
- end
11
-
12
- def create_table
13
- @path << "/tables"
14
- end
15
- end
16
- end
17
- end
@@ -1,44 +0,0 @@
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 = CGI.escape(table_name), CGI.escape(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
- params = columns.collect { |column| "column=#{column}" }.join('&')
22
- @path << "?#{params}"
23
- end
24
- @path
25
- end
26
-
27
- def create
28
- @path
29
- end
30
-
31
- def delete(columns = nil)
32
- if columns
33
- if columns.is_a? String
34
- columns = [columns]
35
- elsif columns.is_a? Array
36
- end
37
- params = columns.collect { |column| "column=#{column}" }.join('&')
38
- @path << "?#{params}"
39
- end
40
- @path
41
- end
42
- end
43
- end
44
- end
@@ -1,6 +0,0 @@
1
- module HBase
2
- module Request
3
- class ScannerRequest < BasicRequest
4
- end
5
- end
6
- end
@@ -1,37 +0,0 @@
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 = CGI.escape(name) if 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
data/lib/hbase/request.rb DELETED
@@ -1,7 +0,0 @@
1
- module HBase; module Request; end; end
2
-
3
- require 'hbase/request/basic_request'
4
- require 'hbase/request/meta_request'
5
- require 'hbase/request/table_request'
6
- require 'hbase/request/row_request'
7
- require 'hbase/request/scanner_request'
@@ -1,17 +0,0 @@
1
- require 'rexml/document'
2
-
3
- module HBase
4
- module Response
5
- class BasicResponse
6
-
7
- def initialize(raw_data)
8
- puts raw_data
9
- @raw_data = raw_data
10
- end
11
-
12
- def parse
13
- parse_content @raw_data
14
- end
15
- end
16
- end
17
- end
@@ -1,33 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,28 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- module HBase; module Response; end; end
2
-
3
- require 'hbase/response/basic_response'
4
- require 'hbase/response/meta_response'
5
- require 'hbase/response/table_response'
6
- require 'hbase/response/row_response'
data/lib/hbase.rb DELETED
@@ -1,44 +0,0 @@
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