Skip to content

Commit

Permalink
callback function to notify that fetchInBatch is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Jae committed Jul 13, 2011
1 parent a890e5d commit ca3e4a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions examples/test.js
Expand Up @@ -11,6 +11,8 @@ var i = 1;
hive.fetchInBatch(5, "SELECT * FROM weather_data where dated = '2011-07-02' limit 12", function(err, data) { hive.fetchInBatch(5, "SELECT * FROM weather_data where dated = '2011-07-02' limit 12", function(err, data) {
console.log("SELECT * FROM weather_data where dated = '2011-07-02' limit 12"); console.log("SELECT * FROM weather_data where dated = '2011-07-02' limit 12");
console.log(i++ + "th data:", data.toTSV()); console.log(i++ + "th data:", data.toTSV());
}, function() {
console.log("fetchInBatch completed")
}); });


hive.execute("DESCRIBE weather_data", function(err, data) { hive.execute("DESCRIBE weather_data", function(err, data) {
Expand Down
7 changes: 4 additions & 3 deletions node-hive.js
Expand Up @@ -70,17 +70,18 @@ var hiveClient = function(config) {
}); });
}, },


fetchInBatch: function(batchSize, query, onCompletion) { fetchInBatch: function(batchSize, query, onBatchCompletion, onCompletion) {
connect(onCompletion, function(client) { connect(onBatchCompletion, function(client) {
client.execute(query, function() { client.execute(query, function() {
client.getSchema(function(schema) { client.getSchema(function(schema) {
var fetchBatch = function() { var fetchBatch = function() {
client.fetchN(batchSize, function(data) { client.fetchN(batchSize, function(data) {
if(data.length > 0) { if(data.length > 0) {
onCompletion(null, ResultSet.create(data, schema)); onBatchCompletion(null, ResultSet.create(data, schema));
process.nextTick(fetchBatch); process.nextTick(fetchBatch);
} else { } else {
client.closeConnection(); client.closeConnection();
if (onCompletion) onCompletion(null, null);
} }
}); });
}; };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"contributors":["Jae Lee <jlee@yetitrails.com>", "Antonio Terreno <antonio.terreno@gmail.com>", "Andy Kent"], "contributors":["Jae Lee <jlee@yetitrails.com>", "Antonio Terreno <antonio.terreno@gmail.com>", "Andy Kent"],
"name": "node-hive", "name": "node-hive",
"description": "Node Hive Client Library", "description": "Node Hive Client Library",
"version": "0.0.4", "version": "0.0.5",
"homepage": "https://github.com/forward/node-hive", "homepage": "https://github.com/forward/node-hive",
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down

0 comments on commit ca3e4a9

Please sign in to comment.