Permalink
Browse files

fetching results in batch

  • Loading branch information...
1 parent 88506fc commit a7ddfc862a65446eda62eda2f757da26f609f5c7 @Jae Jae committed Jul 12, 2011
Showing with 25 additions and 3 deletions.
  1. +6 −3 examples/test.js
  2. +19 −0 node-hive.js
View
@@ -4,10 +4,13 @@ hive.fetch("SELECT * FROM weather_data where dated = '2011-07-01' limit 10", fun
console.log("SELECT * FROM weather_data where dated = '2011-07-01' limit 10");
console.log(data);
});
-hive.fetch("SELECT * FROM weather_data where dated = '2011-07-02' limit 10", function(err, data) {
- console.log("SELECT * FROM weather_data where dated = '2011-07-02' limit 10");
- console.log(data)
+
+var i = 1;
+hive.fetchInBatch(100, "SELECT * FROM weather_data where dated = '2011-07-02' limit 1002", function(err, data) {
+ console.log("SELECT * FROM weather_data where dated = '2011-07-02'");
+ console.log(i++ + "th data:", data);
});
+
hive.execute("DESCRIBE weather_data", function(err, data) {
console.log("DESCRIBE weather_data");
console.log(data);
View
@@ -25,6 +25,25 @@ var hiveClient = function(futureConnection) {
})
},
+ fetchInBatch: function(batchSize, query, cb) {
+ futureConnection(function(client, connection) {
+ client.execute(query, function(err){
+ if (err) return cb(true, err);
+ var fetchBatch = function() {
+ client.fetchN(batchSize, function(err, data){
+ if (err) return cb(true, err);
+ if(data.length > 0) {
+ cb(null, data);
+ process.nextTick(fetchBatch);
+ }
+ else connection.end();
+ });
+ };
+ fetchBatch();
+ });
+ })
+ },
+
execute: function(query, cb){
futureConnection(function(client, connection) {
client.execute(query, function(err){

0 comments on commit a7ddfc8

Please sign in to comment.