How to use App script to run a google big query an

2019-03-06 22:43发布

How to use app script to run a google big query and save the results in a new table in the same project folder on google big query

1条回答
迷人小祖宗
2楼-- · 2019-03-06 23:41

It will look like this:

function saveQueryToTable() {
  var projectId = 'your project';
  var datasetId = 'your dataset';
  var tableId = 'your table';
  var job = {
    configuration: {
      query: {
        query: 'SELECT TOP(word, 300) AS word, COUNT(*) AS word_count' +
               'FROM publicdata:samples.shakespeare' +
               'WHERE LENGTH(word) > 10;',
        destinationTable: {
          projectId: projectId,
          datasetId: datasetId,
          tableId: tableId
        }
      }
    }
  };

  var queryResults = BigQuery.Jobs.insert(job, projectId);
  Logger.log(queryResults.status);
}

More examples here.

查看更多
登录 后发表回答