hbase-ruby 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +11 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +81 -0
  4. data/Rakefile +24 -0
  5. data/VERSION +1 -0
  6. data/lib/hbase.rb +44 -0
  7. data/lib/hbase/client.rb +80 -0
  8. data/lib/hbase/exception.rb +19 -0
  9. data/lib/hbase/model.rb +19 -0
  10. data/lib/hbase/model/column.rb +9 -0
  11. data/lib/hbase/model/column_descriptor.rb +32 -0
  12. data/lib/hbase/model/region_descriptor.rb +9 -0
  13. data/lib/hbase/model/row.rb +11 -0
  14. data/lib/hbase/model/scanner.rb +13 -0
  15. data/lib/hbase/model/table_descriptor.rb +8 -0
  16. data/lib/hbase/operation/meta_operation.rb +10 -0
  17. data/lib/hbase/operation/row_operation.rb +83 -0
  18. data/lib/hbase/operation/scanner_operation.rb +82 -0
  19. data/lib/hbase/operation/table_operation.rb +95 -0
  20. data/lib/hbase/request.rb +7 -0
  21. data/lib/hbase/request/basic_request.rb +27 -0
  22. data/lib/hbase/request/meta_request.rb +17 -0
  23. data/lib/hbase/request/row_request.rb +34 -0
  24. data/lib/hbase/request/scanner_request.rb +25 -0
  25. data/lib/hbase/request/table_request.rb +43 -0
  26. data/lib/hbase/response.rb +7 -0
  27. data/lib/hbase/response/basic_response.rb +16 -0
  28. data/lib/hbase/response/meta_response.rb +35 -0
  29. data/lib/hbase/response/row_response.rb +31 -0
  30. data/lib/hbase/response/scanner_response.rb +37 -0
  31. data/lib/hbase/response/table_response.rb +26 -0
  32. data/spec/hbase/model/column_descriptor_spec.rb +23 -0
  33. data/spec/hbase/model/column_spec.rb +12 -0
  34. data/spec/hbase/model/region_descriptor_spec.rb +4 -0
  35. data/spec/hbase/model/row_spec.rb +12 -0
  36. data/spec/hbase/model/scanner.rb +7 -0
  37. data/spec/hbase/model/table_descriptor_spec.rb +12 -0
  38. data/spec/hbase/operation/meta_operation_spec.rb +18 -0
  39. data/spec/hbase/operation/row_operation_spec.rb +39 -0
  40. data/spec/hbase/operation/scanner_operation_spec.rb +81 -0
  41. data/spec/hbase/operation/table_operation_spec.rb +57 -0
  42. data/spec/hbase/record_spec.rb +25 -0
  43. data/spec/hbase/request/meta_request_spec.rb +10 -0
  44. data/spec/hbase/request/row_request_spec.rb +5 -0
  45. data/spec/hbase/request/scanner_request_spec.rb +5 -0
  46. data/spec/hbase/request/table_request_spec.rb +4 -0
  47. data/spec/hbase/response/meta_response_spec.rb +4 -0
  48. data/spec/hbase/response/row_response_spec.rb +4 -0
  49. data/spec/hbase/response/scanner_response_spec.rb +4 -0
  50. data/spec/hbase/response/table_response_spec.rb +4 -0
  51. data/spec/spec.opts +5 -0
  52. data/spec/spec_helper.rb +7 -0
  53. data/tasks/rspec.rake +7 -0
  54. metadata +147 -0
@@ -0,0 +1,26 @@
1
+ module HBase
2
+ module Response
3
+ class TableResponse < BasicResponse
4
+ def parse_content(raw_data)
5
+ table = JSON.parse(raw_data)
6
+ name = table["name"].strip
7
+
8
+ column_families = []
9
+ table["ColumnSchema"].each do |columnfamily|
10
+ colname = columnfamily["name"].strip
11
+ compression = columnfamily["COMPRESSION"].strip
12
+ bloomfilter = columnfamily["BLOOMFILTER"].strip.to_b
13
+ max_versions = columnfamily["VERSIONS"].strip.to_i
14
+
15
+ column_descriptor = Model::ColumnDescriptor.new(:name => colname,
16
+ :compression => Model::CompressionType.to_compression_type(compression),
17
+ :bloomfilter => bloomfilter,
18
+ :max_versions => max_versions)
19
+ column_families << column_descriptor
20
+ end
21
+
22
+ Model::TableDescriptor.new(:name => name, :column_families => column_families)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::CompressionType do
4
+
5
+ it "should be return the correct type" do
6
+ HBase::Model::CompressionType.to_compression_type("RECORD").should == "RECORD"
7
+ HBase::Model::CompressionType.to_compression_type("BLOCK").should == "BLOCK"
8
+ HBase::Model::CompressionType.to_compression_type("NONE").should == "NONE"
9
+ HBase::Model::CompressionType.to_compression_type("OTHER").should == "NONE"
10
+ end
11
+
12
+ end
13
+
14
+ describe HBase::Model::ColumnDescriptor do
15
+
16
+ it "should be have such attributes" do
17
+ column = HBase::Model::ColumnDescriptor.new({})
18
+ %w{name compression bloomfilter maximum_cell_size max_versions}.each do |method|
19
+ column.should respond_to(method)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::Column do
4
+
5
+ it "should be have such attributes" do
6
+ column = HBase::Model::Column.new({})
7
+ %w{name value timestamp}.each do |method|
8
+ column.should respond_to(method)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::RegionDescriptor do
4
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::Row do
4
+
5
+ it "should be have such attributes" do
6
+ obj = HBase::Model::Row.new({})
7
+ %w{name table_name timestamp columns}.each do |method|
8
+ obj.should respond_to(method)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::Scanner do
4
+
5
+ it "should be ..."
6
+
7
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Model::TableDescriptor do
4
+
5
+ it "should be have such attributes" do
6
+ obj = HBase::Model::TableDescriptor.new({})
7
+ %w{name column_families}.each do |method|
8
+ obj.should respond_to(method)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Operation::MetaOperation do
4
+
5
+ before do
6
+ url = ENV["HBASE_URL"].nil? ? "http://localhost:8080" : ENV["HBASE_URL"]
7
+ @client = HBase::Client.new(url)
8
+ end
9
+
10
+ it "should return tables" do
11
+ tables = @client.list_tables
12
+ tables.should respond_to(:size)
13
+ tables.each do |table|
14
+ table.should.is_a? HBase::Model::TableDescriptor
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Operation::RowOperation do
4
+ before :all do
5
+ url = ENV["HBASE_URL"].nil? ? "http://localhost:8080" : ENV["HBASE_URL"]
6
+ @client = HBase::Client.new(url)
7
+
8
+ table = @client.create_table("test-hbase-ruby", "col1")
9
+ end
10
+
11
+ it "should create two rows called 'row1'" do
12
+ lambda {
13
+ row2 = @client.create_row("test-hbase-ruby", "row1", nil, { :name => "col1:", :value => "row1-col1" })
14
+ }.should_not raise_error
15
+ end
16
+
17
+ it "should show the rows 'row1'" do
18
+ row = @client.show_row("test-hbase-ruby", "row1")
19
+ row.should.is_a? HBase::Model::Row
20
+ row.table_name.should == "test-hbase-ruby"
21
+ row.name.should == "row1"
22
+ row.columns.size.should == 1
23
+ row.columns.each do |col|
24
+ col.should.is_a? HBase::Model::Column
25
+ col.name.should == "col1:"
26
+ col.value.should == "row1-col1"
27
+ end
28
+ end
29
+
30
+ it "should delete the rows 'row1'" do
31
+ lambda {
32
+ row1 = @client.delete_row('test-hbase-ruby', 'row1')
33
+ }.should_not raise_error
34
+ end
35
+
36
+ after :all do
37
+ table = @client.destroy_table("test-hbase-ruby")
38
+ end
39
+ end
@@ -0,0 +1,81 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Operation::ScannerOperation do
4
+ before :all do
5
+ url = ENV["HBASE_URL"].nil? ? "http://localhost:8080" : ENV["HBASE_URL"]
6
+ @client = HBase::Client.new(url)
7
+
8
+ table = @client.create_table("test-hbase-ruby", "col1")
9
+
10
+ @client.create_row('test-hbase-ruby', 'row1', nil, {:name => 'col1:', :value => "row1-col1"})
11
+ @client.create_row('test-hbase-ruby', 'row2', nil, {:name => 'col1:', :value => "row2-col1"})
12
+ @client.create_row('test-hbase-ruby', 'row3', nil, {:name => 'col1:', :value => "row3-col1"})
13
+ end
14
+
15
+ it "should open a scanner and close it successfully" do
16
+ scanner = @client.open_scanner("test-hbase-ruby")
17
+ scanner.should.is_a? HBase::Model::Scanner
18
+
19
+ lambda {
20
+ URI.parse("scanner.scanner_url")
21
+ }.should_not raise_error
22
+
23
+ lambda {
24
+ @client.close_scanner(scanner).should be_true
25
+ }.should_not raise_error
26
+ end
27
+
28
+ it "should scan the whole table when given no options" do
29
+ scanner = @client.open_scanner("test-hbase-ruby")
30
+
31
+ rows = @client.get_rows(scanner)
32
+ rows.size.should == 1
33
+ rows.first.name.should == "row1"
34
+
35
+ @client.close_scanner(scanner).should be_true
36
+ end
37
+
38
+ it "should scan the whole table when given a batch size larger than the number of rows" do
39
+ scanner = @client.open_scanner("test-hbase-ruby", {:batch => 5})
40
+
41
+ rows = @client.get_rows(scanner)
42
+ rows.size.should == 3
43
+ rows.each do |row|
44
+ row.should be_an_instance_of HBase::Model::Row
45
+ ["row1", "row2", "row3"].should include(row.name)
46
+ end
47
+
48
+ @client.close_scanner(scanner).should be_true
49
+ end
50
+
51
+ it "should scan the correct row when given a start_row" do
52
+ scanner = @client.open_scanner("test-hbase-ruby", {:start_row => "row2", :batch => 5})
53
+
54
+ rows = @client.get_rows(scanner)
55
+ rows.size.should == 2
56
+ rows.each do |row|
57
+ row.should be_an_instance_of HBase::Model::Row
58
+ ["row2", "row3"].should include(row.name)
59
+ end
60
+
61
+ @client.close_scanner(scanner).should be_true
62
+ end
63
+
64
+ it "should scan the correct row when given an end_row" do
65
+ # The end_row defined is exclusive, i.e. end_row does not get returned in scanner
66
+ scanner = @client.open_scanner("test-hbase-ruby", {:end_row => "row3", :batch => 5})
67
+
68
+ rows = @client.get_rows(scanner)
69
+ rows.size.should == 2
70
+ rows.each do |row|
71
+ row.should be_an_instance_of HBase::Model::Row
72
+ ["row1", "row2"].should include(row.name)
73
+ end
74
+
75
+ @client.close_scanner(scanner).should be_true
76
+ end
77
+
78
+ after :all do
79
+ @client.destroy_table("test-hbase-ruby")
80
+ end
81
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Operation::TableOperation do
4
+ before :all do
5
+ url = ENV["HBASE_URL"].nil? ? "http://localhost:8080" : ENV["HBASE_URL"]
6
+ @client = HBase::Client.new(url)
7
+ end
8
+
9
+ it "should create a table called test-hbase-ruby" do
10
+ table = @client.create_table('test-hbase-ruby', { :name => 'habbit',
11
+ :max_version => 3,
12
+ :compression => HBase::Model::CompressionType::NONE,
13
+ :in_memory => false,
14
+ :block_cache => false,
15
+ :ttl => -1,
16
+ :max_cell_size => 2147483647,
17
+ :bloomfilter => false
18
+ })
19
+ table.should.is_a? HBase::Model::TableDescriptor
20
+ end
21
+
22
+ it "should show the table info of 'test-hbase-ruby'" do
23
+ table = @client.show_table('test-hbase-ruby')
24
+ table.should.is_a? HBase::Model::TableDescriptor
25
+ table.name.should == "test-hbase-ruby"
26
+ table.column_families.should respond_to(:each)
27
+ table.column_families.map(&:name).should include("habbit")
28
+ table.column_families.each do |cf|
29
+ cf.should.is_a? HBase::Model::ColumnDescriptor
30
+ end
31
+ end
32
+
33
+ it "should disable table 'test-hbase-ruby'" do
34
+ lambda {
35
+ table = @client.disable_table('test-hbase-ruby')
36
+ }.should_not raise_error
37
+ end
38
+
39
+ it "should enable table 'test-hbase-ruby'" do
40
+ lambda {
41
+ table = @client.enable_table('test-hbase-ruby')
42
+ }.should_not raise_error
43
+ end
44
+
45
+ it "should delete the table 'test-hbase-ruby'" do
46
+ lambda {
47
+ table = @client.destroy_table("test-hbase-ruby")
48
+ }.should_not raise_error
49
+
50
+ lambda {
51
+ table = @client.show_table("test-hbase-ruby")
52
+ }.should raise_error(HBase::TableNotFoundError)
53
+ end
54
+
55
+ after :all do
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ describe HBase::Model::Record do
4
+
5
+ # Stub
6
+ it "should be true" do
7
+ true.should == true
8
+ end
9
+
10
+ describe "Init" do
11
+
12
+ it "should be successfuly when has the such instance variable" do
13
+ class HBase::Model::Record ; attr_accessor :a ; end
14
+ record = HBase::Model::Record.new({:a => 1})
15
+ record.a.should == 1
16
+ end
17
+
18
+ it "should be not set the attribute when no such instance variable" do
19
+ record = HBase::Model::Record.new({:a => 1})
20
+ lambda{record.sent(:a)}.should raise_error NoMethodError
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,10 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Request::MetaRequest do
4
+
5
+ it "should get create_table path correctly" do
6
+ mr = HBase::Request::MetaRequest.new
7
+ mr.create_table.should == "/tables"
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Request::RowRequest do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Request::ScannerRequest do
4
+
5
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Request::TableRequest do
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Response::MetaResponse do
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Response::RowResponse do
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Response::ScannerResponse do
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe HBase::Response::TableResponse do
4
+ end
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
5
+ --debugger
@@ -0,0 +1,7 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require File.join(File.dirname(__FILE__), "..", "lib", "hbase")
4
+
5
+ Spec::Runner.configure do |config|
6
+ #.etc
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_files = FileList['spec/**/*_spec.rb']
6
+ t.spec_opts = File.open("spec/spec.opts").readlines.map{|x| x.chomp}
7
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hbase-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ye Dingding
8
+ - Greg Lu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-11-07 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: A pure ruby client used to interact with HBase through its Stargate interface which serves up XML, JSON, protobuf, and more.
37
+ email: greg.lu@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - MIT-LICENSE
44
+ - README.textile
45
+ files:
46
+ - History.txt
47
+ - MIT-LICENSE
48
+ - README.textile
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/hbase.rb
52
+ - lib/hbase/client.rb
53
+ - lib/hbase/exception.rb
54
+ - lib/hbase/model.rb
55
+ - lib/hbase/model/column.rb
56
+ - lib/hbase/model/column_descriptor.rb
57
+ - lib/hbase/model/region_descriptor.rb
58
+ - lib/hbase/model/row.rb
59
+ - lib/hbase/model/scanner.rb
60
+ - lib/hbase/model/table_descriptor.rb
61
+ - lib/hbase/operation/meta_operation.rb
62
+ - lib/hbase/operation/row_operation.rb
63
+ - lib/hbase/operation/scanner_operation.rb
64
+ - lib/hbase/operation/table_operation.rb
65
+ - lib/hbase/request.rb
66
+ - lib/hbase/request/basic_request.rb
67
+ - lib/hbase/request/meta_request.rb
68
+ - lib/hbase/request/row_request.rb
69
+ - lib/hbase/request/scanner_request.rb
70
+ - lib/hbase/request/table_request.rb
71
+ - lib/hbase/response.rb
72
+ - lib/hbase/response/basic_response.rb
73
+ - lib/hbase/response/meta_response.rb
74
+ - lib/hbase/response/row_response.rb
75
+ - lib/hbase/response/scanner_response.rb
76
+ - lib/hbase/response/table_response.rb
77
+ - spec/hbase/model/column_descriptor_spec.rb
78
+ - spec/hbase/model/column_spec.rb
79
+ - spec/hbase/model/region_descriptor_spec.rb
80
+ - spec/hbase/model/row_spec.rb
81
+ - spec/hbase/model/scanner.rb
82
+ - spec/hbase/model/table_descriptor_spec.rb
83
+ - spec/hbase/operation/meta_operation_spec.rb
84
+ - spec/hbase/operation/row_operation_spec.rb
85
+ - spec/hbase/operation/scanner_operation_spec.rb
86
+ - spec/hbase/operation/table_operation_spec.rb
87
+ - spec/hbase/record_spec.rb
88
+ - spec/hbase/request/meta_request_spec.rb
89
+ - spec/hbase/request/row_request_spec.rb
90
+ - spec/hbase/request/scanner_request_spec.rb
91
+ - spec/hbase/request/table_request_spec.rb
92
+ - spec/hbase/response/meta_response_spec.rb
93
+ - spec/hbase/response/row_response_spec.rb
94
+ - spec/hbase/response/scanner_response_spec.rb
95
+ - spec/hbase/response/table_response_spec.rb
96
+ - spec/spec.opts
97
+ - spec/spec_helper.rb
98
+ - tasks/rspec.rake
99
+ has_rdoc: true
100
+ homepage: http://github.com/greglu/hbase-ruby
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --charset=UTF-8
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.5
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: A pure ruby client for HBase using the Stargate interface.
127
+ test_files:
128
+ - spec/hbase/request/row_request_spec.rb
129
+ - spec/hbase/request/table_request_spec.rb
130
+ - spec/hbase/request/meta_request_spec.rb
131
+ - spec/hbase/request/scanner_request_spec.rb
132
+ - spec/hbase/model/scanner.rb
133
+ - spec/hbase/model/column_spec.rb
134
+ - spec/hbase/model/row_spec.rb
135
+ - spec/hbase/model/column_descriptor_spec.rb
136
+ - spec/hbase/model/region_descriptor_spec.rb
137
+ - spec/hbase/model/table_descriptor_spec.rb
138
+ - spec/hbase/operation/row_operation_spec.rb
139
+ - spec/hbase/operation/meta_operation_spec.rb
140
+ - spec/hbase/operation/scanner_operation_spec.rb
141
+ - spec/hbase/operation/table_operation_spec.rb
142
+ - spec/hbase/record_spec.rb
143
+ - spec/hbase/response/scanner_response_spec.rb
144
+ - spec/hbase/response/meta_response_spec.rb
145
+ - spec/hbase/response/table_response_spec.rb
146
+ - spec/hbase/response/row_response_spec.rb
147
+ - spec/spec_helper.rb