Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): add more clustering code snippets #330

Merged

Conversation

ryanyuan
Copy link
Contributor

Add sample code for creating a clustered table from a query result.
File: samples/client_query_destination_table_clustered.py
Section: https://cloud.google.com/bigquery/docs/creating-clustered-tables#creating_a_clustered_table_from_a_query_result

Add sample code for creating a clustered table when you load data.
File: samples/load_table_clustered.py
Section: https://cloud.google.com/bigquery/docs/creating-clustered-tables#creating_a_clustered_table_when_you_load_data

Fixes #329 馃

@ryanyuan ryanyuan requested a review from a team October 18, 2020 05:32
@ryanyuan ryanyuan requested a review from a team as a code owner October 18, 2020 05:32
@ryanyuan ryanyuan requested a review from engelke October 18, 2020 05:32
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 18, 2020
@product-auto-label product-auto-label bot added api: bigquery Issues related to the googleapis/python-bigquery API. samples Issues that are directly related to samples. labels Oct 22, 2020
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! A couple of nits


def client_query_destination_table_clustered(table_id):

# [START bigquery_query_destination_table_clustered]
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to standardize with what the other languages are using.

Suggested change
# [START bigquery_query_destination_table_clustered]
# [START bigquery_query_clustered_table]

table = client.get_table(table_id) # Make an API request.
if table.clustering_fields == cluster_fields:
print("The destination table is written using the cluster_fields configuration.")
# [END bigquery_query_destination_table_clustered]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# [END bigquery_query_destination_table_clustered]
# [END bigquery_query_clustered_table]

source_format=bigquery.SourceFormat.CSV,
)

with open(file_path, "rb") as source_file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The Go sample loads from GCS "gs://cloud-samples-data/bigquery/sample-transactions/transactions.csv"

It'd be nice if we had some consistency across languages. Also, it's a little bit simpler to run the sample without the need for local files.

Go sample:

https://github.com/GoogleCloudPlatform/golang-samples/blob/7c9a079be0894b2c04c825c07d55176e65087c88/bigquery/snippets/loadingdata/bigquery_load_table_clustered.go#L17-L70

@snippet-bot
Copy link

snippet-bot bot commented Nov 4, 2020

Here is the summary of changes.

You added 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label.

tswast
tswast approved these changes Nov 4, 2020
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@ryanyuan
Copy link
Contributor Author

ryanyuan commented Nov 4, 2020

@tswast thanks for the review and changes.

@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
Copy link

@engelke engelke left a comment

Choose a reason for hiding this comment

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

LGTM.

@tswast tswast added automerge Merge the pull request once unit tests and other checks pass. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Nov 17, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 17, 2020
@gcf-merge-on-green gcf-merge-on-green bot merged commit 809e4a2 into googleapis:master Nov 17, 2020
10 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more code snippets for creating clustered table.
4 participants