简体   繁体   English

如何知道 BigQuery 作业插入何时完成

[英]How to know when a BigQuery job insert is complete

I'm using BigQuery.Jobs.insert to upload a csv blob to a BigQuery table (from a Google Sheets spreadsheet if that matters), but I need to know when the upload is complete so that I can run a query to process it.我正在使用 BigQuery.Jobs.insert 将 csv blob 上传到 BigQuery 表(如果重要的话,从 Google 表格电子表格),但我需要知道上传何时完成,以便我可以运行查询来处理它。 Here's the code I have...这是我的代码......

  csv_blob = Utilities.newBlob(csv,"application/octet-stream");
  
  //Copy the csv to BigQuery
  job = BigQuery.Jobs.insert(job, projectId, csv_blob );

  var jobId=job.jobReference.jobId;

  //Give it a half second to complete
  var sleepTimeMs = 500;
  Utilities.sleep(sleepTimeMs);

  //see if it needs longer
  var jobstatus = job.status;
  while(jobstatus.state!="COMPLETE") {
    Utilities.sleep(sleepTimeMs);
    sleepTimeMs *= 2;
    jobstatus = job.status;
  }

The upload is working, but the job.status.state never changes from "RUNNING", no matter how long I wait.上传工作正常,但 job.status.state 永远不会从“RUNNING”改变,无论我等多久。 Even after I manually verify the uploaded table on the server, the job.status.state is still "RUNNING".即使在我手动验证服务器上上传的表之后,job.status.state 仍然是“RUNNING”。 What is the right way to know when the job is complete?知道工作何时完成的正确方法是什么? Thanks谢谢

You need to fetch the current status of the job with BigQuery.Jobs.Get ( REST reference ), it appears that you're just rechecking the response you received from the initial job insertion.您需要使用BigQuery.Jobs.GetREST 参考)获取作业的当前状态,看来您只是在重新检查从初始作业插入中收到的响应。

An quick and dirty example of invoking this:调用它的一个快速而肮脏的例子:

function myFunction() {
  projectID = "my-project-id"
  jobID = "some-job-id"
  location = "us-central1"

  job = BigQuery.Jobs.get(projectID, jobID, {location: location});
  console.log("result state: " + job.status.state + " end time:" + job.statistics.endTime);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BigQuery:如何共享作业结果? - BigQuery: How to share job results? 如何使用 Terraform 在 Cloud Workflow 中传递 BigQuery 插入作业的查询参数 - How to pass query parameter of BigQuery insert job in Cloud Workflow using Terraform 我如何知道 Amazon EC2 操作何时完成? - How do I know when an Amazon EC2 operation is complete? 如何将数据插入数组 BigQuery - How to insert data into array BigQuery 知道何时上传到 s3 存储桶完成 - Know when upload to s3 bucket is complete 有谁知道启动 firebase 应用程序时如何摆脱“Firebase Hosting Setup Complete”屏幕? - does anyone know how to get rid of "Firebase Hosting Setup Complete" screen when launching a firebase application? Cloud Functions:当文件上传到 GCS Bucket 时如何将数据插入 BigQuery? - Cloud Functions: How to Insert Data into BigQuery when a file is Uploaded into a GCS Bucket? 如何通过流式插入避免 BigQuery 中的重复 - how to avoid duplication in BigQuery by streaming insert Airflow 2:将数据从 BigQuery 传输到 Cloud Storage 时找不到作业 - Airflow 2: Job Not Found when transferring data from BigQuery into Cloud Storage 如何修复写入 BigQuery 的数据流模板作业中的“java.lang.RuntimeException:创建作业失败”? - How to fix "java.lang.RuntimeException: Failed to create job" in a Dataflow template job that writes to BigQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM