通过API运行BigQuery查询时,Google脚本会返回“异常:空响应”

时间:2017-11-28 10:45:08

标签: google-apps-script google-bigquery

我在Google表格中使用Google脚本来运行查询(通过Bigquery)并将结果返回到同一电子表格。对于数据的日期范围较窄的查询,这一切都正常,但是当我将日期范围扩展到几周后,我收到错误:“例外:空响应”。两个查询在其他方面完全相同,并且在BigQuery中手动运行它们时要处理的大小相同(尽管扩展日期范围查询的作业说明中的行输入/输出较大)。有谁知道是什么导致了这个错误以及我如何解决这个问题?

不成功查询的执行记录,即查询包含WHERE user_dim.first_open_timestamp_micros BETWEEN 1509494400000000 AND 1511395200000000:

  

[17-11-28 02:15:13:072 PST]开始执行

     

[17-11-28 02:15:13:085 PST] SpreadsheetApp.getActiveSheet()[0秒]

     

[17-11-28 02:15:13:222 PST] Sheet.getRange([C183])[0.136秒]

     

[17-11-28 02:15:13:284 PST] Range.getValue()[0.062秒]

     

[17-11-28 02:16:13:278 PST] Logger.log([例外:空响应,[]])[0秒]

     

[17-11-28 02:16:16:565 PST] Browser.msgBox([例外:空响应])[3.286秒]

     

[17-11-28 02:16:16:609 PST]执行成功[63.483秒总运行时间]

成功查询的执行记录,即查询包含WHERE user_dim.first_open_timestamp_micros BETWEEN 1510444800000000 AND 1511395200000000:

  

[17-11-28 01:49:51:604 PST]开始执行

     

[17-11-28 01:49:51:614 PST] SpreadsheetApp.getActiveSheet()[0秒]

     

[17-11-28 01:49:51:672 PST] Sheet.getRange([C183])[0.057秒]

     

[17-11-28 01:49:51:730 PST] Range.getValue()[0.057秒]

     

[17-11-28 01:50:31:816 PST] Sheet.getRange([1,20,1,43])[0秒]

     

[17-11-28 01:50:31:896太平洋标准时间] Range.setValues([[[20737,7342,3061,872,1076,924,322,170,36,54,79,928,224] ,21,50,8645,3364,749,2060,1051,609,226,44,51,175,924,192,22,49,1263,515,96,99,82,32,11,0,3 ,21,148,35,1,0]]] ......)[0.08秒]

     

[17-11-28 01:50:34:394 PST] Browser.msgBox([按OK查看结果])[2.497秒]

     

[17-11-28 01:50:34:516太平洋标准时间]执行成功[总运行时间为42.781秒]

脚本如下(删除了projectNumber):

function runQuery1() {
var projectNumber = ‘XXXXXXXX';
var sheet = SpreadsheetApp.getActiveSheet();
var cell1 = sheet.getRange("C183").getValue();
var sql = cell1;
var queryResults;

// Inserts a Query Job
try {
var queryRequest = BigQuery.newQueryRequest();
queryRequest.setQuery(sql).setUseLegacySql(false).setTimeoutMs(999999);
queryResults = BigQuery.Jobs.query(queryRequest, projectNumber);
}
catch (err) {
Logger.log(err);
Browser.msgBox(err);
return;
}

// Check on status of the Query Job
while (queryResults.getJobComplete() == false) {
try {
queryResults = BigQuery.Jobs.getQueryResults(projectNumber, queryJob.getJobReference().getJobId());
}
catch (err) {
Logger.log(err);
Browser.msgBox(err);
return;
}
}

// Update the amount of results
var resultCount = queryResults.getTotalRows();
var resultSchema = queryResults.getSchema();

var resultValues = new Array(resultCount);
var tableRows = queryResults.getRows();

Iterate through query results
for (var i = 0; i < tableRows.length; i++) {
var cols = tableRows[i].getF();
resultValues[i] = new Array(cols.length);

// For each column, add values to the result array
for (var j = 0; j < cols.length; j++) {
resultValues[i][j] = cols[j].getV();
}
} 

// Update the Spreadsheet with data from the resultValues array, starting from cell A1
sheet.getRange(1, 20, resultCount, tableRows[0].getF().length).setValues(resultValues);  
Browser.msgBox("Press OK to see results");
}

0 个答案:

没有答案