Skip to content

Commit 21cf56e

Browse files
emar-kartswast
authored andcommitted
docs(bigquery): standardize comments and formatting in existing code samples (googleapis#9212)
* update samples * comments rephrasing * docs: comments rephrasing
1 parent 6e6cd39 commit 21cf56e

43 files changed

Lines changed: 200 additions & 95 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bigquery/samples/add_empty_column.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ def add_empty_column(client, table_id):
2121
# TODO(developer): Construct a BigQuery client object.
2222
# client = bigquery.Client()
2323

24-
# TODO(developer): Set table_id to the ID of the table to add an empty column.
24+
# TODO(developer): Set table_id to the ID of the table
25+
# to add an empty column.
2526
# table_id = "your-project.your_dataset.your_table_name"
2627

27-
table = client.get_table(table_id)
28+
table = client.get_table(table_id) # Make an API request.
2829

2930
original_schema = table.schema
3031
new_schema = original_schema[:] # creates a copy of the schema
3132
new_schema.append(bigquery.SchemaField("phone", "STRING"))
3233

3334
table.schema = new_schema
34-
table = client.update_table(table, ["schema"]) # API request
35+
table = client.update_table(table, ["schema"]) # Make an API request.
3536

3637
if len(table.schema) == len(original_schema) + 1 == len(new_schema):
3738
print("A new column has been added.")

bigquery/samples/browse_table_data.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def browse_table_data(client, table_id):
2626
# table_id = "your-project.your_dataset.your_table_name"
2727

2828
# Download all rows from a table.
29-
rows_iter = client.list_rows(table_id)
29+
rows_iter = client.list_rows(table_id) # Make an API request.
3030

3131
# Iterate over rows to make the API requests to fetch row data.
3232
rows = list(rows_iter)
@@ -38,10 +38,18 @@ def browse_table_data(client, table_id):
3838
print("Downloaded {} rows from table {}".format(len(rows), table_id))
3939

4040
# Specify selected fields to limit the results to certain columns.
41-
table = client.get_table(table_id)
41+
table = client.get_table(table_id) # Make an API request.
4242
fields = table.schema[:2] # first two columns
4343
rows_iter = client.list_rows(table_id, selected_fields=fields, max_results=10)
4444
rows = list(rows_iter)
4545
print("Selected {} columns from table {}.".format(len(rows_iter.schema), table_id))
4646
print("Downloaded {} rows from table {}".format(len(rows), table_id))
47+
48+
# Print row data in tabular format.
49+
rows = client.list_rows(table, max_results=10)
50+
format_string = "{!s:<16} " * len(rows.schema)
51+
field_names = [field.name for field in rows.schema]
52+
print(format_string.format(*field_names)) # Prints column headers.
53+
for row in rows:
54+
print(format_string.format(*row)) # Prints row data.
4755
# [END bigquery_browse_table]

bigquery/samples/create_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def create_dataset(client, dataset_id):
3333
# Send the dataset to the API for creation.
3434
# Raises google.api_core.exceptions.Conflict if the Dataset already
3535
# exists within the project.
36-
dataset = client.create_dataset(dataset) # API request
36+
dataset = client.create_dataset(dataset) # Make an API request.
3737
print("Created dataset {}.{}".format(client.project, dataset.dataset_id))
3838
# [END bigquery_create_dataset]

bigquery/samples/create_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def create_job(client):
3333
# The client libraries automatically generate a job ID. Override the
3434
# generated ID with either the job_id_prefix or job_id parameters.
3535
job_id_prefix="code_sample_",
36-
) # API request
36+
) # Make an API request.
3737

3838
print("Started job: {}".format(query_job.job_id))
3939
# [END bigquery_create_job]

bigquery/samples/create_routine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def create_routine(client, routine_id):
4040
],
4141
)
4242

43-
routine = client.create_routine(routine)
43+
routine = client.create_routine(routine) # Make an API request.
4444

4545
print("Created routine {}".format(routine.reference))
4646
# [END bigquery_create_routine]

bigquery/samples/create_routine_ddl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def create_routine_ddl(client, routine_id):
3636
)
3737

3838
# Initiate the query to create the routine.
39-
query_job = client.query(sql)
39+
query_job = client.query(sql) # Make an API request.
4040

4141
# Wait for the query to complete.
42-
query_job.result()
42+
query_job.result() # Waits for the job to complete.
4343

4444
print("Created routine {}".format(query_job.ddl_target_routine))
4545
# [END bigquery_create_routine_ddl]

bigquery/samples/create_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create_table(client, table_id):
3030
]
3131

3232
table = bigquery.Table(table_id, schema=schema)
33-
table = client.create_table(table) # API request
33+
table = client.create_table(table) # Make an API request.
3434
print(
3535
"Created table {}.{}.{}".format(table.project, table.dataset_id, table.table_id)
3636
)

bigquery/samples/dataset_exists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def dataset_exists(client, dataset_id):
2222
# dataset_id = "your-project.your_dataset"
2323

2424
try:
25-
client.get_dataset(dataset_id)
25+
client.get_dataset(dataset_id) # Make an API request.
2626
print("Dataset {} already exists".format(dataset_id))
2727
except NotFound:
2828
print("Dataset {} is not found".format(dataset_id))

bigquery/samples/delete_dataset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def delete_dataset(client, dataset_id):
2727

2828
# Use the delete_contents parameter to delete a dataset and its contents
2929
# Use the not_found_ok parameter to not receive an error if the dataset has already been deleted.
30-
client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=True)
30+
client.delete_dataset(
31+
dataset_id, delete_contents=True, not_found_ok=True
32+
) # Make an API request.
3133

3234
print("Deleted dataset '{}'.".format(dataset_id))
3335
# [END bigquery_delete_dataset]

bigquery/samples/delete_dataset_labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def delete_dataset_labels(client, dataset_id):
2525
# TODO(developer): Set dataset_id to the ID of the dataset to fetch.
2626
# dataset_id = "your-project.your_dataset"
2727

28-
dataset = client.get_dataset(dataset_id)
28+
dataset = client.get_dataset(dataset_id) # Make an API request.
2929

3030
# To delete a label from a dataset, set its value to None
3131
dataset.labels["color"] = None
3232

33-
dataset = client.update_dataset(dataset, ["labels"])
33+
dataset = client.update_dataset(dataset, ["labels"]) # Make an API request.
3434
print("Labels deleted from {}".format(dataset_id))
3535
# [END bigquery_delete_label_dataset]
3636
return dataset

0 commit comments

Comments
 (0)