Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Add 'QueryJob.results' method#2321
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fb31f5c5c630fa9307d7e4cd0aa4ef7b499File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -172,3 +172,55 @@ def _validate(self, value): | ||
| """ | ||
| if value not in self.ALLOWED: | ||
| raise ValueError('Pass one of: %s' ', '.join(self.ALLOWED)) | ||
| class UDFResource(object): | ||
| """Describe a single user-defined function (UDF) resource. | ||
| :type udf_type: str | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| :param udf_type: the type of the resource ('inlineCode' or 'resourceUri') | ||
| :type value: str | ||
| :param value: the inline code or resource URI. | ||
| See | ||
| https://cloud.google.com/bigquery/user-defined-functions#api | ||
| """ | ||
| def __init__(self, udf_type, value): | ||
| self.udf_type = udf_type | ||
| self.value = value | ||
| def __eq__(self, other): | ||
| return( | ||
| self.udf_type == other.udf_type and | ||
| self.value == other.value) | ||
| class UDFResourcesProperty(object): | ||
| """Custom property type, holding :class:`UDFResource` instances.""" | ||
| def __get__(self, instance, owner): | ||
| """Descriptor protocol: accessor""" | ||
| if instance is None: | ||
| return self | ||
| return list(instance._udf_resources) | ||
| def __set__(self, instance, value): | ||
| """Descriptor protocol: mutator""" | ||
| if not all(isinstance(u, UDFResource) for u in value): | ||
| raise ValueError("udf items must be UDFResource") | ||
| instance._udf_resources = tuple(value) | ||
| def _build_udf_resources(resources): | ||
| """ | ||
| :type resources: sequence of :class:`UDFResource` | ||
| :param resources: fields to be appended. | ||
| :rtype: mapping | ||
| :returns: a mapping describing userDefinedFunctionResources for the query. | ||
| """ | ||
| udfs = [] | ||
| for resource in resources: | ||
| udf = {resource.udf_type: resource.value} | ||
| udfs.append(udf) | ||
| return udfs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,9 +20,9 @@ | ||
| from google.cloud.bigquery._helpers import _rows_from_json | ||
| from google.cloud.bigquery.dataset import Dataset | ||
| from google.cloud.bigquery.job import QueryJob | ||
| from google.cloud.bigquery.job import UDFResourcesProperty | ||
| from google.cloud.bigquery.job import _build_udf_resources | ||
| from google.cloud.bigquery.table import _parse_schema_resource | ||
| from google.cloud.bigquery._helpers import _build_udf_resources | ||
| from google.cloud.bigquery._helpers import UDFResourcesProperty | ||
| class _SyncQueryConfiguration(object): | ||
| @@ -65,6 +65,26 @@ def __init__(self, query, client, udf_resources=()): | ||
| self.udf_resources = udf_resources | ||
| self._job = None | ||
| @classmethod | ||
| def from_query_job(cls, job): | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| """Factory: construct from an existing job. | ||
| :type job: :class:`~google.cloud.bigquery.job.QueryJob` | ||
| :param job: existing job | ||
| :rtype: :class:`QueryResults` | ||
| :returns: the instance, bound to the job | ||
| """ | ||
| instance = cls(job.query, job._client, job.udf_resources) | ||
| instance._job = job | ||
| if job.default_dataset is not None: | ||
| instance.default_dataset = job.default_dataset | ||
| if job.use_query_cache is not None: | ||
| instance.use_query_cache = job.use_query_cache | ||
| if job.use_legacy_sql is not None: | ||
| instance.use_legacy_sql = job.use_legacy_sql | ||
| return instance | ||
| @property | ||
| def project(self): | ||
| """Project bound to the job. | ||
| @@ -307,6 +327,9 @@ def run(self, client=None): | ||
| :param client: the client to use. If not passed, falls back to the | ||
| ``client`` stored on the current dataset. | ||
| """ | ||
| if self._job is not None: | ||
| raise ValueError("Query job is already running.") | ||
| client = self._require_client(client) | ||
| path = '/projects/%s/queries' % (self.project,) | ||
| api_response = client.connection.api_request( | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.