| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Holds name, type, and value for scalar query parameters, and handles marshalling them to / from JSON representation mandated by the BigQuery API. Toward #2551.
Holds name, type, and value for array query parameters, and handles marshalling them to / from JSON representation mandated by the BigQuery API. Toward #2551.
Holds name, types, and values for Struct query parameters, and handles marshalling them to / from JSON representation mandated by the BigQuery API. Toward #2551.
It is just a list comprehension, really.
| 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 |
| """Named / positional query parameters for scalar values. | ||
|
|
||
| :type name: str or None | ||
| :param name: Parameter name, used via `@foo` syntax. If None, the |
| @classmethod | ||
| def positional(cls, type_, value): | ||
| """Factory for positional paramters. | ||
|
|
| :param value: the scalar parameter value. | ||
|
|
||
| :rtype: :class:`ScalarQueryParameter` | ||
| :returns: instance w/o name |
| """Factory for positional paramters. | ||
|
|
||
| :type sub_parms: tuple of :class:`ScalarQueryParameter` | ||
| :param sub_parms:s the sub-parameters for the struct |
|
|
||
| @staticmethod | ||
| def _get_target_class(): | ||
| from google.cloud.bigquery._helpers import AbstractQueryParameter |
| """Named / positional query parameters for scalar values. | ||
|
|
||
| :type name: str or None | ||
| :param name: Parameter name, used via `@foo` syntax. If None, the |
| class ScalarQueryParameter(object): | ||
| """Named / positional query parameters for scalar values. | ||
|
|
||
| :type name: str or None |
|
|
||
| :type name: str or None | ||
| :param name: Parameter name, used via `@foo` syntax. If None, the | ||
| paramter can only be addressed via position (`?`). |
| """ | ||
| name = resource.get('name') | ||
| type_ = resource['parameterType']['type'] | ||
| value = resource['parameterValue']['value'] |
| :class:`datetime.date`. | ||
| :param value: the scalar parameter value. | ||
| """ | ||
| def __init__(self, name, type_, value): |
| query_parameter.to_api_repr() | ||
| for query_parameter in self._query_parameters | ||
| ] | ||
| if self._query_parameters[0].name is None: |
| else: | ||
| self.assertIsNone(job.maximum_bytes_billed) | ||
|
|
||
| def _verifyUDFResources(self, job, config): |
| 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 |
| if token is None: | ||
| break | ||
| jobs, token = client.list_jobs(page_token=token) # API request | ||
| job_iterator = client.list_jobs() # API request |
|
|
||
| @snippet | ||
| def client_run_sync_query_w_param(client, _): | ||
| """Run a synchronous query using a query parameter""" |
|
|
||
| :type type_: str | ||
| :param type_: name of parameter type. One of `'STRING'`, `'INT64'`, | ||
| `'FLOAT64'`, `'BOOLEAN'`, `'TIMESTAMP'`, or `'DATE'`. |
The back-end raises an exception when passed the 'BOOLEAN' type to define a query parameter. Addresses: #2776 (comment)
| {'name': name, 'type': self.struct_types[name]} | ||
| for name in self._order | ||
| {'name': key, 'type': value} | ||
| for key, value in self.struct_types.items() |
| the class). | ||
|
|
||
| :type value: list of instances of classes derived from | ||
| :class:`AbstractQueryParameter`. |
There was a problem hiding this comment.
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.
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') |
Sorry, something went wrong.
* 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.
|
does this mean we can use @parameters in the BigQuery UI ?? I cant seem to figure out how to declare them correctly. |
Sorry, something went wrong.
|
@avitzavi I'm not sure what you are asking. Does the example in the docs help? |
Sorry, something went wrong.
|
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.
|
Sorry, something went wrong.
|
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? |
Sorry, something went wrong.
|
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.
|
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Closes #2551.