Skip to content

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

Merged
tswast merged 18 commits into
googleapis:masterfrom
MaxxleLLC:new-samples
Dec 2, 2019
Merged

refactor(bigquery): update code samples to use strings for table and dataset IDs#9495
tswast merged 18 commits into
googleapis:masterfrom
MaxxleLLC:new-samples

Conversation

@emar-kar

@emar-karemar-kar commented Oct 18, 2019

Copy link
Copy Markdown
Contributor

Towards #8989
Closes#9499.

List of changes:

New samples:

  1. client_query_add_column;
  2. client_query_batch;
  3. client_query_destination_table;
  4. client_query_destination_table_cmek;
  5. client_query_destination_table_legacy;
  6. client_query_dry_run;
  7. client_query_legacy_sql;
  8. client_query_relax_column;
  9. copy_table_cmek;
  10. copy_table_multiple_source.

Comment lines in samples unified:

  1. client_query;
  2. copy_table;
  3. load_table_dataframe.

DEPRECATED tests

  1. test_create_routine;
  2. test_update_routine;
  3. test_get_routine;
  4. test_delete_routine;
  5. test_list_routines;
  6. test_create_routine_ddl

All those tests were united in the test_routine_samples file!

@emar-karemar-kar added the api: bigquery Issues related to the BigQuery API. label Oct 18, 2019
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 18, 2019
@emar-karemar-kar changed the title New samplesrefactor(bigquery): update code samples to use strings for table and dataset IDsOct 18, 2019
@emar-kar
emar-kar requested a review from tswastOctober 18, 2019 11:01
@emar-kar
emar-kar marked this pull request as ready for review October 18, 2019 11:01
@emar-kar
emar-kar requested a review from a teamOctober 18, 2019 11:01
@emar-karemar-kar added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2019
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2019
@tswasttswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2019
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2019
Comment threadbigquery/samples/copy_table_multiple_source.py Outdated
Comment threadbigquery/samples/copy_table_multiple_source.py Outdated
Comment threadbigquery/samples/copy_table_cmek.py Outdated
Comment threadbigquery/samples/copy_table_cmek.py Outdated
Comment threadbigquery/samples/client_query_legacy_sql.py Outdated
Comment threadbigquery/samples/client_query_destination_table_cmek.py Outdated
Comment threadbigquery/samples/tests/test_client_query_dry_run.py Outdated
Comment threadbigquery/samples/tests/test_client_query_batch.py
Comment threadbigquery/samples/client_query_destination_table_cmek.py
Comment threadbigquery/samples/tests/test_client_query_dry_run.py Outdated
Comment threadbigquery/samples/tests/test_client_query_legacy_sql.py Outdated
Comment threadbigquery/docs/usage/queries.rst
emar-karand others added 4 commits October 24, 2019 13:32
The parameter can sometimes confuse new BigQuery developers. Since
location autodetection now works pretty well, the parameter can be
removed from code samples for better clarity, except where the samples
want to explicitly demonstrate its usage.
@googlebot

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebotgooglebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Oct 25, 2019
@plamut

Copy link
Copy Markdown
Contributor

@googlebot I consent.

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebotgooglebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Oct 25, 2019
Comment threadbigquery/samples/copy_table_cmek.py Outdated
Comment threadbigquery/samples/client_query_destination_table_legacy.py Outdated
Comment threadbigquery/samples/client_query_destination_table_legacy.py Outdated
Comment threadbigquery/samples/client_query_legacy_sql.py Outdated
Comment threadbigquery/samples/client_query_destination_table.py Outdated
Comment threadbigquery/samples/client_query_destination_table.py Outdated
Comment threadbigquery/samples/client_query_destination_table_cmek.py
Comment threadbigquery/samples/client_query_batch.py Outdated
Comment threadbigquery/samples/client_query_relax_column.py
@emar-karemar-kar added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 8, 2019
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 8, 2019
@tswast
tswast self-requested a review November 13, 2019 01:17

copy_table_multiple_source.copy_table_multiple_source(
client, random_table_id, table_ids
)

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 call dest_table = client.get_table(random_table_id) and then assert dest_table.num_rows > 0 so that we know that the job did what we expected it to do.

Comment threadbigquery/samples/tests/test_routine_samples.py


def test_get_routine(capsys, client, routine_id):
def test_client_query_destination_table_legacy(capsys, client, table_id):

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.

Use random_table_id since we want to create a new table in the actual sample.

The table_id creates a table before the tests run.

table=client.create_table(table)

assert routine.body == "x * 4"
query_job = client_query_dry_run.client_query_dry_run(client)
out, err = capsys.readouterr()
assert "This query will process 0 bytes." not 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.

I got confused by this test.

I'd very much like to see a positive assertion that a non-zero number is present. not in could happen for many different reasons.

Suggested change
assert"This query will process 0 bytes."notinout
assert"This query will process"inout
assertquery_job.total_bytes_processed>0

@tswast
tswast self-requested a review December 2, 2019 15:34
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.

BigQuery: Remove location parameter from query code samples

5 participants

@emar-kar@googlebot@plamut@tswast@yoshi-kokoro