【问题标题】:API call to bigquery.jobs.getQueryResults failed with error: Not found: Job对 bigquery.jobs.getQueryResults 的 API 调用失败并出现错误:未找到:作业
【发布时间】:2020-12-29 17:11:17
【问题描述】:

我正在尝试通过 Apps 脚本从 BigQuery 中提取地理数据,但我的脚本因上述错误消息而失败。

function runQuery() {
  // Replace this value with the project ID listed in the Google
  // Cloud Platform project.
  var projectId = '111111';
  
  var request = {
    useLegacySql: false,
    query: 'select geom, POA_CODE16, POA_NAME16, AREASQKM16 from `my-bigquery-project.my-datasource.my-table` WHERE POA_CODE16 >= 2000 AND POA_CODE16 < 3000;'
  };
  
  var queryResults = BigQuery.Jobs.query(request, projectId);
  var jobId = queryResults.jobReference.jobId;
  
  Logger.log('Initial jobId: %s', jobId);
    
  // Check on status of the Query Job.
  var sleepTimeMs = 500;
  while (!queryResults.jobComplete) {
    Utilities.sleep(sleepTimeMs);
    sleepTimeMs *= 2;
    Logger.log('Not complete jobId: %s', jobId);
    try {
      queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId);
    } catch(e) {
      Logger.log(e);
    }
  }
  
  // Get all the rows of results.
  var rows = queryResults.rows;
  while (queryResults.pageToken) {
    
    Logger.log('Page token jobId: %s', jobId);
    
    queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
      pageToken: queryResults.pageToken
    });
    rows = rows.concat(queryResults.rows);

  }
  
  Logger.log(rows.length);
} 

脚本在这里失败:

queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
      pageToken: queryResults.pageToken
    }); 

有错误

GoogleJsonResponseException: API call to bigquery.jobs.getQueryResults failed with error: Not found: Job my-bigquery-project:job_##RJYm1kUsbMif3N6Dpa7t-mkC## (line 34, file "tests")

日志显示:

Initial jobId: job_##RJYm1kUsbMif3N6Dpa7t-mkC##
Page token jobId: job_##RJYm1kUsbMif3N6Dpa7t-mkC##

我觉得这可能是返回的行的大小 - 多边形很大 - 这是问题所在,但错误消息没有提供任何线索,我不确定如何/在哪里调试它.

查询在 BigQuery 中运行良好。

【问题讨论】:

    标签: google-apps-script google-bigquery


    【解决方案1】:

    您可能需要为 timeoutMs 设置一个比 default 的 10000 更高的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 2019-01-14
      相关资源
      最近更新 更多