我正在使用const google = require('googleapis');
流式传输到google bigquery,但现在当我想选择我的数据库时,我感到困惑。查看文档时,我需要使用bigquery.jobs.query
,但我不明白实际的选择应该放在哪里。
var query = `select 1 `;
bqBooking.auth = jwtClient;
bigquery.jobs.query(bqBooking, function (err, rows) {
if (err) {
return callback(err);
}
printExample(rows);
callback(null, rows);
});
/**
* Run an example query.
*
* @param {Function} callback Callback function.
*/
function queryExample (callback) {
var query = 'SELECT TOP(corpus, 10) as title, COUNT(*) as unique_wordsn' +
'FROM [publicdata:samples.shakespeare];';
bigquery.query(query, function (err, rows) {
if (err) {
return callback(err);
}
printExample(rows);
callback(null, rows);
});
}
https://cloud.google.com/bigquery/create-simple-app-api
可以将查询作为参数传递到bigQuery.jobs.query示例的"请求主体"中,如链接所示请在第二个链接中使用"尝试此API"选项。
var google = require('googleapis');
var bigquery = google.bigquery('v2');
authorize(function(authClient) {
var request = {
// Project ID of the project billed for the query
projectId: '', // TODO: Update placeholder value.
resource: {
// TODO: Add desired properties to the request body.
"query": "Select channel, sum(totalRequests) from
conversation_logs.RequestSummary WHERE timeStamp >
TIMESTAMP('2017-09-03 00:00:00 UTC') Group by channel;",
"maxResults": 1,
"useLegacySql": false
},
auth: authClient
};
bigquery.jobs.query(request, function(err, response) {
if (err) {
console.log(err);
return;
}
// TODO: Change code below to process the `response` object:
console.log(JSON.stringify(response, null, 2));
});
});
function authorize(callback) {
google.auth.getApplicationDefault(function(err, authClient)) {
if (err) {
console.log('authentication failed: ', err);
return;
}
if (authClient.createScopedRequired &&
authClient.createScopedRequired()) {
var scopes = ['https://www.googleapis.com/auth/cloud-
platform'];
authClient = authClient.createScoped(scopes);
}
callback(authClient);
});
}