Content-Length: 388602 | pFad | http://github.com/googleapis/google-cloud-python/commit/c927c986e4d7928507960e610aec32d478a15bd7

03 Add sample demonstrating how to create a job. (#8422) · googleapis/google-cloud-python@c927c98 · GitHub
Skip to content

Commit c927c98

Browse files
authored
Add sample demonstrating how to create a job. (#8422)
* Add sample demonstrating how to create a job. This sample is intended for https://cloud.google.com/bigquery/docs/running-jobs It demonstrates advanced features, such as overriding location autodetection and overriding job ID generation. * Blacken. Remove link and location auto-detect information from comments.
1 parent dacd029 commit c927c98

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

bigquery/samples/create_job.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
from .. import create_job
16+
17+
18+
def test_create_job(capsys, client):
19+
20+
query_job = create_job.create_job(client)
21+
client.cancel_job(query_job.job_id, location="US")
22+
out, err = capsys.readouterr()
23+
assert "Started job: {}".format(query_job.job_id) in out

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/googleapis/google-cloud-python/commit/c927c986e4d7928507960e610aec32d478a15bd7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy