Skip to content
Browse files

Expose connection and end in client; Add samples

  • Loading branch information...
1 parent a3c6484 commit 278ba963d04c3324b8d844cd7bc73ac91d73734d @wdavidw committed Nov 3, 2011
Showing with 104 additions and 4 deletions.
  1. +41 −4 README.md
  2. +4 −0 index.js
  3. +19 −0 lib/hive.coffee
  4. +20 −0 samples/connect_raw/sample.js
  5. +20 −0 samples/connect_sugar/sample.js
View
45 README.md
@@ -1,16 +1,53 @@
# Thrift Hive - Hive client using the Apache Thrift RPC system.
-The project export the Hive API throught Thrift.
+The project export the Hive API throught Thrift. Multiple versions of hive are
+supported.
-## Quick Example
+The only function added to the generated Thrift code is `hive.createClient`. It
+take an `options` object as its argument and return the result of
+`thrift.createClient`. This client object is enriched with a `connection`
+property to expose the object returned by `thrift.createConnection` as well as
+with the `end` function as a shortcut to `connection.end`.
+
+## Hive connection: suggar example
```javascript
var hive = require('thrift-hive');
- // Initialization
- var client = hive.createClient('0.7.1-cdh3u2',{
+ // Client connection
+ var client = hive.createClient({
+ version: '0.7.1-cdh3u2'
server: '127.0.0.1'
port: 10000
timeout: 1000
});
+ // Execute with fetchAll
+ client.execute('show databases', function(err){
+ assert.ifError(err);
+ client.fetchAll(function(err, databases){
+ assert.ifError(err);
+ console.log(databases);
+ client.end();
+ });
+ });
+```
+## Hive connection: raw example
+
+```javascript
+ var thrift = require('thrift');
+ var transport = require('thrift/transport');
+ var ThriftHive = require('thrift-hive/0.7.1-cdh3u2/ThriftHive');
+ // Client connection
+ var options = {transport: transport.TBufferedTransport, timeout: 1000};
+ var connection = thrift.createConnection('127.0.0.1', 10000, options);
+ var client = thrift.createClient(ThriftHive, connection);
+ // Execute with fetchAll
+ client.execute('show databases', function(err){
+ assert.ifError(err);
+ client.fetchAll(function(err, databases){
+ assert.ifError(err);
+ console.log(databases);
+ connection.end();
+ });
+ });
```
View
4 index.js
@@ -0,0 +1,4 @@
+
+require('coffee-script');
+
+module.exports = require('./lib/hive');
View
19 lib/hive.coffee
@@ -0,0 +1,19 @@
+
+thrift = require 'thrift'
+transport = require 'thrift/lib/thrift/transport'
+
+#module.exports = class Client
+ #
+
+module.exports.createClient = (options = {}) ->
+ options.version ?= '0.7.1-cdh3u2'
+ options.server ?= '127.0.0.1'
+ options.port ?= 10000
+ options.timeout ?= 1000
+ options.transport ?= transport.TBufferedTransport
+ connection = thrift.createConnection options.server, options.port, options
+ client = thrift.createClient require("./#{options.version}/ThriftHive"), connection
+ client.connection = connection
+ client.end = connection.end
+ client
+
View
20 samples/connect_raw/sample.js
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+
+ // Client conenction
+ 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('127.0.0.1', 10000, options);
+ var client = thrift.createClient(ThriftHive, connection);
+ // Execute with fetchAll
+ client.execute('show databases', function(err){
+ assert.ifError(err);
+ client.fetchAll(function(err, databases){
+ assert.ifError(err);
+ console.log(databases);
+ connection.end();
+ });
+ });
View
20 samples/connect_sugar/sample.js
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+
+ var assert = require('assert');
+ var hive = require('../../');
+ // Client connection
+ var client = hive.createClient({
+ version: '0.7.1-cdh3u2',
+ server: '127.0.0.1',
+ port: 10000,
+ timeout: 1000
+ });
+ // Execute with fetchAll
+ client.execute('show databases', function(err){
+ assert.ifError(err);
+ client.fetchAll(function(err, databases){
+ assert.ifError(err);
+ console.log(databases);
+ client.end();
+ });
+ });

0 comments on commit 278ba96

Please sign in to comment.
Something went wrong with that request. Please try again.