-
Notifications
You must be signed in to change notification settings - Fork 322
feat: add job_id, location, project, and query_id properties on RowIterator
#1733
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1558,6 +1558,10 @@ def __init__( | |
| selected_fields=None, | ||
| total_rows=None, | ||
| first_page_response=None, | ||
| location: Optional[str] = None, | ||
| job_id: Optional[str] = None, | ||
| query_id: Optional[str] = None, | ||
| project: Optional[str] = None, | ||
| ): | ||
| super(RowIterator, self).__init__( | ||
| client, | ||
|
|
@@ -1575,12 +1579,51 @@ def __init__( | |
| self._field_to_index = _helpers._field_to_index_mapping(schema) | ||
| self._page_size = page_size | ||
| self._preserve_order = False | ||
| self._project = client.project if client is not None else None | ||
| self._schema = schema | ||
| self._selected_fields = selected_fields | ||
| self._table = table | ||
| self._total_rows = total_rows | ||
| self._first_page_response = first_page_response | ||
| self._location = location | ||
| self._job_id = job_id | ||
| self._query_id = query_id | ||
| self._project = project | ||
|
|
||
| @property | ||
| def _billing_project(self) -> Optional[str]: | ||
| """GCP Project ID where BQ API will bill to (if applicable).""" | ||
| client = self.client | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder what's the difference between
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference in other contexts is usually described as "billing project" versus "data project". I've renamed this private property to reflect that. This is easiest to understand in the context of public datasets. I have permission to query tables in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow I see! so
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, though for queries we're using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return client.project if client is not None else None | ||
|
|
||
| @property | ||
| def job_id(self) -> Optional[str]: | ||
| """ID of the query job (if applicable). | ||
|
|
||
| To get the job metadata, call | ||
| ``job = client.get_job(rows.job_id, location=rows.location)``. | ||
| """ | ||
| return self._job_id | ||
|
|
||
| @property | ||
| def location(self) -> Optional[str]: | ||
| """Location where the query executed (if applicable). | ||
|
|
||
| See: https://cloud.google.com/bigquery/docs/locations | ||
| """ | ||
| return self._location | ||
|
|
||
| @property | ||
| def project(self) -> Optional[str]: | ||
| """GCP Project ID where these rows are read from.""" | ||
| return self._project | ||
|
|
||
| @property | ||
| def query_id(self) -> Optional[str]: | ||
| """[Preview] ID of a completed query. | ||
|
|
||
| This ID is auto-generated and not guaranteed to be populated. | ||
| """ | ||
| return self._query_id | ||
|
|
||
| def _is_completely_cached(self): | ||
| """Check if all results are completely cached. | ||
|
|
@@ -1723,7 +1766,7 @@ def to_arrow_iterable( | |
|
|
||
| bqstorage_download = functools.partial( | ||
| _pandas_helpers.download_arrow_bqstorage, | ||
| self._project, | ||
| self._billing_project, | ||
| self._table, | ||
| bqstorage_client, | ||
| preserve_order=self._preserve_order, | ||
|
|
@@ -1903,7 +1946,7 @@ def to_dataframe_iterable( | |
| column_names = [field.name for field in self._schema] | ||
| bqstorage_download = functools.partial( | ||
| _pandas_helpers.download_dataframe_bqstorage, | ||
| self._project, | ||
| self._billing_project, | ||
| self._table, | ||
| bqstorage_client, | ||
| column_names, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2113,6 +2113,38 @@ def test_constructor_with_dict_schema(self): | |
| ] | ||
| self.assertEqual(iterator.schema, expected_schema) | ||
|
|
||
| def test_job_id_missing(self): | ||
| rows = self._make_one() | ||
| self.assertIsNone(rows.job_id) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious about testing philosophy.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I matched the existing pattern in this test. I do think we could probably combine a lot of these into a single parametrized test. I worry slightly about the required |
||
|
|
||
| def test_job_id_present(self): | ||
| rows = self._make_one(job_id="abc-123") | ||
| self.assertEqual(rows.job_id, "abc-123") | ||
|
|
||
| def test_location_missing(self): | ||
| rows = self._make_one() | ||
| self.assertIsNone(rows.location) | ||
|
|
||
| def test_location_present(self): | ||
| rows = self._make_one(location="asia-northeast1") | ||
| self.assertEqual(rows.location, "asia-northeast1") | ||
|
|
||
| def test_project_missing(self): | ||
| rows = self._make_one() | ||
| self.assertIsNone(rows.project) | ||
|
|
||
| def test_project_present(self): | ||
| rows = self._make_one(project="test-project") | ||
| self.assertEqual(rows.project, "test-project") | ||
|
|
||
| def test_query_id_missing(self): | ||
| rows = self._make_one() | ||
| self.assertIsNone(rows.query_id) | ||
|
|
||
| def test_query_id_present(self): | ||
| rows = self._make_one(query_id="xyz-987") | ||
| self.assertEqual(rows.query_id, "xyz-987") | ||
|
|
||
| def test_iterate(self): | ||
| from google.cloud.bigquery.schema import SchemaField | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.