2016-08-07 7 views
1

私はconst google = require('googleapis');をGoogle bigqueryにストリーミングするために使用していますが、今は自分のデータベースを選択するときに困惑します。 ドキュメントを見ると、私はbigquery.jobs.queryを使用する必要がありますが、実際の選択をどこに置くべきか分かりません。googleapis bigquery apiを使用して選択するには

var query = `select 1 `; 
bqBooking.auth = jwtClient; 
bigquery.jobs.query(bqBooking, function (err, rows) { 
    if (err) { 
     return callback(err); 
    } 

    printExample(rows); 
    callback(null, rows); 
}); 

答えて

0
/** 
* Run an example query. 
* 
* @param {Function} callback Callback function. 
*/ 
function queryExample (callback) { 
    var query = 'SELECT TOP(corpus, 10) as title, COUNT(*) as unique_words\n' + 
    '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

+0

このサンプルでは、​​var gcloud = require( 'gcloud')が使用されています。 私はconst google = require( 'googleapis')を使用していますが、 –

0

linkに示すように、第二のリンクでオプション「このAPIを試してみてください」を使用してくださいbigQuery.jobs.query exampleの「リクエストボディ」にパラメータとしてクエリを渡すことができます。

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); 
    }); 
} 
関連する問題