-
Notifications
You must be signed in to change notification settings - Fork 6.6k
BigQuery: add samples for structs, timestamps, and arrays in query parameters. #730
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
@@ -90,31 +92,115 @@ def sync_query_named_params(corpus, min_word_count): | |||
print_results(query_results) | |||
|
|||
|
|||
def sync_query_array_params(gender, states): | |||
client = bigquery.Client() | |||
query_results = client.run_sync_query( |
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.
For readability, can you make the query it's own variable?
query = """
...
"""
query_results = client.run_sync_query(query, ...)
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.
Done.
@@ -90,31 +94,118 @@ def sync_query_named_params(corpus, min_word_count): | |||
print_results(query_results) | |||
|
|||
|
|||
def sync_query_array_params(gender, states): |
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.
General comment, no action necessary:
These samples seem .. cramped. It might help with readability if you put blank newlines between logical steps:
client = bigquery.Client()
query = """
...
"""
query_results = client.run_sync_query(...)
query_results.use_legacy_sql = False
query_results.run()
print_results(query_results)
All blocking issues have been fixed. This PR should start working after the next release of google-cloud-biguery |
Any updates on this? |
Didn't realize this was still open. I'll update to the latest libs and try it out. @ace-n If you are thinking of using this as an example for the Node.js version, please talk to me first. This sample will be evolving with the BQ client library changes this quarter. |
ebbe21a
to
fc794f3
Compare
I just pushed a change to rebase on latest master. No other changes made. This should be okay to merge as soon as the tests pass. @ace-n Please do not follow this as an example for Node.js. "Synchronous" queries should not be used in new samples. I'm waiting on some changes to the Python libraries before I can clean all these up to follow best practices. |
@dpebot merge when green |
Okay! I'll merge when all statuses are green and all reviewers approve. |
Travis failure seems like it's a problem in the veneer libs for encoding timestamps. |
- query using an array value as a parameter. - query using timestamps in named parameters. See: https://cloud.google.com/bigquery/querying-data#using_timestamps_in_parameterized_queries - query using a struct in query parameters.
I did some updates to debug what's going on. I think the backend API behavior has changed since those blocking bugs were closed (ugh). All the tests for these new samples are failing.
I'm starting a thread with the BQ eng folks. |
D'oh. The reason it was failing is that I hadn't updated the samples to the latest version of google-cloud-python. Has dpebot not been updating? |
Just fixed him.
…On Mon, Apr 24, 2017 at 11:09 AM Tim Swast ***@***.***> wrote:
D'oh. The reason it was failing is that I hadn't updated the samples to
the latest version of google-cloud-python. Has dpebot not been updating?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#730 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPUc7A4X2EKDplNj4EYHWUTFwXAuzByks5rzOVFgaJpZM4LRWR1>
.
|
Update to latest version of google-cloud-bigquery.
Thanks. @jonparrott The test failure looks like it's a flake with list_projects, unrelated to this change. Okay to merge? |
def query_positional_params(corpus, min_word_count): | ||
client = bigquery.Client() | ||
query = """SELECT word, word_count | ||
FROM `bigquery-public-data.samples.shakespeare` |
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.
Indent this by one, and move the SELECT into the heredoc (throughout, please).
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.
Done.
# in the query). Note that you cannot mix named and positional | ||
# parameters. | ||
None, | ||
'STRING', |
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.
It doesn't seem necessary to break these into lines, you an just put None, 'STRING', corpus
on the same line.
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.
Done.
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.
Looks (mostly) good.
Currently none of these work.
Blocked by:
BigQuery: request object not populated correctly for array query parameters googleapis/google-cloud-python#2862BigQuery: timestamps not populated correctly for parameterized queries googleapis/google-cloud-python#2886BigQuery: structs not populated correctly in query parameters googleapis/google-cloud-python#2887