Database Reference
In-Depth Information
of the dialog box it says, “These services must be enabled in the Google
Developers Console,” you need to click through, and once again switch a
toggle to turn on BigQuery. This page looks like the project setup page when
you signed up for BigQuery and turned on billing. You do not have to sign
up for billing here, and although this does create a project, this project is not
used in a meaningful way when you access BigQuery. This project does not
show up in your projects list. After enabling BigQuery from the list, you can
safely forget that this project even exists.
Now you can close the various dialog boxes and browser tabs that have
popped up, and BigQuery access should be ready to go.
Running a BigQuery Query in Apps Script
Before returning to the spreadsheet, just write a simple function that runs a
query and logs the result. This way you can verify that things are configured
correctly and BigQuery works. Try entering the following function
(substituting your own project ID) and pressing Save:
function simpleQuery() {
var projectId = 'bigquery-e2e'; // YOUR PROJECT HERE.
var sql = 'SELECT corpus, COUNT(*) as cnt '
+ 'FROM [publicdata:samples.shakespeare] '
+ 'GROUP BY corpus';
Logger.log('%s: Running query: "%s"', projectId,
sql);
var resource = {
'query': sql
};
var queryResults = BigQuery.Jobs.query(resource,
projectId);
Logger.log('Got query results:\n%s', queryResults);
}
This function is more or less the simplest way to run a query. As you've
seen in previous chapters, it is far from complete; it doesn't handle queries
that take longer to run than the default timeout, and it fetches only the
first page of results. The advantage, however, is it lets you know whether
you have BigQuery working. Select simpleQuery from the Select Function
Search WWH ::




Custom Search