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: add from_string factory methods to Dataset and Table #5255

Merged
merged 3 commits into from
Apr 27, 2018

Conversation

tswast
Copy link
Contributor

@tswast tswast commented Apr 27, 2018

To make it easier to construct Datasets and Tables when the
full-qualified ID is known ahead of time, this PR adds helper methods
called from_string to Dataset, DatasetReference, Table, and
TableReference. In each case, the expected format is a fully-qualified
ID (including the project ID) in standard SQL format.

dataset = client.create_dataset(
    bigquery.Dataset(
        client.dataset('mydataset', project='other-project')
    )
)

becomes

dataset = client.create_dataset(
    bigquery.Dataset.from_string('other-project.mydataset')
)

Also, while writing doctests/examples, I noticed __repr__ was
inconsistent with the actual constructor on some of these classes. I
fixed that while I was here so those string representations don't cause
confusion.

/cc @maxim-lian

To make it easier to construct Datasets and Tables when the
full-qualified ID is known ahead of time, this PR adds helper methods
called `from_string` to Dataset, DatasetReference, Table, and
TableReference. In each case, the expected format is a fully-qualified
ID (including the project ID) in standard SQL format.

```
dataset = client.create_dataset(
    bigquery.Dataset(
        client.dataset('mydataset', project='other-project')
    )
)
```

becomes

```
dataset = client.create_dataset(
    bigquery.Dataset.from_string('other-project.mydataset')
)
```

Also, while writing doctests/examples, I noticed `__repr__` was
inconsistent with the actual constructor on some of these classes, so I
fixed that while I was here so those string representations don't cause
confusion.
@tswast tswast requested review from tseaver and alixhami April 27, 2018 17:27
@tswast tswast requested a review from lukesneeringer as a code owner April 27, 2018 17:27
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 27, 2018
@max-sixty
Copy link

Thanks a lot!

'standard SQL format. e.g. "project.dataset.table", got '
'{}'.format(full_table_id))

return cls(DatasetReference(parts[0], parts[1]), parts[2])

This comment was marked as spam.

standard SQL format.
"""
dataset_ref = DatasetReference.from_string(full_dataset_id)
return cls(dataset_ref)

This comment was marked as spam.

standard SQL format.
"""
table_ref = TableReference.from_string(full_table_id)
return cls(table_ref)

This comment was marked as spam.

@tswast tswast merged commit 20ff503 into googleapis:master Apr 27, 2018
@tswast tswast deleted the bq-from-string branch April 27, 2018 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants