Permalink
Browse files

Merge pull request #1 from simplymeasured/master

Adding HBase filtering to scanners
  • Loading branch information...
2 parents 548659f + a288df7 commit eac9f86685504f40f52e749e10f56b653ba39b18 @bmuller committed Jun 1, 2012
Showing with 310 additions and 13 deletions.
  1. +2 −0 .rvmrc
  2. +6 −0 Gemfile
  3. +8 −0 Gemfile.lock
  4. +6 −2 README.rdoc
  5. +3 −0 Rakefile
  6. +6 −3 hbaserb.gemspec
  7. +4 −4 lib/hbaserb/table.rb
  8. +1 −1 lib/hbaserb/version.rb
  9. +272 −1 lib/thrift/hbase.rb
  10. +1 −1 lib/thrift/hbase_constants.rb
  11. +1 −1 lib/thrift/hbase_types.rb
View
2 .rvmrc
@@ -0,0 +1,2 @@
+rvm use 1.8.7-p302@hbaserb --create
+bundle check
View
6 Gemfile
@@ -0,0 +1,6 @@
+# A sample Gemfile
+source "http://rubygems.org"
+
+# gem "rails"
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
8 Gemfile.lock
@@ -0,0 +1,8 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
View
8 README.rdoc
@@ -1,6 +1,6 @@
= hbaserb -- HBase Thrift interface for Ruby
-A Ruby thrift lib for interfacing with Hadoop's HBase
+A Ruby thrift lib for interfacing with Hadoop's HBase 0.92.0
To install:
gem install hbaserb
@@ -17,6 +17,9 @@ To install:
# insert some data
table.mutate_row 'myrow', {'colfamone:myvalue' => 'awesome value'}
+ # delete some data
+ table.mutate_row 'myrow', {'colfamone:myvalue' => nil}
+
# get it
puts t.get('myrow', 'colfamone:myvalue').first.value
@@ -28,6 +31,7 @@ To install:
puts t.get('myrow', 'colfamtwo:counter').first.to_i64
# make a scanner
- s = t.create_scanner('myrow', 'colfamnone') { |row|
+ s = t.create_scanner('my-start-row', 'my-end-row', 'colfamnone') { |row|
puts "Columns: #{row.columns.keys}"
}
+
View
3 Rakefile
@@ -1,5 +1,8 @@
require 'rubygems'
require 'bundler'
+
+require 'rake'
+
require 'rake/testtask'
require 'rdoc/task'
View
9 hbaserb.gemspec
@@ -1,6 +1,5 @@
$:.push File.expand_path("../lib", __FILE__)
require "hbaserb/version"
-require "rake"
require "date"
Gem::Specification.new do |s|
@@ -11,9 +10,13 @@ Gem::Specification.new do |s|
s.description = "Ruby HBase library using Thrift"
s.summary = "Simple lib for interfaceing with HBase via Ruby and Thrift."
s.email = "brian.muller@livingsocial.com"
- s.files = FileList["lib/**/*", "[A-Z]*", "Rakefile", "docs/**/*"]
- s.homepage = "http://github.com/bmuller/hbaserb"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+
+ s.homepage = "http://github.com/bmuller/hbaserb"
s.add_dependency('thrift', '>= 0.4.0')
s.rubyforge_project = "hbaserb"
end
View
8 lib/hbaserb/table.rb
@@ -46,17 +46,17 @@ def atomic_increment(row, column, value=1)
end
# pass in no params to scan whole table
- def create_scanner(row=nil, *columns, &block)
- row ||= ""
+ def create_scanner(start_row=nil, end_row=nil, *columns, &block)
columns = (columns.length > 0) ? columns : column_families.keys
- sid = call :scannerOpen, row.to_s, columns
+
+ sid = call :scannerOpenWithStop, start_row.to_s, end_row.to_s, columns
Scanner.new @client, sid, &block
end
# mutations is a key / value pair to insert / update for the given row
# the keys are in the form "family:column"
def mutate_row(row, mutations)
- mutations = mutations.map { |k,v| Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => k, :value => v) }
+ mutations = mutations.map { |k,v| Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => k, :value => v, :isDelete => v.nil?) }
call :mutateRow, row, mutations
end
View
2 lib/hbaserb/version.rb
@@ -1,3 +1,3 @@
module HBaseRB
- VERSION = "0.0.4"
+ VERSION = "0.0.5"
end
View
273 lib/thrift/hbase.rb
@@ -1,5 +1,5 @@
#
-# Autogenerated by Thrift
+# Autogenerated by Thrift Compiler (0.8.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
@@ -283,6 +283,70 @@ def recv_getRowWithColumnsTs()
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getRowWithColumnsTs failed: unknown result')
end
+ def getRows(tableName, rows)
+ send_getRows(tableName, rows)
+ return recv_getRows()
+ end
+
+ def send_getRows(tableName, rows)
+ send_message('getRows', GetRows_args, :tableName => tableName, :rows => rows)
+ end
+
+ def recv_getRows()
+ result = receive_message(GetRows_result)
+ return result.success unless result.success.nil?
+ raise result.io unless result.io.nil?
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getRows failed: unknown result')
+ end
+
+ def getRowsWithColumns(tableName, rows, columns)
+ send_getRowsWithColumns(tableName, rows, columns)
+ return recv_getRowsWithColumns()
+ end
+
+ def send_getRowsWithColumns(tableName, rows, columns)
+ send_message('getRowsWithColumns', GetRowsWithColumns_args, :tableName => tableName, :rows => rows, :columns => columns)
+ end
+
+ def recv_getRowsWithColumns()
+ result = receive_message(GetRowsWithColumns_result)
+ return result.success unless result.success.nil?
+ raise result.io unless result.io.nil?
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getRowsWithColumns failed: unknown result')
+ end
+
+ def getRowsTs(tableName, rows, timestamp)
+ send_getRowsTs(tableName, rows, timestamp)
+ return recv_getRowsTs()
+ end
+
+ def send_getRowsTs(tableName, rows, timestamp)
+ send_message('getRowsTs', GetRowsTs_args, :tableName => tableName, :rows => rows, :timestamp => timestamp)
+ end
+
+ def recv_getRowsTs()
+ result = receive_message(GetRowsTs_result)
+ return result.success unless result.success.nil?
+ raise result.io unless result.io.nil?
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getRowsTs failed: unknown result')
+ end
+
+ def getRowsWithColumnsTs(tableName, rows, columns, timestamp)
+ send_getRowsWithColumnsTs(tableName, rows, columns, timestamp)
+ return recv_getRowsWithColumnsTs()
+ end
+
+ def send_getRowsWithColumnsTs(tableName, rows, columns, timestamp)
+ send_message('getRowsWithColumnsTs', GetRowsWithColumnsTs_args, :tableName => tableName, :rows => rows, :columns => columns, :timestamp => timestamp)
+ end
+
+ def recv_getRowsWithColumnsTs()
+ result = receive_message(GetRowsWithColumnsTs_result)
+ return result.success unless result.success.nil?
+ raise result.io unless result.io.nil?
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getRowsWithColumnsTs failed: unknown result')
+ end
+
def mutateRow(tableName, row, mutations)
send_mutateRow(tableName, row, mutations)
recv_mutateRow()
@@ -750,6 +814,50 @@ def process_getRowWithColumnsTs(seqid, iprot, oprot)
write_result(result, oprot, 'getRowWithColumnsTs', seqid)
end
+ def process_getRows(seqid, iprot, oprot)
+ args = read_args(iprot, GetRows_args)
+ result = GetRows_result.new()
+ begin
+ result.success = @handler.getRows(args.tableName, args.rows)
+ rescue Apache::Hadoop::Hbase::Thrift::IOError => io
+ result.io = io
+ end
+ write_result(result, oprot, 'getRows', seqid)
+ end
+
+ def process_getRowsWithColumns(seqid, iprot, oprot)
+ args = read_args(iprot, GetRowsWithColumns_args)
+ result = GetRowsWithColumns_result.new()
+ begin
+ result.success = @handler.getRowsWithColumns(args.tableName, args.rows, args.columns)
+ rescue Apache::Hadoop::Hbase::Thrift::IOError => io
+ result.io = io
+ end
+ write_result(result, oprot, 'getRowsWithColumns', seqid)
+ end
+
+ def process_getRowsTs(seqid, iprot, oprot)
+ args = read_args(iprot, GetRowsTs_args)
+ result = GetRowsTs_result.new()
+ begin
+ result.success = @handler.getRowsTs(args.tableName, args.rows, args.timestamp)
+ rescue Apache::Hadoop::Hbase::Thrift::IOError => io
+ result.io = io
+ end
+ write_result(result, oprot, 'getRowsTs', seqid)
+ end
+
+ def process_getRowsWithColumnsTs(seqid, iprot, oprot)
+ args = read_args(iprot, GetRowsWithColumnsTs_args)
+ result = GetRowsWithColumnsTs_result.new()
+ begin
+ result.success = @handler.getRowsWithColumnsTs(args.tableName, args.rows, args.columns, args.timestamp)
+ rescue Apache::Hadoop::Hbase::Thrift::IOError => io
+ result.io = io
+ end
+ write_result(result, oprot, 'getRowsWithColumnsTs', seqid)
+ end
+
def process_mutateRow(seqid, iprot, oprot)
args = read_args(iprot, MutateRow_args)
result = MutateRow_result.new()
@@ -1593,6 +1701,169 @@ def validate
::Thrift::Struct.generate_accessors self
end
+ class GetRows_args
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ TABLENAME = 1
+ ROWS = 2
+
+ FIELDS = {
+ # name of table
+ TABLENAME => {:type => ::Thrift::Types::STRING, :name => 'tableName', :binary => true},
+ # row keys
+ ROWS => {:type => ::Thrift::Types::LIST, :name => 'rows', :element => {:type => ::Thrift::Types::STRING, :binary => true}}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRows_result
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ SUCCESS = 0
+ IO = 1
+
+ FIELDS = {
+ SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TRowResult}},
+ IO => {:type => ::Thrift::Types::STRUCT, :name => 'io', :class => Apache::Hadoop::Hbase::Thrift::IOError}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsWithColumns_args
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ TABLENAME = 1
+ ROWS = 2
+ COLUMNS = 3
+
+ FIELDS = {
+ # name of table
+ TABLENAME => {:type => ::Thrift::Types::STRING, :name => 'tableName', :binary => true},
+ # row keys
+ ROWS => {:type => ::Thrift::Types::LIST, :name => 'rows', :element => {:type => ::Thrift::Types::STRING, :binary => true}},
+ # List of columns to return, null for all columns
+ COLUMNS => {:type => ::Thrift::Types::LIST, :name => 'columns', :element => {:type => ::Thrift::Types::STRING, :binary => true}}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsWithColumns_result
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ SUCCESS = 0
+ IO = 1
+
+ FIELDS = {
+ SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TRowResult}},
+ IO => {:type => ::Thrift::Types::STRUCT, :name => 'io', :class => Apache::Hadoop::Hbase::Thrift::IOError}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsTs_args
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ TABLENAME = 1
+ ROWS = 2
+ TIMESTAMP = 3
+
+ FIELDS = {
+ # name of the table
+ TABLENAME => {:type => ::Thrift::Types::STRING, :name => 'tableName', :binary => true},
+ # row keys
+ ROWS => {:type => ::Thrift::Types::LIST, :name => 'rows', :element => {:type => ::Thrift::Types::STRING, :binary => true}},
+ # timestamp
+ TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsTs_result
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ SUCCESS = 0
+ IO = 1
+
+ FIELDS = {
+ SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TRowResult}},
+ IO => {:type => ::Thrift::Types::STRUCT, :name => 'io', :class => Apache::Hadoop::Hbase::Thrift::IOError}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsWithColumnsTs_args
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ TABLENAME = 1
+ ROWS = 2
+ COLUMNS = 3
+ TIMESTAMP = 4
+
+ FIELDS = {
+ # name of table
+ TABLENAME => {:type => ::Thrift::Types::STRING, :name => 'tableName', :binary => true},
+ # row keys
+ ROWS => {:type => ::Thrift::Types::LIST, :name => 'rows', :element => {:type => ::Thrift::Types::STRING, :binary => true}},
+ # List of columns to return, null for all columns
+ COLUMNS => {:type => ::Thrift::Types::LIST, :name => 'columns', :element => {:type => ::Thrift::Types::STRING, :binary => true}},
+ TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
+ class GetRowsWithColumnsTs_result
+ include ::Thrift::Struct, ::Thrift::Struct_Union
+ SUCCESS = 0
+ IO = 1
+
+ FIELDS = {
+ SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TRowResult}},
+ IO => {:type => ::Thrift::Types::STRUCT, :name => 'io', :class => Apache::Hadoop::Hbase::Thrift::IOError}
+ }
+
+ def struct_fields; FIELDS; end
+
+ def validate
+ end
+
+ ::Thrift::Struct.generate_accessors self
+ end
+
class MutateRow_args
include ::Thrift::Struct, ::Thrift::Struct_Union
TABLENAME = 1
View
2 lib/thrift/hbase_constants.rb
@@ -1,5 +1,5 @@
#
-# Autogenerated by Thrift
+# Autogenerated by Thrift Compiler (0.8.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
View
2 lib/thrift/hbase_types.rb
@@ -1,5 +1,5 @@
#
-# Autogenerated by Thrift
+# Autogenerated by Thrift Compiler (0.8.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

0 comments on commit eac9f86

Please sign in to comment.