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

@ryanyuan ryanyuan commented Oct 18, 2020

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 review from as code owners Oct 18, 2020
@ryanyuan ryanyuan requested a review from engelke Oct 18, 2020
@google-cla google-cla bot added the cla: yes label Oct 18, 2020
Copy link
Contributor

@tswast tswast left a comment

Thanks for the contribution! A couple of nits

Loading


def client_query_destination_table_clustered(table_id):

# [START bigquery_query_destination_table_clustered]
Copy link
Contributor

@tswast tswast Oct 29, 2020

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]

Loading

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

@tswast tswast Oct 29, 2020

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]

Loading

source_format=bigquery.SourceFormat.CSV,
)

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

@tswast tswast Oct 29, 2020

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

Loading

@snippet-bot
Copy link

@snippet-bot snippet-bot bot commented Nov 4, 2020

Loading

tswast
tswast approved these changes Nov 4, 2020
@ryanyuan
Copy link
Contributor Author

@ryanyuan ryanyuan commented Nov 4, 2020

@tswast thanks for the review and changes.

Loading

Copy link

@engelke engelke left a comment

LGTM.

Loading

@gcf-merge-on-green gcf-merge-on-green bot merged commit 809e4a2 into googleapis:master Nov 17, 2020
11 checks passed
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants