|
| 1 | +# Copyright 2019 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def create_job(client): |
| 17 | + # [START bigquery_create_job] |
| 18 | + from google.cloud import bigquery |
| 19 | + |
| 20 | + # TODO(developer): Construct a BigQuery client object. |
| 21 | + # client = bigquery.Client() |
| 22 | + |
| 23 | + query_job = client.query( |
| 24 | + "SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`", |
| 25 | + # Explicitly force job execution to be routed to a specific processing |
| 26 | + # location. |
| 27 | + location="US", |
| 28 | + # Specify a job configuration to set optional job resource properties. |
| 29 | + job_config=bigquery.QueryJobConfig( |
| 30 | + labels={"example-label": "example-value"}, maximum_bytes_billed=1000000 |
| 31 | + ), |
| 32 | + # The client libraries automatically generate a job ID. Override the |
| 33 | + # generated ID with either the job_id_prefix or job_id parameters. |
| 34 | + job_id_prefix="code_sample_", |
| 35 | + ) # API request |
| 36 | + |
| 37 | + print("Started job: {}".format(query_job.job_id)) |
| 38 | + # [END bigquery_create_job] |
| 39 | + return query_job |
0 commit comments