Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.0.1
Fetching contributors…

Cannot retrieve contributors at this time

file 109 lines (91 sloc) 3.143 kb

Thrift Hive - Hive client with multi versions support and a streaming API.

The project export the Hive API using Apache Thrift RPC system. It support multiple versions and a readable stream API.

Hive Client

We've added a function hive.createClient to simplify coding. However, you are free to use the raw Thrift API. The client take an options object as its argument andexpose an execute and a query methods.

Available options

  • version
    default to '0.7.1-cdh3u2'
  • server
    default to ''
  • port
    default to 10000
  • timeout
    default to 1000 milliseconds

Available API

  • client
    A reference to the thrift client returned by thrift.createClient
  • connection
    A reference to the thrift connection returned by thrift.createConnection
  • end([callback])
    Close the Thrift connection
  • execute(query, [callback])
    Execute a query
  • query(query, [size])
    Execute a query and return its results as an array of arrays (rows and columns). The size argument is optional and indicate the number of row to return on each fetch.
    hive = require 'thrift-hive'
    # Client connection
    client = hive.createClient
        version: '0.7.1-cdh3u2'
        server: ''
        port: 10000
        timeout: 1000
    # Execute
    client.execute 'USE default', (err) ->
        console.log err.message if err

Hive Query

The client.query function return an object similar to the Readable Stream API. At the moment, we have only implemented pause and resume.

Raw versus sugar API

Here's an exemple using the raw API

    var assert     = require('assert');
    var thrift     = require('thrift');
    var transport  = require('thrift/lib/thrift/transport');
    var ThriftHive = require('../lib/0.7.1-cdh3u2/ThriftHive');
    // Client connection
    var options = {transport: transport.TBufferedTransport, timeout: 1000};
    var connection = thrift.createConnection('', 10000, options);
    var client = thrift.createClient(ThriftHive, connection);
    // Execute query
    client.execute('show databases', function(err){
        client.fetchAll(function(err, databases){

Here's an exemple using our sugar API

    var assert = require('assert');
    var hive = require('thrift-hive');
    // Client connection
    var client = hive.createClient({
        version: '0.7.1-cdh3u2',
        server: '',
        port: 10000,
        timeout: 1000
    // Execute query
    client.query('show databases')
    .on('row', function(database){
    .on('end', function(err){
Something went wrong with that request. Please try again.