Skip to content

BigQuery: Allow using TableListItem to create a Table #8096

@max-sixty

Description

@max-sixty

Is your feature request related to a problem? Please describe.

Currently a TableListItem can't be supplied to the Table constructor

In [1]: from google.cloud import bigquery

In [2]: c = bigquery.Client()
/usr/local/lib/python3.6/site-packages/google/auth/_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
/usr/local/lib/python3.6/site-packages/google/auth/_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)

In [3]: c.list_tables('sixty')
Out[3]: <google.api_core.page_iterator.HTTPIterator at 0x7fb5ac642e48>

In [4]: tables = list(c.list_tables('sixty'))

In [5]: tables
Out[5]:
[<google.cloud.bigquery.table.TableListItem at 0x7fb5ae747048>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb5ae747240>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb5ae7470f0>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb5ae7477f0>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb5ae747e80>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb5ae747c88>,
 <google.cloud.bigquery.table.TableListItem at 0x7fb554282710>]

In [6]: c.get_table(tables[0])
Out[6]: Table(TableReference(DatasetReference('sixty-capital', 'sixty'), 'equities'))

In [7]: bigquery.Table(tables[0])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-ac46513e6958> in <module>
----> 1 bigquery.Table(tables[0])

/usr/local/lib/python3.6/site-packages/google/cloud/bigquery/table.py in __init__(self, table_ref, schema)
    365         if isinstance(table_ref, six.string_types):
    366             table_ref = TableReference.from_string(table_ref)
--> 367         self._properties = {"tableReference": table_ref.to_api_repr(), "labels": {}}
    368         # Let the @property do validation.
    369         if schema is not None:

AttributeError: 'TableListItem' object has no attribute 'to_api_repr'

Describe the solution you'd like

Table can take a reference, a string, a TableListItem, anything that could be a Table - overall either unify the types or make conversions between them implicit

The python BigQuery API has got waaay better, but I still find myself looking at the API docs most times I use it, and it still sometimes feels tethered to the HTTP API (or distant memories of writing Java code :) )

Thank you!

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions