How to run a run a BigQuery job programmatically?

0 votes
I have a big query job that I need to run programmatically. How do I do it?
Nov 15 in GCP by anonymous
• 4,330 points
22 views

1 answer to this question.

0 votes

To run a job programmatically:

  1. Start the job by calling the jobs.insert method. When you call the jobs.insert method, include a job resource representation that contains:

    • Your location in the location property in the jobReference section.

    • The job ID generated by your client code. The server generates a job ID for you if you omit it, but it is a best practice to generate the job ID on the client side to allow reliable retry of the jobs.insert call.

      For example:

      {
        "jobReference": {
          "projectId": "my_project",
          "jobId": "job_123",
          “location”: “asia-northeast1”
        },
        "configuration":
        {
          // ..
        },
      }
      
      
  2. In the configuration section of the job resource, include a child property that specifies the job type — load, query, extract, or copy.

  3. After calling the jobs.insert method, check the job status by calling jobs.get with the job ID and location, and check the status.state value to learn the job status. When status.state is DONE, the job has stopped running; however, a DONE status does not mean that the job completed successfully, only that it is no longer running.

  4. Check for job success. If the job has an errorResult property, the job has failed. The status.errorResult property holds information describing what went wrong in a failed job. If status.errorResult is absent, the job finished successfully, although there might have been some non-fatal errors, such as problems importing a few rows in a load job. Non-fatal errors are returned in the job's status.errors list.

answered Nov 15 by Sirajul
• 40,980 points

Related Questions In GCP

0 votes
1 answer

Schedule a query to run every 3 hours in my BigQuery project.

 Use the bq query command. With this method, you will ...READ MORE

answered Nov 21 in GCP by anonymous
• 40,980 points
27 views
0 votes
1 answer

How to delete a project from Google Cloud Console

First of all, select the project you ...READ MORE

answered Apr 18, 2018 in GCP by kurt_cobain
• 9,280 points
191 views
+1 vote
2 answers

How to open a port on google compute engine

You need to set the firewall rule ...READ MORE

answered Jul 9 in GCP by K sagar
197 views
0 votes
1 answer
0 votes
1 answer

Does Google cloud platform (GCP) offer IaaS ? Or just PaaS?

GCP provides IaaS as well, although it ...READ MORE

answered Sep 20 in GCP by Sirajul
• 40,980 points
172 views
0 votes
1 answer

How do I create a VPCN (Virtual private cloud network) on Google Cloud?

You can connect various GCP resources to each ...READ MORE

answered Sep 23 in GCP by Sirajul
• 40,980 points
40 views
0 votes
1 answer

Cloud SQL of google cloud is IaaS or PaaS?

Cloud SQL is PAAS (Plaform As A ...READ MORE

answered Sep 23 in GCP by Sirajul
• 40,980 points
63 views
0 votes
1 answer