Repository navigation
refactor(bigquery): update code samples to use strings for table and dataset IDs #9136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 78 commits
6b3a2a3
4c6d7b4
377310c
5ce976f
a7b2376
0de5d8b
5e05cd8
f6b60a0
a773251
8375877
a0792bd
95dc8f8
cf7576e
0645e33
92efd59
1814821
a31bc1f
725c515
6ffc123
5654dcd
2ff376c
948ddb5
e8d62c4
28251ec
ad623ba
ec67aee
c8c0f70
42204ed
b4dade6
febfa11
c66ba4b
0e7ccf5
d5ab15d
7704ad3
6dd1174
50c4aed
7a654c3
8e26115
0cf0071
f602e3f
0bf9aab
2e50a81
9e77624
7d99673
e37f5a2
af27c29
47ee156
b78f6c9
6ee351e
9a65dae
0913f6a
14757f6
9941957
4ca71e5
cd78ed2
9cc5661
7e42411
056f357
70c032f
cde3e62
9d3c1aa
99a5bd5
2ba305b
f3607c1
1040fba
edac824
ea94915
92fca34
17fb644
2dfcc3d
c4e3f7c
902fdd9
2483f55
df4f6c1
ccf3dcd
b87e7d0
150bcf2
ab504bf
176395e
e67d172
da4a2bc
8852951
6d533b3
327373c
e55f698
ef884b8
50394cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| def client_list_jobs(client): | ||
|
|
||
| # [START bigquery_list_jobs] | ||
| # TODO(developer): Import the client library. | ||
| # from google.cloud import bigquery | ||
|
|
||
| import datetime | ||
|
|
||
| # TODO(developer): Construct a BigQuery client object. | ||
| # client = bigquery.Client() | ||
|
|
||
| # List the 10 most recent jobs in reverse chronological order. | ||
| # Omit the max_results parameter to list jobs from the past 6 months. | ||
| print("Last 10 jobs:") | ||
| for job in client.list_jobs(max_results=10): # API request(s) | ||
| print("{}".format(job.job_id)) | ||
|
|
||
| # The following are examples of additional optional parameters: | ||
|
|
||
| # Use min_creation_time and/or max_creation_time to specify a time window. | ||
| print("Jobs from the last ten minutes:") | ||
| ten_mins_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=10) | ||
| for job in client.list_jobs(min_creation_time=ten_mins_ago): | ||
| print("{}".format(job.job_id)) | ||
|
|
||
| # Use all_users to include jobs run by all users in the project. | ||
| print("Last 10 jobs run by all users:") | ||
| for job in client.list_jobs(max_results=10, all_users=True): | ||
| print("{} run by user: {}".format(job.job_id, job.user_email)) | ||
|
|
||
| # Use state_filter to filter by job state. | ||
| print("Last 10 jobs done:") | ||
| for job in client.list_jobs(max_results=10, state_filter="DONE"): | ||
| print("{}".format(job.job_id)) | ||
| # [END bigquery_list_jobs] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||
| # Copyright 2019 Google LLC | ||||||||||||||||||||
| # | ||||||||||||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||||||||||||
| # You may obtain a copy of the License at | ||||||||||||||||||||
| # | ||||||||||||||||||||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||
| # | ||||||||||||||||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||||||||||
| # limitations under the License. | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def client_query(client): | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # [START bigquery_query] | ||||||||||||||||||||
| # TODO(developer): Import the client library. | ||||||||||||||||||||
| # from google.cloud import bigquery | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # TODO(developer): Construct a BigQuery client object. | ||||||||||||||||||||
| # client = bigquery.Client() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| query = ( | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we want to show more than one field in the print logic, let's select more than one column.
Suggested change
|
||||||||||||||||||||
| "SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` " | ||||||||||||||||||||
| 'WHERE state = "TX" ' | ||||||||||||||||||||
| "LIMIT 100" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| query_job = client.query( | ||||||||||||||||||||
| query, location="US" # Must match the destination dataset(s) location. | ||||||||||||||||||||
| ) # Make an API request. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| print("The query data:") | ||||||||||||||||||||
| for row in query_job: | ||||||||||||||||||||
| # Row values can be accessed by field name or index | ||||||||||||||||||||
| print(row) | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's demonstrate that fields can be accessed by name or index.
Suggested change
|
||||||||||||||||||||
| # [END bigquery_query] | ||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.