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
bigquery: add Client.list_rows, remove Table.fetch_data#4119
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
File 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 |
|---|---|---|
| @@ -26,14 +26,16 @@ | ||
| from google.cloud.bigquery._http import Connection | ||
| from google.cloud.bigquery.dataset import Dataset | ||
| from google.cloud.bigquery.dataset import DatasetReference | ||
| from google.cloud.bigquery.table import Table | ||
| from google.cloud.bigquery.table import Table, _TABLE_HAS_NO_SCHEMA | ||
| from google.cloud.bigquery.table import TableReference | ||
| from google.cloud.bigquery.job import CopyJob | ||
| from google.cloud.bigquery.job import ExtractJob | ||
| from google.cloud.bigquery.job import LoadJob | ||
| from google.cloud.bigquery.job import QueryJob | ||
| from google.cloud.bigquery.job import QueryJobConfig | ||
| from google.cloud.bigquery.query import QueryResults | ||
| from google.cloud.bigquery._helpers import _item_to_row | ||
| from google.cloud.bigquery._helpers import _rows_page_start | ||
| class Project(object): | ||
| @@ -346,7 +348,6 @@ def delete_table(self, table): | ||
| :type table: One of: | ||
| :class:`~google.cloud.bigquery.table.Table` | ||
| :class:`~google.cloud.bigquery.table.TableReference` | ||
| :param table: the table to delete, or a reference to it. | ||
| """ | ||
| if not isinstance(table, (Table, TableReference)): | ||
| @@ -667,6 +668,80 @@ def query_rows(self, query, job_config=None, job_id=None, timeout=None): | ||
| job.begin() | ||
| return job.result(timeout=timeout) | ||
| def list_rows(self, table, selected_fields=None, max_results=None, | ||
| page_token=None, start_index=None): | ||
| """List the rows of the table. | ||
| See | ||
| https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/list | ||
| .. note:: | ||
| This method assumes that the provided schema is up-to-date with the | ||
| schema as defined on the back-end: if the two schemas are not | ||
| identical, the values returned may be incomplete. To ensure that the | ||
| local copy of the schema is up-to-date, call ``client.get_table``. | ||
| :type table: One of: | ||
| :class:`~google.cloud.bigquery.table.Table` | ||
| :class:`~google.cloud.bigquery.table.TableReference` | ||
| :param table: the table to list, or a reference to it. | ||
| :type selected_fields: list of :class:`SchemaField` | ||
| :param selected_fields: | ||
| The fields to return. Required if ``table`` is a | ||
| :class:`~google.cloud.bigquery.table.TableReference`. | ||
| :type max_results: int | ||
| :param max_results: maximum number of rows to return. | ||
| :type page_token: str | ||
| :param page_token: (Optional) Token representing a cursor into the | ||
| table's rows. | ||
| :type start_index: int | ||
| :param page_token: (Optional) The zero-based index of the starting | ||
| row to read. | ||
| :rtype: :class:`~google.api.core.page_iterator.Iterator` | ||
| :returns: Iterator of row data :class:`tuple`s. During each page, the | ||
| iterator will have the ``total_rows`` attribute set, | ||
| which counts the total number of rows **in the table** | ||
| (this is distinct from the total number of rows in the | ||
| current page: ``iterator.page.num_items``). | ||
| """ | ||
| if selected_fields is not None: | ||
| schema = selected_fields | ||
| elif isinstance(table, TableReference): | ||
| raise ValueError('need selected_fields with TableReference') | ||
| elif isinstance(table, Table): | ||
| if len(table._schema) == 0: | ||
| raise ValueError(_TABLE_HAS_NO_SCHEMA) | ||
| schema = table.schema | ||
| else: | ||
| raise TypeError('table should be Table or TableReference') | ||
| params = {} | ||
| if selected_fields is not None: | ||
| params['selectedFields'] = [f.name for f in selected_fields] | ||
| if start_index is not None: | ||
| params['startIndex'] = start_index | ||
| iterator = page_iterator.HTTPIterator( | ||
| client=self, | ||
| api_request=self._connection.api_request, | ||
| path='%s/data' % (table.path,), | ||
| item_to_value=_item_to_row, | ||
| items_key='rows', | ||
| page_token=page_token, | ||
| next_token='pageToken', | ||
| max_results=max_results, | ||
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.
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.
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. | ||
| page_start=_rows_page_start, | ||
| extra_params=params) | ||
| iterator.schema = schema | ||
| return iterator | ||
| # pylint: disable=unused-argument | ||
| def _item_to_project(iterator, resource): | ||
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.