Skip to content
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

BigQuery: Allow using TableListItem to create a Table #8096

Closed
max-sixty opened this issue May 22, 2019 · 3 comments · Fixed by #8738
Closed

BigQuery: Allow using TableListItem to create a Table #8096

max-sixty opened this issue May 22, 2019 · 3 comments · Fixed by #8738
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@max-sixty
Copy link

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!

@tseaver tseaver added api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 22, 2019
@tseaver
Copy link
Contributor

tseaver commented May 22, 2019

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

@tswast
Copy link
Contributor

tswast commented May 22, 2019

@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?)

@max-sixty
Copy link
Author

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
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants