sishen-hbase-ruby 0.5.0 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{hbase-ruby}
3
- s.version = "0.5.0"
3
+ s.version = "1.0"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Ye Dingding"]
7
- s.date = %q{2008-08-09}
7
+ s.date = %q{2009-03-08}
8
8
  s.description = %q{hbase-ruby is a pure ruby client for hbase and enable the ruby app enjoy the power of HBase}
9
9
  s.email = %q{yedingding@gmail.com}
10
10
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
11
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/model/scanner.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", "lib/hbase/response/scanner_response.rb"]
12
12
  s.has_rdoc = true
13
- s.homepage = %q{http://sishen.lifegoo.com}
13
+ s.homepage = %q{http://github.com/sishen}
14
14
  s.rdoc_options = ["--main", "README.txt"]
15
15
  s.require_paths = ["lib"]
16
16
  s.rubygems_version = %q{1.2.0}
@@ -51,12 +51,13 @@ module HBase
51
51
  rescue Errno::ECONNREFUSED
52
52
  raise ConnectionNotEstablishedError, "can't connect to #{@url}"
53
53
  rescue Timeout::Error => e
54
+ puts e.backtrace.join("\n")
54
55
  raise ConnectionTimeoutError, "execution expired. Maybe query disabled tables"
55
56
  end
56
57
 
57
58
  case response
58
59
  when Net::HTTPSuccess
59
- response.body.blank? ? response.header : response.body
60
+ response.body
60
61
  else
61
62
  response.error!
62
63
  end
@@ -4,7 +4,7 @@ module HBase
4
4
  NONE = "NONE"
5
5
  RECORD = "RECORD"
6
6
  BLOCK = "BLOCK"
7
-
7
+
8
8
  CTYPES = [NONE, RECORD, BLOCK]
9
9
 
10
10
  def to_compression_type(type_string)
@@ -18,7 +18,6 @@ module HBase
18
18
  request = Request::RowRequest.new(table_name, name, timestamp)
19
19
  row = Response::RowResponse.new(get(request.show(columns, options))).parse
20
20
  row.table_name = table_name
21
- row.name = name
22
21
  row.timestamp = timestamp
23
22
  row
24
23
  rescue Net::ProtocolError => e
@@ -34,12 +33,14 @@ module HBase
34
33
  begin
35
34
  request = Request::RowRequest.new(table_name, name, timestamp)
36
35
  data = []
37
- if columns.instance_of? Array
38
- data = columns
39
- elsif columns.instance_of? Hash
40
- data = [columns]
41
- else
42
- raise StandardError, "Only Array or Hash data accepted"
36
+ if columns
37
+ if columns.instance_of? Array
38
+ data = columns
39
+ elsif columns.instance_of? Hash
40
+ data = [columns]
41
+ else
42
+ raise StandardError, "Only Array or Hash data accepted"
43
+ end
43
44
  end
44
45
  xml_data ="<?xml version='1.0' encoding='UTF-8'?><columns>"
45
46
  data.each do |d|
@@ -49,7 +50,7 @@ module HBase
49
50
  end
50
51
  xml_data << "</columns>"
51
52
 
52
- Response::RowResponse.new(post(request.create, xml_data))
53
+ post(request.create, xml_data)
53
54
  rescue Net::ProtocolError => e
54
55
  if e.to_s.include?("Table")
55
56
  raise TableNotFoundError, "Table '#{table_name}' Not Found"
@@ -1,10 +1,12 @@
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)
4
+ def open_scanner(table_name, columns, start_row = nil, stop_row = nil, timestamp = nil)
5
5
  begin
6
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
7
+ scanner = Response::ScannerResponse.new(post(request.open(columns, start_row, stop_row, timestamp))).parse
8
+ scanner.table_name = table_name
9
+ scanner
8
10
  rescue Net::ProtocolError => e
9
11
  if e.to_s.include?("TableNotFoundException")
10
12
  raise TableNotFoundError, "Table #{table_name} Not Found!"
@@ -73,6 +73,11 @@ module HBase
73
73
  end
74
74
  end
75
75
 
76
+ def destroy_table(name, columns = nil)
77
+ disable_table(name)
78
+ delete_table(name, columns)
79
+ end
80
+
76
81
  def enable_table(name)
77
82
  begin
78
83
  request = Request::TableRequest.new(name)
@@ -9,11 +9,11 @@ module HBase
9
9
  super(path)
10
10
  end
11
11
 
12
- def open(columns, start_row = nil, end_row = nil, timestamp = nil)
12
+ def open(columns, start_row = nil, stop_row = nil, timestamp = nil)
13
13
  search = []
14
14
  search << pack_params(columns)
15
15
  search << "start_row=#{CGI.escape(start_row)}" if start_row
16
- search << "end_row=#{CGI.escape(end_row)}" if end_row
16
+ search << "stop_row=#{CGI.escape(end_row)}" if stop_row
17
17
  search << "timestamp=#{CGI.escape(timestamp)}" if timestamp
18
18
 
19
19
  @path << "?" << search.join('&')
@@ -20,7 +20,8 @@ module HBase
20
20
  entry = doc.elements["tables"]
21
21
  tables = []
22
22
  entry.elements.each("table") do |table|
23
- t = Model::TableDescriptor.new(:name => table.text.strip)
23
+ name = table.elements["name"].text.strip rescue nil
24
+ t = Model::TableDescriptor.new(:name => name)
24
25
  tables << t
25
26
  end
26
27
  tables
@@ -4,9 +4,11 @@ module HBase
4
4
  def parse_content(raw_data)
5
5
  doc = REXML::Document.new(raw_data)
6
6
  row = doc.elements["row"]
7
+ rname = row.elements["name"].text.strip.unpack("m").first
7
8
  columns = []
9
+ # Need fix in the server side
8
10
  count = row.elements["count"].text.strip.to_i rescue 0
9
- row.elements.each("column") do |col|
11
+ row.elements["columns"].elements.each("column") do |col|
10
12
  name = col.elements["name"].text.strip.unpack("m").first
11
13
  value = col.elements["value"].text.strip.unpack("m").first rescue nil
12
14
  timestamp = col.elements["timestamp"].text.strip.to_i
@@ -14,7 +16,7 @@ module HBase
14
16
  :value => value,
15
17
  :timestamp => timestamp)
16
18
  end
17
- Model::Row.new(:total_count => count, :columns => columns)
19
+ Model::Row.new(:name => rname, :total_count => count, :columns => columns)
18
20
  end
19
21
  end
20
22
  end
@@ -2,30 +2,33 @@ module HBase
2
2
  module Response
3
3
  class ScannerResponse < BasicResponse
4
4
  def parse_content(raw_data)
5
+ puts raw_data
6
+
5
7
  doc = REXML::Document.new(raw_data)
6
- doc = doc.elements["rows"] if doc.elements["rows"] && doc.elements["rows"].has_elements?
7
8
 
8
- rows = []
9
- doc.elements.each("row") do |row|
10
- row_name = row.elements["name"].text.strip.unpack("m").first
11
- columns = []
12
- row.elements.each("column") do |col|
13
- name = col.elements["name"].text.strip.unpack("m").first
14
- value = col.elements["value"].text.strip.unpack("m").first rescue nil
15
- timestamp = col.elements["timestamp"].text.strip.to_i
16
- columns << Model::Column.new(:name => name,
17
- :value => value,
18
- :timestamp => timestamp)
9
+ if doc.elements["/scanner"] && doc.elements["/scanner"].has_elements?
10
+ scanner = doc.elements["scanner"]
11
+ id = scanner.elements["id"].text.strip.to_i
12
+ Model::Scanner.new(:scanner_id => id)
13
+
14
+ elsif doc.elements["rows"] && doc.elements["rows"].has_elements?
15
+ doc = doc.elements["rows"]
16
+ rows = []
17
+ doc.elements.each("row") do |row|
18
+ row_name = row.elements["name"].text.strip.unpack("m").first
19
+ columns = []
20
+ row.elements.each("column") do |col|
21
+ name = col.elements["name"].text.strip.unpack("m").first
22
+ value = col.elements["value"].text.strip.unpack("m").first rescue nil
23
+ timestamp = col.elements["timestamp"].text.strip.to_i
24
+ columns << Model::Column.new(:name => name,
25
+ :value => value,
26
+ :timestamp => timestamp)
27
+ end
28
+ rows << Model::Row.new(:name => row_name, :columns => columns)
19
29
  end
20
- rows << Model::Row.new(:name => row_name, :columns => columns)
30
+ rows
21
31
  end
22
- rows
23
- end
24
-
25
- def get_scanner_id
26
- location = @raw_data['location']
27
- paths = location.split('/')
28
- Model::Scanner.new(:table_name => paths[2], :scanner_id => paths[4])
29
32
  end
30
33
  end
31
34
  end
@@ -12,7 +12,7 @@ module HBase
12
12
  compression = columnfamily.elements["compression"].text.strip
13
13
  bloomfilter = columnfamily.elements["bloomfilter"].text.strip.to_b
14
14
  max_versions = columnfamily.elements["max-versions"].text.strip.to_i
15
- maximum_cell_size = columnfamily.elements["maximum-cell-size"].text.strip.to_i
15
+ maximum_cell_size = columnfamily.elements["max-length"].text.strip.to_i
16
16
 
17
17
  column_descriptor = Model::ColumnDescriptor.new(:name => colname,
18
18
  :compression => Model::CompressionType.to_compression_type(compression),
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.5.0
4
+ version: "1.0"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ye Dingding
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-09 00:00:00 -07:00
12
+ date: 2009-03-08 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: rspec
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -74,7 +76,7 @@ files:
74
76
  - lib/hbase/response/table_response.rb
75
77
  - lib/hbase/response/scanner_response.rb
76
78
  has_rdoc: true
77
- homepage: http://sishen.lifegoo.com
79
+ homepage: http://github.com/sishen
78
80
  post_install_message:
79
81
  rdoc_options:
80
82
  - --main
data/README.txt DELETED
@@ -1,65 +0,0 @@
1
- hbase-ruby is a pure ruby client for HBase (http://hadoop.apache.org/hbase). It works with the most recent version of HBase REST interface.
2
-
3
- == INSTALLTION
4
-
5
- $gem sources -a http://gems.github.com
6
- $gem install sishen-hbase-ruby
7
-
8
- For those who wants to use hbase in their rails application, can add this line to the environment.rb:
9
- {{{
10
- config.gem 'sishen-hbase-ruby', :lib => "hbase", :source => "http://gems.github.com"
11
- }}}
12
-
13
- To build the gem yourself:
14
-
15
- $rake gem
16
-
17
- == USAGE
18
-
19
- First download the recent version of hbase (svn checkout http://svn.apache.org/repos/asf/hadoop/hbase/trunk hbase), compile it with 'ant', then launch HBase server:
20
-
21
- $bin/start-hbase.sh
22
-
23
- Here is the example:
24
- {{{
25
- require 'hbase'
26
-
27
- client = HBase::Client.new("http://localhost:60010/api") # this url is the default.
28
-
29
- # Table Operation
30
- tables = client.list_tables # list available tables
31
- table = client.create_table('users', 'habbit') # create a table whose column_family is habbit
32
- table = client.show_table('users') # show the meta info of table users
33
- client.disable_table('users') # disable table users
34
- client.enable_table('users') # enable table users
35
- client.delete_table('users') # delete table users
36
-
37
- # Row Operation
38
- row = client.show_row('users', 'sishen') # show the data of row 'sishen' in table 'users'
39
- 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'
40
- client.delete_row('users', 'sishen', nil, 'habbit:football') # delete the row 'sishen' of table 'users' with the optional column 'habbit:football'
41
-
42
- # Scanner Operation
43
- scanner = client.open_scanner('users', 'habbit:')
44
- rows = client.get_rows(scanner)
45
- client.close_scanner(scanner)
46
- }}}
47
-
48
- == Testing
49
-
50
- First you want to install rspec gem:
51
-
52
- {{{
53
- sudo gem install rspec
54
- }}}
55
-
56
- Now, you can run the spec by following rake task:
57
-
58
- {{{
59
- rake examples
60
- }}}
61
-
62
- == Copyright
63
-
64
- Copyright (c) 2008 Dingding Ye <yedingding@gmail.com>
65
- Distributed under MIT License