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 Python Client v0.28.0: Can't recover {Dataset,Table}References from Dataset or Table objects #4327

Closed
robfraz opened this issue Nov 2, 2017 · 6 comments
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

@robfraz
Copy link

robfraz commented Nov 2, 2017

Hello,

In v0.28.0 of the BigQuery Python Client, it doesn't seem possible to recover the original DatasetReference or TableReference used to create the the Dataset or Table, thus preventing any part of the API (or a user's application) that requires a reference to also take the Dataset or Table object. It seems the reference used in creating the Dataset or Table is lost on object creation [1][2].

For example, in the client.load_table_from_file() function [3], a table_ref is expected; it seems logically unreasonable that a full Table object can't be used to fulfil the need for a table reference.

Cheers,
Rob

[1] https://github.com/GoogleCloudPlatform/google-cloud-python/blob/0.28.0/bigquery/google/cloud/bigquery/table.py#L170-L177
[2] https://github.com/GoogleCloudPlatform/google-cloud-python/blob/0.28.0/bigquery/google/cloud/bigquery/dataset.py#L204-L208
[3] https://github.com/GoogleCloudPlatform/google-cloud-python/blob/0.28.0/bigquery/google/cloud/bigquery/client.py#L692-L706

@dhermes dhermes added api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. status: investigating The issue is under investigation, which is determined to be non-trivial. labels Nov 2, 2017
@dhermes
Copy link
Contributor

dhermes commented Nov 2, 2017

@tswast Can you lend a hand here?

@tswast
Copy link
Contributor

tswast commented Nov 10, 2017

This is a good feature request. I agree that such a change would improve usability.

I see two ways to address this:

  1. To allow either Table or TableReference for operations such as client.load_table_from_file(). Likewise for Dataset and DatasetReference.
  2. Add a helper method to get the TableReference from a Table object. Likewise for Dataset and DatasetReference.

In the meantime, the workaround is to create a TableReference manually from a Table.

dataset_ref = DatasetReference(table.project, table.dataset_id)
table_ref = TableReference(dataset_ref, table.table_id)

My preference would be for (2). Something like the following code:

table_ref = table.reference

@robfraz
Copy link
Author

robfraz commented Nov 13, 2017

@tswast Sounds good. You want me to submit a pull request, or is this something that you'll add yourselves?

@tswast
Copy link
Contributor

tswast commented Nov 13, 2017

Contributions welcome. :-)

@tswast tswast removed the status: investigating The issue is under investigation, which is determined to be non-trivial. label Nov 17, 2017
@tswast tswast self-assigned this Nov 17, 2017
@tswast
Copy link
Contributor

tswast commented Nov 17, 2017

I've got a PR pending #4405

@robfraz
Copy link
Author

robfraz commented Nov 20, 2017

Nice - thanks. I wouldn't have had a chance to get to it until the weekend just gone, and you beat me to it.

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

No branches or pull requests

3 participants