Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bigquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"test": "npm run system-test"
},
"dependencies": {
"@google-cloud/bigquery": "0.9.3",
"@google-cloud/storage": "1.1.0",
"yargs": "7.1.0"
"@google-cloud/bigquery": "0.9.6",
"@google-cloud/storage": "1.2.0",
"yargs": "8.0.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.14",
"ava": "0.19.1",
"proxyquire": "1.7.11",
"sinon": "2.1.0",
"uuid": "3.0.1"
"@google-cloud/nodejs-repo-tools": "1.4.15",
"ava": "0.20.0",
"proxyquire": "1.8.0",
"sinon": "2.3.6",
"uuid": "3.1.0"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
Expand Down
11 changes: 11 additions & 0 deletions bigquery/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ function asyncQuery (sqlQuery, projectId) {
console.log(`Job ${job.id} started.`);
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
})
.then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
})
.then(() => {
console.log(`Job ${job.id} completed.`);
return job.getQueryResults();
Expand Down
2 changes: 1 addition & 1 deletion bigquery/resources/data.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Gandalf, 2000, 140.0, 1
Gandalf,2000,140.0,TRUE
13 changes: 9 additions & 4 deletions bigquery/system-test/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ corpus: antonyandcleopatra
unique_words: 4582`;

const sqlQuery = `SELECT * FROM publicdata.samples.natality LIMIT 5;`;

test.before(tools.checkCredentials);
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);
const badQuery = `SELECT * FROM INVALID`;

test(`should query shakespeare`, async (t) => {
const output = await tools.runAsync(`${cmd} shakespeare`, cwd);
Expand All @@ -66,3 +63,11 @@ test(`should run an async query`, async (t) => {
t.true(output.includes(`Rows:`));
t.true(output.includes(`source_year`));
});

test.skip(`should handle sync query errors`, async (t) => {
await t.throws(tools.runAsync(`${cmd} sync "${badQuery}"`, cwd), /ERROR:/);
});

test.skip(`should handle async query errors`, async (t) => {
await t.throws(tools.runAsync(`${cmd} async "${badQuery}"`, cwd), /ERROR:/);
});
46 changes: 45 additions & 1 deletion bigquery/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,20 @@ function copyTable (srcDatasetId, srcTableId, destDatasetId, destTableId, projec
.then((results) => {
job = results[0];
console.log(`Job ${job.id} started.`);

// Wait for the job to finish
return job.promise();
})
.then(() => {
.then((results) => {
// Get the job's status
return job.getMetadata();
}).then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
}).then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch((err) => {
Expand Down Expand Up @@ -230,9 +241,20 @@ function importLocalFile (datasetId, tableId, filename, projectId) {
.then((results) => {
job = results[0];
console.log(`Job ${job.id} started.`);

// Wait for the job to finish
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
}).then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
}).then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch((err) => {
Expand Down Expand Up @@ -281,9 +303,20 @@ function importFileFromGCS (datasetId, tableId, bucketName, filename, projectId)
.then((results) => {
job = results[0];
console.log(`Job ${job.id} started.`);

// Wait for the job to finish
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
}).then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
}).then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch((err) => {
Expand Down Expand Up @@ -332,9 +365,20 @@ function exportTableToGCS (datasetId, tableId, bucketName, filename, projectId)
.then((results) => {
job = results[0];
console.log(`Job ${job.id} started.`);

// Wait for the job to finish
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
}).then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
}).then(() => {
console.log(`Job ${job.id} completed.`);
})
.catch((err) => {
Expand Down