-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
refactor(bigquery): update code samples to use strings for table and dataset IDs #9136
Conversation
sync forks
*.rst *.py test conf
Methods were divided into 3 files: - add label - get labels - delete labels *.rst - docs updated tests passed successfully
minor corrections, 'dataset_exists' moved to the 'Getting a Dataset' section
minor corrections, 'dataset_exists' moved to the 'Getting a Dataset' section
grammar fix
grammar fix
minor corrections, removed extra comments
minor corrections, removed extra comments
deleted 'dataset_exists' and 'table_exists' methods
Added additional asserts into the test refactoring of the main file.
cosmetic chgs by 'black'
Chged an assertion parameter
@emar-kar Of course... I was apparently looking at |
@plamut yeah, the amount of commits is really huge. This is my bad. I’ll fix it with the next part. |
bigquery/samples/copy_table.py
Outdated
# table_id = "your-project.your_dataset.your_table_name" | ||
|
||
orig_table = client.get_table(table_id) # Make an API request. | ||
dataset = client.get_dataset(dataset_id) # Make an API request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calls to get_table
and get_dataset
are unnecessary. Let's use
# TODO(developer): Set source_table_id to the ID of the original table.
# source_table_id = "your-project.source_dataset.source_table"
# TODO(developer): Set destination_table_id to the ID of the destination table.
destination_table_id = "your-project.destination_dataset.destination_table"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bigquery/samples/client_query.py
Outdated
print("The query data:") | ||
for row in query_job: | ||
# Row values can be accessed by field name or index | ||
print(row) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's demonstrate that fields can be accessed by name or index.
print(row) | |
print("name={}, count={}".format(row[0], row["count"])) |
bigquery/samples/client_query.py
Outdated
# TODO(developer): Construct a BigQuery client object. | ||
# client = bigquery.Client() | ||
|
||
query = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
query = ( | |
query = """ | |
SELECT name, SUM(number) as total_people | |
FROM `bigquery-public-data.usa_names.usa_1910_2013` | |
WHERE state = 'TX' | |
GROUP BY name, state | |
ORDER BY total_people DESC | |
LIMIT 20 | |
""" |
client_query.client_query(client) | ||
out, err = capsys.readouterr() | ||
assert "The query data:" in out | ||
assert "Row(" in out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're using the usa_1910_2013
table, the data won't change. We can use a specific value in our tests.
assert "Row(" in out | |
assert "name=James, count=272793" in out |
- copy_table - client_query - test_copy_table - test_client_query
Thanks for your patience. I've been travelling a lot lately, but now I'm back. Re:
Since our code samples are included in how-to guides, our technical writing style guide requires (1) imperative. |
Yeah, sorry. I pushed the commit with |
Towards #8989
This PR contains five snippets: