Skip to content

p5k6/rbhive

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RBHive – Ruby thrift lib for executing Hive queries

A simple library to execute Hive queries against the Hive thrift server. Also supports PLAIN SASL connection to HiveServer2 thrift server.

Example of fetching some results

HiveServer:

require 'rubygems'
require 'rbhive'

RBHive.connect('hive.server.address') do |connection|
  connection.fetch 'SELECT city, country FROM cities'
end
 [{:city => "London", :country => "UK"}, {:city => "Mumbai", :country => "India"}, {:city => "New York", :country => "USA"}]

HiveServer2:

RBHive.tcli_connect('hive.server2.address', 'hive.server2.port', 'hive.server2.connection_options_hash') do |connection|
  connection.fetch 'SELECT city, country FROM cities'
end
 [{:city => "London", :country => "UK"}, {:city => "Mumbai", :country => "India"}, {:city => "New York", :country => "USA"}]

where connection_options_hash = { username: ‘user’, password: ‘pass’} or an empty(nil) is accepted.

There are plans to implement LDAP/KERBEROS authentication as well. Only NONE supported currently.

Example of executing a query

require 'rubygems'
require 'rbhive'

RBHive.connect('hive.server.address') do |connection|
  connection.execute 'DROP TABLE cities'
end
 nil

Example of how to create and/or drop tables

require 'rubygems'
require 'rbhive'

table = TableSchema.new('person', 'List of people that owe me money') do
  column 'name', :string, 'Full name of debtor'
  column 'address', :string, 'Address of debtor'
  column 'amount', :float, 'The amount of money borrowed'

  partition 'dated', :string, 'The date money was given'
  partition 'country', :string, 'The country the person resides in'
end

RBHive.connect('hive.server.address') do |connection|
  connection.create_table(table)
  connection.drop_table(table)
end

Example of how to modify table schema

require 'rubygems'
require 'rbhive'

table = TableSchema.new('person', 'List of people that owe me money') do
  column 'name', :string, 'Full name of debtor'
  column 'address', :string, 'Address of debtor'
  column 'amount', :float, 'The amount of money borrowed'
  column 'new_amount', :float, 'The new amount this person somehow convinced me to give them'

  partition 'dated', :string, 'The date money was given'
  partition 'country', :string, 'The country the person resides in'
end

RBHive.connect('hive.server.address') do |connection|
  connection.replace_columns(table)
end

About

Ruby gem for querying hive databases.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%