Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (104 sloc) 3.53 KB

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

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


    npm install thrift-hive

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 implement the EventEmitter API.

The following events are emitted:

  • row
  • row-first
  • row-last
  • error
  • end

The client.query functionreturn a Node Readable Stream. It is possible to pipe the data into a Writable Stream but it is your responsibility to emit the data event, usually inside the row event.

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.