| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@tswast this is the usage Im going for: https://gist.github.com/jonparrott/cb0ec50b8c70dfb32693fae021659baa |
Sorry, something went wrong.
|
I don't like query_job.result() rows = query_job.results().fetch_data(max_results=10) I'd prefer if it was rows = query_job.result() Also, the query job needs to be calling getQueryResults and checking for jobComplete in the response rather than polling the job state. The reason for this is that getQueryResults will wait for the job to complete or timeout (whichever comes first), whereas get Job returns immediately. |
Sorry, something went wrong.
| retry_on = tenacity.retry_if_result( | ||
| functools.partial(operator.is_not, True)) | ||
| # Use exponential backoff with jitter. | ||
| wait_on = ( |
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 result after #2840 is implemented?
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? |
Sorry, something went wrong.
|
#2840 is already implemented. getQueryResults is preferable because the job polling method adds up to polling_interval milliseconds of latency to get the query results compared to the long-lived request which will return results as soon as they are available. |
Sorry, something went wrong.
|
I'm okay with doing the getQueryResults in a subsequent PR. |
Sorry, something went wrong.
|
@tswast Cool, are you good with this PR as-is then? |
Sorry, something went wrong.
|
Could we make the change where QueryJob.result() returns QueryResults in this PR? |
Sorry, something went wrong.
If not, I'll propose we make that as a breaking change when changing the polling method. |
Sorry, something went wrong.
Yep. Done. Can you try this out and let me know how broken it is? This should work: def async_query(query):
client = bigquery.Client()
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)
for row in rows:
print(row) |
Sorry, something went wrong.
|
@tswast verified that this seems to work: >>> from google.cloud import bigquery
>>> import uuid
>>>
>>> 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)
>>> for row in rows:
... print(row)
...
(1,) |
Sorry, something went wrong.
There was a problem hiding this comment.
I have no real concerns here though I think someone else should have a look?
Sorry, something went wrong.
| 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 |
| api_response = client._connection.api_request( | ||
| method='POST', path='%s/cancel' % (self.path,)) | ||
| self._set_properties(api_response['job']) | ||
| return True |
| # 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: |
|
|
||
| if self.error_result is not None: | ||
| exception = exceptions.GoogleCloudError( | ||
| self.error_result, errors=self.errors) |
| """ | ||
| # Do not refresh is the state is already done, as the job will not | ||
| # change once complete. | ||
| if self.state != 'DONE': |
| return QueryResults.from_query_job(self) | ||
|
|
||
| def results(self): | ||
| """DEPRECATED. |
| 'tableUnavailable': http_client.BAD_REQUEST, | ||
| } | ||
|
|
||
| _FakeResponse = collections.namedtuple('_FakeResponse', ['status']) |
|
|
||
|
|
||
| def _error_result_to_exception(error_result): | ||
| """""" |
| # 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) |
| """ | ||
| return False | ||
| return (self.error_result is not None | ||
| and self.error_result.get('reason') == 'stopped') |
| import unittest | ||
|
|
||
|
|
||
| class TestErrorResultToException(unittest.TestCase): |
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
Sorry, something went wrong.
* 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()
| Back | FazBrowse Home | New Git URL |
Resolves #3556
Towards #3617