Skip to content

Latest commit

 

History

History
88 lines (59 loc) · 1.72 KB

README.md

File metadata and controls

88 lines (59 loc) · 1.72 KB

HBase For Ruby Made Easy

To use HBase with Apache Thrift, you might have to manually generate Ruby code from generic *.thrift files.

This gem tries to alleviate that slight annoyance by packaging everything you need to communicate with HBase.

Installation

Bundler

Add to Gemfile and run bundle install:

gem 'hbase-rb'

Without Bundler

Install the gem:

gem install hbase-rb

Require it explicitly in your scripts:

require "rubygems"
require "hbase-rb"

Versioning

The version of the gem matches the version of HBase the interface was generated against.

For instance, when using HBase 0.90.4:

gem 'hbase-rb', '0.90.4'

Usage

This library simply exposes the generated Ruby code from Thrift. Therefore it is not necessarily very idiomatic Ruby.

For example:

socket    = Thrift::Socket.new('localhost', 9090)

transport = Thrift::BufferedTransport.new(socket)
transport.open

protocol  = Thrift::BinaryProtocol.new(transport)
client    = HBase::Client.new(protocol)

puts client.getTableNames

Writing Rows

# Assuming a table "mytable" and a column family "c"
client.mutateRow("mytable", "abc123", [HBase::Mutation.new(column: "c:foo", value: "bar")])

Reading Rows

# Assuming a table "mytable" and a column family "c"
results = client.getRow("mytable", "abc123")
if result = results.first
  result.columns.each do |key, cell|
    puts "#{key}: #{cell.value}"
  end
end

API Reference