usingGoogle.Cloud.BigQuery.V2;usingSystem;usingSystem.Collections.Generic;publicclassBigQueryCreateJob{publicBigQueryJobCreateJob(stringprojectId="your-project-id"){stringquery=@" SELECT country_name from `bigquery-public-data.utility_us.country_code_iso";// Initialize client that will be used to send requests.BigQueryClientclient=BigQueryClient.Create(projectId);QueryOptionsqueryOptions=newQueryOptions{JobLocation="us",JobIdPrefix="code_sample_",Labels=newDictionary<string,string>
{["example-label"]="example-value"},MaximumBytesBilled=1000000};BigQueryJobqueryJob=client.CreateQueryJob(sql:query,parameters:null,options:queryOptions);Console.WriteLine($"Started job: {queryJob.Reference.JobId}");returnqueryJob;}}
importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.Job;importcom.google.cloud.bigquery.JobId;importcom.google.cloud.bigquery.JobInfo;importcom.google.cloud.bigquery.QueryJobConfiguration;importcom.google.common.collect.ImmutableMap;importjava.util.UUID;// Sample to create a jobpublicclassCreateJob{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.Stringquery="SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`";createJob(query);}publicstaticvoidcreateJob(Stringquery){try{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();// Specify a job configuration to set optional job resource properties.QueryJobConfigurationqueryConfig=QueryJobConfiguration.newBuilder(query).setLabels(ImmutableMap.of("example-label","example-value")).build();// The location and job name are optional,// if both are not specified then client will auto-create.StringjobName="jobId_"+UUID.randomUUID().toString();JobIdjobId=JobId.newBuilder().setLocation("us").setJob(jobName).build();// Create a job with job IDbigquery.create(JobInfo.of(jobId,queryConfig));// Get a job that was just createdJobjob=bigquery.getJob(jobId);if(job.getJobId().getJob().equals(jobId.getJob())){System.out.print("Job created successfully."+job.getJobId().getJob());}else{System.out.print("Job was not created");}}catch(BigQueryExceptione){System.out.print("Job was not created. \n"+e.toString());}}}
fromgoogle.cloudimportbigquery# Construct a BigQuery client object.client=bigquery.Client()query_job=client.query("SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`",# Explicitly force job execution to be routed to a specific processing# location.location="US",# Specify a job configuration to set optional job resource properties.job_config=bigquery.QueryJobConfig(labels={"example-label":"example-value"},maximum_bytes_billed=1000000),# The client libraries automatically generate a job ID. Override the# generated ID with either the job_id_prefix or job_id parameters.job_id_prefix="code_sample_",)# Make an API request.print("Started job: {}".format(query_job.job_id))
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-17。"],[[["\u003cp\u003eTo run a BigQuery job programmatically, you must call the \u003ccode\u003ejobs.insert\u003c/code\u003e method, check the job's status using the \u003ccode\u003ejobs.get\u003c/code\u003e method until it's \u003ccode\u003eDONE\u003c/code\u003e, and then check for success or failure by examining the \u003ccode\u003estatus.errorResult\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eRunning a job requires the \u003ccode\u003ebigquery.jobs.create\u003c/code\u003e IAM permission, which is included in predefined roles like \u003ccode\u003eroles/bigquery.user\u003c/code\u003e, \u003ccode\u003eroles/bigquery.jobUser\u003c/code\u003e, and \u003ccode\u003eroles/bigquery.admin\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eJobs can be initiated with specific types such as \u003ccode\u003eload\u003c/code\u003e, \u003ccode\u003equery\u003c/code\u003e, \u003ccode\u003eextract\u003c/code\u003e, or \u003ccode\u003ecopy\u003c/code\u003e, which must be defined in the job resource's \u003ccode\u003econfiguration\u003c/code\u003e section when calling \u003ccode\u003ejobs.insert\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries for languages like C#, Java, and Python provide methods to create and manage BigQuery jobs, including options to set job locations, IDs, labels, and maximum billing thresholds.\u003c/p\u003e\n"],["\u003cp\u003eLabels can be added to jobs through the \u003ccode\u003ebq\u003c/code\u003e command-line tool for query jobs or through the API via the \u003ccode\u003ejobs.insert\u003c/code\u003e method's \u003ccode\u003elabels\u003c/code\u003e property, and these labels are included in billing data.\u003c/p\u003e\n"]]],[],null,[]]