-
Notifications
You must be signed in to change notification settings - Fork 6.5k
BigQuery: Updates samples for BigQuery Beta 2 (do not merge until release) #1178
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM. I know you are in class now, so I'll address most of these comments in a new commit to the branch.
job_name = str(uuid.uuid4()) | ||
dataset_ref = bigquery_client.dataset(dataset_id) | ||
table_ref = dataset_ref.table(table_id) | ||
job_id = str(uuid.uuid4()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
job_id
is optional now that the client library can generate it, so probably can be removed from this sample
job_name = str(uuid.uuid4()) | ||
dataset_ref = bigquery_client.dataset(dataset_id) | ||
table_ref = dataset_ref.table(table_id) | ||
job_id = str(uuid.uuid4()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this job_id generation.
] | ||
job_config = bigquery.QueryJobConfig() | ||
job_config.query_parameters = query_params | ||
job_id = str(uuid.uuid4()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this job_id, too.
job_config.query_parameters = query_params | ||
job_id = str(uuid.uuid4()) | ||
query_job = client.query(query, job_config=job_config, job_id=job_id) | ||
|
||
query_job.result() # Wait for job to complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the return value for result instead of getting the table after this.
job_config.query_parameters = query_params | ||
job_id = str(uuid.uuid4()) | ||
query_job = client.query(query, job_config=job_config, job_id=job_id) | ||
|
||
query_job.result() # Wait for job to complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the rows from the return value for result here.
job_config.query_parameters = query_params | ||
query_job = client.query(query, job_config=job_config, job_id=job_id) | ||
|
||
query_job.result() # Waits for job to complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return value from result.
bigquery.ScalarQueryParameter('y', 'STRING', y) | ||
) | ||
] | ||
job_id = str(uuid.uuid4()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let the client library generate the job ID.
job_config.query_parameters = query_params | ||
query_job = client.query(query, job_config=job_config, job_id=job_id) | ||
|
||
query_job.result() # Waits for job to complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return value from result.
for row in destination_table.fetch_data(): | ||
print(row) | ||
for row in results: | ||
print("{}: {}".format(row.title, row.unique_words)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! It's much nicer to show accessing the specific columns in this sample.
bigquery/cloud-client/snippets.py
Outdated
|
||
# Load at most 25 results. | ||
rows = itertools.islice(table.fetch_data(), 25) | ||
rows = itertools.islice(bigquery_client.list_rows(table), 25) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can actually pass max_results
to list_rows
now.
Use max_results in list_rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I reviewed a second too soon. I see you've addressed the job_id and result changes. Thanks!
…of outdated 'publicdata'
…ease) [(googleapis#1178)](GoogleCloudPlatform/python-docs-samples#1178) * updates client.extract_table() sample * updates client.load_table_from_file() sample * updates client.load_table_from_uri() sample * updates parameterized query samples * updates query samples * updates dataset quickstart * fixes typo in sample * updates simple app sample * updates snippets * updates stream data sample * updates user credentials sample * removes job_id generation * Update BQ lib to 0.28.0. Use max_results in list_rows. * updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata' * updates readme and help sections
…ease) [(googleapis#1178)](GoogleCloudPlatform/python-docs-samples#1178) * updates client.extract_table() sample * updates client.load_table_from_file() sample * updates client.load_table_from_uri() sample * updates parameterized query samples * updates query samples * updates dataset quickstart * fixes typo in sample * updates simple app sample * updates snippets * updates stream data sample * updates user credentials sample * removes job_id generation * Update BQ lib to 0.28.0. Use max_results in list_rows. * updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata' * updates readme and help sections
…ease) [(#1178)](GoogleCloudPlatform/python-docs-samples#1178) * updates client.extract_table() sample * updates client.load_table_from_file() sample * updates client.load_table_from_uri() sample * updates parameterized query samples * updates query samples * updates dataset quickstart * fixes typo in sample * updates simple app sample * updates snippets * updates stream data sample * updates user credentials sample * removes job_id generation * Update BQ lib to 0.28.0. Use max_results in list_rows. * updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata' * updates readme and help sections
No description provided.