Skip to content

refactor(bigquery): update code samples to use strings for table and dataset IDs - #9136

Merged
emar-kar merged 87 commits into
googleapis:masterfrom
MaxxleLLC:second-five-v2
Oct 15, 2019
Merged

refactor(bigquery): update code samples to use strings for table and dataset IDs#9136
emar-kar merged 87 commits into
googleapis:masterfrom
MaxxleLLC:second-five-v2

Conversation

@emar-kar

Copy link
Copy Markdown
Contributor

Towards #8989
This PR contains five snippets:

  • client_list_jobs
  • client_query
  • copy_table
  • table_exists
  • table_insert_rows

mf2199and others added 30 commits August 8, 2019 23:11
*.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

Copy link
Copy Markdown
Contributor

@emar-kar Of course... I was apparently looking at snippets.py when writing the review comment, my bad. The number of commits is huge, and in retrospect I should have probably looked at the final set of changes right from the start.

@emar-kar

Copy link
Copy Markdown
ContributorAuthor

@plamut yeah, the amount of commits is really huge. This is my bad. I’ll fix it with the next part.

@emar-karemar-kar changed the title BigQuery: Update code samples to use strings for table and dataset IDsrefactor(bigquery): Update code samples to use strings for table and dataset IDsSep 25, 2019
@emar-karemar-kar changed the title refactor(bigquery): Update code samples to use strings for table and dataset IDsrefactor(bigquery): update code samples to use strings for table and dataset IDsSep 25, 2019
@plamutplamut added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 25, 2019
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 25, 2019
Comment threadbigquery/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.

Copy link
Copy Markdown
Contributor

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"

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also decided to move the num_rows assertion to the test file.
code_1

Comment threadbigquery/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)

Copy link
Copy Markdown
Contributor

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.

Suggested change
print(row)
print("name={}, count={}".format(row[0], row["count"]))

Comment threadbigquery/samples/client_query.py Outdated
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()

query = (

Copy link
Copy Markdown
Contributor

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.

Suggested change
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

Copy link
Copy Markdown
Contributor

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.

Suggested change
assert"Row("inout
assert"name=James, count=272793"inout

@emar-karemar-kar added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@emar-karemar-kar added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2019
@emar-karemar-kar removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2019
@emar-kar
emar-kar requested a review from tswastOctober 8, 2019 11:40
@tswast

Copy link
Copy Markdown
Contributor

Thanks for your patience. I've been travelling a lot lately, but now I'm back.

Re: Make and API request vs Makes an API request, I'd interpret these in two ways:

  1. (imperative) You, the developer, should Make and API request.
  2. (descriptive) This line of code Makes an API request.

Since our code samples are included in how-to guides, our technical writing style guide requires (1) imperative.

@emar-kar

Copy link
Copy Markdown
ContributorAuthor

Yeah, sorry. I pushed the commit with -s modification today. I'll revert it tomorrow. Thank you, appreciate your help.

@emar-kar

Copy link
Copy Markdown
ContributorAuthor

@tswast One more thing with the comments. I also added Waits for the job to complete lines in #9212. Maybe it is required to be without -s too?

@tswast

Copy link
Copy Markdown
Contributor

@tswast One more thing with the comments. I also added Waits for the job to complete lines in #9212. Maybe it is required to be without -s too?

Yes, without the -s would more closely match our tech writing style guide.

@emar-kar
emar-kar merged commit 01f6826 into googleapis:masterOct 15, 2019
@emar-kar
emar-kar deleted the second-five-v2 branch October 16, 2019 15:03
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigqueryIssues related to the BigQuery API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@emar-kar@googlebot@IlyaFaer@tswast@plamut@tseaver@yoshi-kokoro@mf2199