Skip to content

BigQuery: Allow using TableListItem to create a Table #8096

Closed

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!

Activity

  1. added
    api: bigqueryIssues related to the BigQuery API.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on May 22, 2019
  2. tseaver commented on May 22, 2019

    @tseaver
    Contributor

    @tswast Would this be as straightforward as adding TableListItem.to_api_repr (and likely the complementary from_api_repr)?

  3. tswast commented on May 22, 2019

    @tswast
    Contributor

    @max-sixty I'm a little wary of this request, since TableListItem has some but not all properties of Table. Would it be expected that the new Table instance has copied all those values or it's treated purely as a reference?

    Would this be as straightforward as adding TableListItem.to_api_repr (and likely the complementary from_api_repr)?

    I think not quite. If it's just to treat it like we do a reference, I think we'd want to check if we got a TableListItem (or Table?) and set

    table_ref = table_ref.reference
    

    if it is one of those types. (or maybe just if it has a .reference property?)

  4. max-sixty commented on May 23, 2019

    @max-sixty
    ContributorAuthor

    If it's just to treat it like we do a reference, I think we'd want to check if we got a TableListItem (or Table?) and set

    👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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