Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created September 30, 2009 17:17
Show Gist options
  • Save kevinpet/198256 to your computer and use it in GitHub Desktop.
Save kevinpet/198256 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'hbase'
transport = Thrift::BufferedTransport.new(Thrift::Socket.new('127.0.0.1', 9090))
protocol = Thrift::BinaryProtocol.new(transport)
client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
transport.open
unless ARGV.length >= 2
STDERR.puts "usage: query.rb <table name> <index name> [<column>]"
exit 1
end
table = ARGV[0]
index = "#{table}-#{ARGV[1]}"
column = ARGV[2] || 'content:title'
unless client.isTableEnabled table
STDERR.puts "primary table '#{table}' not enabled"
exit 1
end
unless client.isTableEnabled index
STDERR.puts "index table '#{index}' not enabled"
exit 1
end
puts <<_INFO_
Table '#{table}' and index '#{index}' are enabled, expecting to find
the the item searched for in '__INDEX__:ROW' and value of interest
in '#{column}'
_INFO_
STDIN.each do |id|
id.strip!
row_keys = client.get index, id, '__INDEX__:ROW'
row_key_cell = row_keys[0]
if row_key_cell
row_key = row_key_cell.value
puts "Found row key #{row_key}"
value = client.get table, row_key, column
puts "Found item #{value[0].value}"
else
puts "unable to find '#{id}' in index"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment