Uh oh!
There was an error while loading. Please reload this page.
Add Future interface to BigQuery jobs - #3626
Conversation
theacodes
commented
Jul 18, 2017
@tswast this is the usage Im going for: https://gist.github.com/jonparrott/cb0ec50b8c70dfb32693fae021659baa |
tswast
commented
Jul 19, 2017
I don't like I'd prefer if it was Also, the query job needs to be calling getQueryResults and checking for |
| retry_on = tenacity.retry_if_result( | ||
| functools.partial(operator.is_not, True)) | ||
| # Use exponential backoff with jitter. | ||
| wait_on = ( |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
theacodes
commented
Jul 19, 2017
That seems reasonable as long as we don't lose data, but wouldn't that require switching to core iterator (#2840)? Could we accept the non-breaking behavior of this PR as-is for now and do another PR to switch the return value of
Why is that preferable? Doing a long-lived HTTP request is quite different from any of the other behavior in this library. Also, would you be okay with addressing this in a follow-up PR rather than in this one? |
tswast
commented
Jul 19, 2017
#2840 is already implemented.
|
tswast
commented
Jul 19, 2017
I'm okay with doing the |
theacodes
commented
Jul 19, 2017
@tswast Cool, are you good with this PR as-is then? |
tswast
commented
Jul 19, 2017
Could we make the change where |
tswast
commented
Jul 19, 2017
If not, I'll propose we make that as a breaking change when changing the polling method. |
theacodes
commented
Jul 19, 2017
Yep. Done. Can you try this out and let me know how broken it is? This should work: defasync_query(query):
client=bigquery.Client()
query_job=client.run_async_query(str(uuid.uuid4()), query)
query_job.use_legacy_sql=Falserows=query_job.result().fetch_data(max_results=10)
forrowinrows:
print(row) |
theacodes
commented
Jul 19, 2017
@tswast verified that this seems to work: >>>fromgoogle.cloudimportbigquery>>>importuuid>>>>>>client=bigquery.Client()
>>>query='SELECT 1'>>>query_job=client.run_async_query(str(uuid.uuid4()), query)
>>>query_job.use_legacy_sql=False>>>>>>rows=query_job.result().fetch_data(max_results=10)
>>>forrowinrows:
... print(row)
...
(1,) |
dhermes
left a comment
There was a problem hiding this comment.
I have no real concerns here though I think someone else should have a look?
| from google.cloud.bigquery._helpers import UDFResourcesProperty | ||
| from google.cloud.bigquery._helpers import _EnumProperty | ||
| from google.cloud.bigquery._helpers import _TypedProperty | ||
| import google.cloud.future.base |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| api_response = client._connection.api_request( | ||
| method='POST', path='%s/cancel' % (self.path,)) | ||
| self._set_properties(api_response['job']) | ||
| return True |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| # set, do not call set_result/set_exception again. | ||
| # Note: self._result_set is set to True in set_result and | ||
| # set_exception, in case those methods are invoked directly. | ||
| if self.state != 'DONE' or self._result_set: |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| if self.error_result is not None: | ||
| exception = exceptions.GoogleCloudError( | ||
| self.error_result, errors=self.errors) |
This comment was marked as spam.
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.
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.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| """ | ||
| # Do not refresh is the state is already done, as the job will not | ||
| # change once complete. | ||
| if self.state != 'DONE': |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| return QueryResults.from_query_job(self) | ||
| def results(self): | ||
| """DEPRECATED. |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| 'tableUnavailable': http_client.BAD_REQUEST, | ||
| } | ||
| _FakeResponse = collections.namedtuple('_FakeResponse', ['status']) |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| def _error_result_to_exception(error_result): | ||
| """""" |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| # make_exception expects an httplib2 response object. | ||
| fake_response = _FakeResponse(status=status_code) | ||
| return exceptions.make_exception( | ||
| fake_response, b'', error_info=error_result, use_json=False) |
This comment was marked as spam.
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.
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.
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.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| """ | ||
| return False | ||
| return (self.error_result is not None | ||
| and self.error_result.get('reason') == 'stopped') |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| import unittest | ||
| class TestErrorResultToException(unittest.TestCase): |
This comment was marked as spam.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
theacodes
commented
Jul 21, 2017
* Add future interface to bigquery Jobs. * Make QueryJob return QueryResults from result() * Deprecate QueryJob.results()
* Add future interface to bigquery Jobs. * Make QueryJob return QueryResults from result() * Deprecate QueryJob.results()
* Add future interface to bigquery Jobs. * Make QueryJob return QueryResults from result() * Deprecate QueryJob.results()
Resolves#3556
Towards #3617