Skip to content

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

Merged
merged 4 commits into from
Apr 24, 2017

Conversation

@tswast tswast added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 20, 2016
@tswast tswast requested a review from theacodes December 20, 2016 00:53
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 20, 2016
@@ -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(
Copy link
Contributor

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, ...)

Copy link
Contributor Author

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):
Copy link
Contributor

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)

@tswast
Copy link
Contributor Author

tswast commented Jan 4, 2017

All blocking issues have been fixed. This PR should start working after the next release of google-cloud-biguery

@ace-n
Copy link

ace-n commented Apr 10, 2017

Any updates on this?

@tswast
Copy link
Contributor Author

tswast commented Apr 10, 2017

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.

@tswast tswast force-pushed the tswast-bq branch 2 times, most recently from ebbe21a to fc794f3 Compare April 12, 2017 22:22
@tswast tswast removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 12, 2017
@tswast
Copy link
Contributor Author

tswast commented Apr 12, 2017

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.

@tswast
Copy link
Contributor Author

tswast commented Apr 12, 2017

@dpebot merge when green

@dpebot
Copy link
Collaborator

dpebot commented Apr 12, 2017

Okay! I'll merge when all statuses are green and all reviewers approve.

@dpebot dpebot added the automerge Merge the pull request once unit tests and other checks pass. label Apr 12, 2017
@dpebot dpebot self-assigned this Apr 12, 2017
@tswast tswast assigned tswast and unassigned dpebot Apr 13, 2017
@tswast tswast removed the automerge Merge the pull request once unit tests and other checks pass. label Apr 13, 2017
@tswast
Copy link
Contributor Author

tswast commented Apr 13, 2017

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.
@tswast tswast added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 21, 2017
@tswast
Copy link
Contributor Author

tswast commented Apr 21, 2017

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.

query_params_test.py::test_query_array_params FAILED
query_params_test.py::test_query_named_params PASSED
query_params_test.py::test_query_positional_params PASSED
query_params_test.py::test_query_struct_params FAILED
query_params_test.py::test_query_timestamp_params FAILED

I'm starting a thread with the BQ eng folks.

@tswast
Copy link
Contributor Author

tswast commented Apr 24, 2017

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?

@tswast tswast removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 24, 2017
@theacodes
Copy link
Contributor

theacodes commented Apr 24, 2017 via email

Update to latest version of google-cloud-bigquery.
@tswast
Copy link
Contributor Author

tswast commented Apr 24, 2017

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`
Copy link
Contributor

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).

Copy link
Contributor Author

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',
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@theacodes theacodes left a comment

Choose a reason for hiding this comment

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

Looks (mostly) good.

@tswast tswast merged commit dd90f35 into master Apr 24, 2017
@tswast tswast deleted the tswast-bq branch April 24, 2017 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants