GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add support for query parameters by tseaver · Pull Request #2776 · googleapis/google-cloud-python

Conversation

@tseaver

@tseaver tseaver commented Nov 29, 2016

Copy link
Copy Markdown
Contributor

Closes #2551.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daspecster reacted with thumbs up emoji daspecster and tswast reacted with hooray emoji
All reactions
  • 👍 1 reaction
  • 🎉 2 reactions
tseaver added 10 commits November 28, 2016 16:50
@tseaver
Add 'ScalarQueryParameter' class.
128db62
Holds name, type, and value for scalar query parameters, and handles
marshalling them to / from JSON representation mandated by the BigQuery API.

Toward #2551.
@tseaver
Factor out 'AbstractQueryParameter.
3421d7a
@tseaver
Add 'ArrayQueryParameter' class.
57c61c1
Holds name, type, and value for array query parameters, and handles
marshalling them to / from JSON representation mandated by the BigQuery API.

Toward #2551.
@tseaver
Add 'StructQueryParameter' class.
6650c59
Holds name, types, and values for Struct query parameters, and handles
marshalling them to / from JSON representation mandated by the BigQuery API.

Toward #2551.
@tseaver
Remove '_build_udf_resources' helper.
fcff570
It is just a list comprehension, really.
@tseaver
Add 'QueryParametersProperty' descriptor class.
2e06228
@tseaver
Add 'query_parameters' property to 'QueryResults' and 'QueryJob'.
968582f
@tseaver
Plumb 'udf_resources'/'query_parameters' through client query factories.
52b25ec
@tseaver
Expose concrete query parameter classes as package APIs.
9089907
@tseaver
Add a snippet documenting use of query parameters.
9fd7f76
@tseaver tseaver added the api: bigquery Issues related to the BigQuery API. label Nov 29, 2016
@tseaver tseaver assigned daspecster and dhermes Nov 29, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 29, 2016
daspecster
daspecster reviewed Nov 29, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/__init__.py Outdated
from google.cloud.bigquery.dataset import Dataset
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.table import Table
from google.cloud.bigquery._helpers import ArrayQueryParameter

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
"""Named / positional query parameters for scalar values.

:type name: str or None
:param name: Parameter name, used via `@foo` syntax. If None, the

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py
@classmethod
def positional(cls, type_, value):
"""Factory for positional paramters.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
:param value: the scalar parameter value.

:rtype: :class:`ScalarQueryParameter`
:returns: instance w/o name

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daspecster
daspecster reviewed Nov 29, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
"""Factory for positional paramters.

:type sub_parms: tuple of :class:`ScalarQueryParameter`
:param sub_parms:s the sub-parameters for the struct

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/unit_tests/test__helpers.py

@staticmethod
def _get_target_class():
from google.cloud.bigquery._helpers import AbstractQueryParameter

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
Address code review.
1df82a0
dhermes
dhermes reviewed Nov 29, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
"""Named / positional query parameters for scalar values.

:type name: str or None
:param name: Parameter name, used via `@foo` syntax. If None, the

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py
class ScalarQueryParameter(object):
"""Named / positional query parameters for scalar values.

:type name: str or None

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated

:type name: str or None
:param name: Parameter name, used via `@foo` syntax. If None, the
paramter can only be addressed via position (`?`).

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py
"""
name = resource.get('name')
type_ = resource['parameterType']['type']
value = resource['parameterValue']['value']

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py
:class:`datetime.date`.
:param value: the scalar parameter value.
"""
def __init__(self, name, type_, value):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/job.py
query_parameter.to_api_repr()
for query_parameter in self._query_parameters
]
if self._query_parameters[0].name is None:

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/unit_tests/test_job.py Outdated
else:
self.assertIsNone(job.maximum_bytes_billed)

def _verifyUDFResources(self, job, config):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/unit_tests/test_job.py Outdated
def test_begin_w_named_query_parameter(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter
query_parameters = [ScalarQueryParameter('foo', 'INT64', 123)]
PATH = 'projects/%s/jobs' % self.PROJECT

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/bigquery_snippets.py Outdated
if token is None:
break
jobs, token = client.list_jobs(page_token=token) # API request
job_iterator = client.list_jobs() # API request

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/bigquery_snippets.py

@snippet
def client_run_sync_query_w_param(client, _):
"""Run a synchronous query using a query parameter"""

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daspecster daspecster added the PR: Needs to be squashed label Nov 29, 2016
tseaver added 5 commits November 30, 2016 10:58
@tseaver
Document expected types for QueryParametersProperty setter/getter.
6191ca6
Addresses:
#2776 (comment)
@tseaver
Use 'collections.OrderedDict' vs. hand-rolling order.
89f5a58
Addresses:
#2776 (comment).
@tseaver
PEP8.
a4ff964
Addresses:
#2776 (comment).
@tseaver
Correct notation of where API requests occur.
d4d451e
Addresses: #2776 (comment)
@tseaver
s/parm/param/.
0f61970
Addresses:
#2776 (comment)
@tseaver tseaver mentioned this pull request Nov 30, 2016
BigQuery: Add support for query parameters #2551
Closed
blowmage
blowmage reviewed Dec 1, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated

:type type_: str
:param type_: name of parameter type. One of `'STRING'`, `'INT64'`,
`'FLOAT64'`, `'BOOLEAN'`, `'TIMESTAMP'`, or `'DATE'`.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request Dec 1, 2016
Add support for standard SQL 'BOOL' type. #2789
Merged
@tseaver
Update docstring to show standard-SQL 'BOOL' type.
524baf1
The back-end raises an exception when passed the 'BOOLEAN' type to define
a query parameter.

Addresses:
#2776 (comment)
@danoscarmike danoscarmike mentioned this pull request Dec 1, 2016
bigquery: support SQL parameters googleapis/google-cloud-node#1787
Closed
dhermes
dhermes reviewed Dec 2, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/_helpers.py
{'name': name, 'type': self.struct_types[name]}
for name in self._order
{'name': key, 'type': value}
for key, value in self.struct_types.items()

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
the class).

:type value: list of instances of classes derived from
:class:`AbstractQueryParameter`.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver added 3 commits December 2, 2016 14:41
@tseaver
Indentation fix.
4b2cb13
@tseaver
Preserve OrderedDict for struct_types.
99bdcd1
Addresses:
#2776 (comment).
@tseaver
Normalize '%' formatting.
132741a
Addresses:
#2776 (comment).
dhermes
dhermes approved these changes Dec 2, 2016
View reviewed changes

@dhermes dhermes left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM, though I don't understand why you'd have the constructor and the API rep so far apart, especially if no human is every going to use the constructor

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tseaver

tseaver commented Dec 2, 2016

Copy link
Copy Markdown
Contributor Author

especially if no human is every going to use the constructor

I do expect humans to use the constructor, e.g.:

from google.cloud.bigquery import Client
from google.cloud.bigquery import ScalarQueryParameter
from google.cloud.bigquery import StructQueryParameter


birth_state = ScalarQueryParameter('birth_state', 'STRING', 'VA')
death_state = ScalarQueryParameter('death_state', 'STRING', 'MS')
birth_death = StructQueryParameter(
    'birth_death', birth_state, death_state)

client = Client()

query = client.run_sync_query(
    'SELECT * FROM mortality WHERE birth_death = @birth_death')
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
tseaver merged commit 75c4115 into googleapis:master Dec 2, 2016
@tseaver
tseaver deleted the 2551-bigquery-query_parameters branch December 2, 2016 22:52
@tseaver tseaver removed the PR: Needs to be squashed label Dec 2, 2016
@dhermes dhermes mentioned this pull request Dec 5, 2016
Cutting new releases for BigQuery, Language and Core. #2815
Merged
@tswast tswast mentioned this pull request Dec 5, 2016
BigQuery samples using query parameters. GoogleCloudPlatform/python-docs-samples#699
Merged
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
@tseaver
Add support for query parameters (googleapis#2776)
92e5119
* Add 'ScalarQueryParameter' class.

  Holds name, type, and value for scalar query parameters, and handles
  marshalling them to / from JSON representation mandated by the BigQuery API.

* Factor out 'AbstractQueryParameter.

* Add 'ArrayQueryParameter' class.

  Holds name, type, and value for array query parameters, and handles
  marshalling them to / from JSON representation mandated by the BigQuery API.

* Add 'StructQueryParameter' class.

  Holds name, types, and values for Struct query parameters, and handles
  marshalling them to / from JSON representation mandated by the BigQuery API.

* Add 'QueryParametersProperty' descriptor class.

* Add 'query_parameters' property to 'QueryResults' and 'QueryJob'.

* Plumb 'udf_resources'/'query_parameters' through client query factories.

* Expose concrete query parameter classes as package APIs.

Closes googleapis#2551.
@theacodes theacodes unassigned daspecster and dhermes Sep 28, 2018
@avitzavi

avitzavi commented Oct 31, 2018

Copy link
Copy Markdown

does this mean we can use @parameters in the BigQuery UI ?? I cant seem to figure out how to declare them correctly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

@avitzavi I'm not sure what you are asking. Does the example in the docs help?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avitzavi

avitzavi commented Oct 31, 2018 via email

Copy link
Copy Markdown
I’m trying to use variables like I do in sql server: “Declare @variable INT = 10” Can I do this in the BigQuery UI?
…
On Oct 31, 2018, at 2:25 PM, Tres Seaver ***@***.***> wrote: @avitzavi I'm not sure what you are asking. Does the example in the docs help? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

The @parameter placeholders added by this PR are used for passing in values from the client to be substituted into a query: they aren't meant to be used that way.

Also, I don't know what you mean by "BigQuery UI" -- is that the https://console.cloud.google.com/ interface?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avitzavi

avitzavi commented Oct 31, 2018 via email

Copy link
Copy Markdown
Yes it is the console. The Declare/Set methods from SQL are very valuable for me as a data analyst. Seems like a really big missing feature... I create many reports (based off scheduled queries) and not having these parameters makes it much more challenging to do. Especially given the Console's lack of basic editor features like find/replace.
…
Oct 31, 2018, at 5:30 PM, Tres Seaver ***@***.***> wrote: The @parameter placeholders added by this PR are used for passing in values from the client to be substituted into a query: they aren't meant to be used that way. Also, I don't know what you mean by "BigQuery UI" -- is that the https://console.cloud.google.com/ interface? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

@avitzavi This repository is solely about the Python client libraries which wrap the various Google Cloud APIs. Please check out the BigQuery support page for ways to get support for the back-end API itself.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

3 more reviewers
@blowmage blowmage blowmage left review comments
@daspecster daspecster daspecster left review comments
@dhermes dhermes dhermes approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@tseaver @avitzavi @blowmage @daspecster @dhermes @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.