Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

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

Merged
gcf-merge-on-green[bot] merged 7 commits into
googleapis:masterfrom
ryanyuan:add-sample-code-clustering
Nov 17, 2020
Merged

docs(samples): add more clustering code snippets#330
gcf-merge-on-green[bot] merged 7 commits into
googleapis:masterfrom
ryanyuan:add-sample-code-clustering

Conversation

@ryanyuan

Copy link
Copy Markdown
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 teamOctober 18, 2020 05:32
@ryanyuan
ryanyuan requested a review from a team as a code ownerOctober 18, 2020 05:32
@ryanyuan
ryanyuan requested a review from engelkeOctober 18, 2020 05:32
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Oct 18, 2020
@ryanyuan
ryanyuanforce-pushed the add-sample-code-clustering branch from e15442f to 2ca69beCompareOctober 19, 2020 22:14
@product-auto-labelproduct-auto-labelBot added api: bigquery Issues related to the googleapis/python-bigquery API. samples Issues that are directly related to samples. labels Oct 22, 2020

@tswasttswast left a comment

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.

Thanks for the contribution! A couple of nits


def client_query_destination_table_clustered(table_id):

# [START bigquery_query_destination_table_clustered]

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.

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
Copy Markdown
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]

Comment threadsamples/load_table_clustered.py Outdated
source_format=bigquery.SourceFormat.CSV,
)

with open(file_path, "rb") as source_file:

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.

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

snippet-botBot commented Nov 4, 2020

Copy link
Copy Markdown

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.

@tswasttswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@tswasttswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@tswasttswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 4, 2020
@ryanyuan

Copy link
Copy Markdown
ContributorAuthor

@tswast thanks for the review and changes.

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

@engelkeengelke left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM.

@tswasttswast 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-kokoroyoshi-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-greenBot merged commit 809e4a2 into googleapis:masterNov 17, 2020
@gcf-merge-on-greengcf-merge-on-greenBot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 17, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis human has signed the Contributor License Agreement.samplesIssues 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

@ryanyuan@engelke@tswast@yoshi-kokoro