Skip to content

Instantly share code, notes, and snippets.

@spidaman
Created December 1, 2009 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spidaman/246032 to your computer and use it in GitHub Desktop.
Save spidaman/246032 to your computer and use it in GitHub Desktop.
# see http://ole-martin.net/hbase-tutorial-for-beginners/
require 'java'
require 'hbase-0.20.2.jar'
require 'lib/zookeeper-3.2.1.jar'
require 'lib/commons-logging-1.0.4.jar'
require 'lib/commons-logging-api-1.0.4.jar'
require 'lib/hadoop-0.20.1-hdfs127-core.jar'
require 'lib/log4j-1.2.15.jar'
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.io.RowResult
def from_bytes(b)
String::from_java_bytes(b)
end
def retrieve_post(post_id)
table = HTable.new(HBaseConfiguration.new, 'blogposts')
result = table.get_row(post_id)
rv = {}
result.key_set().each { |key|
rv[from_bytes(key)] = from_bytes(result.get(key).get_value)
}
rv
end
retrieve_post('post1').entries.each { |k,v|
puts "#{k} => #{v}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment