-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add browsing data sample #201
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,20 +63,17 @@ describe('bigquery:tables', function () { | |
}); | ||
|
||
after(function (done) { | ||
// Delete srcDataset | ||
bigquery.dataset(srcDataset).delete({ force: true }, function () { | ||
// Delete destDataset | ||
bigquery.dataset(destDataset).delete({ force: true }, function () { | ||
// Delete files | ||
storage.bucket(options.bucket).deleteFiles({ force: true }, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// Delete bucket | ||
setTimeout(function () { | ||
storage.bucket(options.bucket).delete(done); | ||
}, 2000); | ||
}); | ||
// Delete testing dataset/table | ||
bigquery.dataset(options.dataset).delete({ force: true }, function () { | ||
// Delete files | ||
storage.bucket(options.bucket).deleteFiles({ force: true }, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// Delete bucket | ||
setTimeout(function () { | ||
storage.bucket(options.bucket).delete(done); | ||
}, 2000); | ||
}); | ||
}); | ||
}); | ||
|
@@ -191,6 +188,20 @@ describe('bigquery:tables', function () { | |
}); | ||
}); | ||
|
||
describe('browseRows', function () { | ||
it('should display rows in a table', function (done) { | ||
program.browseRows(options.dataset, options.table, function (err, rows) { | ||
assert.equal(err, null); | ||
assert.notEqual(rows, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're asserting that |
||
assert.equal(Array.isArray(rows), true); | ||
assert.equal(rows.length > 0, true); | ||
assert.equal(console.log.calledOnce, true); | ||
assert.deepEqual(console.log.firstCall.args, ['Found %d row(s)!', rows.length]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('deleteTable', function () { | ||
it('should delete table', function (done) { | ||
program.deleteTable(options, function (err) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,19 @@ function listTables (options, callback) { | |
} | ||
// [END list_tables] | ||
|
||
function browseRows (dataset, table, callback) { | ||
var bigquery = BigQuery(); | ||
var tableObj = bigquery.dataset(dataset).table(table); | ||
tableObj.getRows(function (err, rows) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a space between
|
||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
console.log('Found %d row(s)!', rows.length); | ||
return callback(null, rows); | ||
}); | ||
} | ||
|
||
// [START delete_table] | ||
/** | ||
* Deletes a table with the specified name from the specified dataset. | ||
|
@@ -236,6 +249,7 @@ var fs = require('fs'); | |
var program = module.exports = { | ||
createTable: createTable, | ||
listTables: listTables, | ||
browseRows: browseRows, | ||
deleteTable: deleteTable, | ||
importFile: importFile, | ||
exportTableToGCS: exportTableToGCS, | ||
|
@@ -270,6 +284,9 @@ cli | |
); | ||
} | ||
) | ||
.command('browse <dataset> <table>', 'List the rows in a BigQuery table.', {}, function (options) { | ||
program.browseRows(options.dataset, options.table, utils.makeHandler()); | ||
}) | ||
.command('import <dataset> <table> <file>', 'Import data from a local file or a Google Cloud Storage file into BigQuery.', { | ||
bucket: { | ||
alias: 'b', | ||
|
@@ -331,6 +348,10 @@ cli | |
'node $0 list my_dataset', | ||
'List tables in "my_dataset".' | ||
) | ||
.example( | ||
'node $0 browse my_dataset my_table', | ||
'Display rows from "my_table" in "my_dataset".' | ||
) | ||
.example( | ||
'node $0 delete my_dataset my_table', | ||
'Delete "my_table" from "my_dataset".' | ||
|
@@ -363,7 +384,7 @@ cli | |
'node $0 copy src_dataset src_table dest_dataset dest_table', | ||
'Copy src_dataset:src_table to dest_dataset:dest_table.' | ||
) | ||
.wrap(100) | ||
.wrap(120) | ||
.recommendCommands() | ||
.epilogue('For more information, see https://cloud.google.com/bigquery/docs'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these changes? Don't we still need to delete both
srcDataset
anddestDataset
?