Uh oh!
There was an error while loading. Please reload this page.
refactor(bigquery): update code samples to use strings for table and dataset IDs - #9136
Conversation
*.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
plamut
commented
Sep 19, 2019
@emar-kar Of course... I was apparently looking at |
emar-kar
commented
Sep 19, 2019
@plamut yeah, the amount of commits is really huge. This is my bad. I’ll fix it with the next part. |
| # 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.
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"
| 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.
Let's demonstrate that fields can be accessed by name or index.
| print(row) | |
| print("name={}, count={}".format(row[0], row["count"])) |
| # TODO(developer): Construct a BigQuery client object. | ||
| # client = bigquery.Client() | ||
| query = ( |
There was a problem hiding this comment.
Since we want to show more than one field in the print logic, let's select more than one column.
| query=( | |
| query=""" | |
| SELECTname, SUM(number) astotal_people | |
| FROM`bigquery-public-data.usa_names.usa_1910_2013` | |
| WHEREstate='TX' | |
| GROUPBYname, state | |
| ORDERBYtotal_peopleDESC | |
| LIMIT20 | |
| """ |
| 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.
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("inout | |
| assert"name=James, count=272793"inout |
- copy_table - client_query - test_copy_table - test_client_query
tswast
commented
Oct 8, 2019
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. |
emar-kar
commented
Oct 8, 2019
Yeah, sorry. I pushed the commit with |

Towards #8989
This PR contains five snippets: