Skip to content

Commit

Permalink
deprecations(bigquery): deprecate client.dataset() in favor of Data…
Browse files Browse the repository at this point in the history
…setReference

Now that all client methods that take a `DatasetReference` or
`TableReference` also take a string, the `client.dataset()` method is
unnecessary and confusing.
  • Loading branch information
tswast committed Jan 23, 2020
1 parent 0280a94 commit 5a1bab8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 51 deletions.
27 changes: 24 additions & 3 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import math
import os
import tempfile
import textwrap
import uuid
import warnings

Expand Down Expand Up @@ -354,7 +355,18 @@ def list_datasets(
)

def dataset(self, dataset_id, project=None):
"""Construct a reference to a dataset.
"""Deprecated: Construct a reference to a dataset.
This method is deprecated. Construct a
:class:`~google.cloud.bigquery.dataset.DatasetReference` using its
constructor or use a string where previously a reference object was
used.
As ``google-cloud-bigquery`` version 1.7.0, all client methods that
take a :class:`~google.cloud.bigquery.dataset.DatasetReference` or
:class:`~google.cloud.bigquery.table.TableReference` also take a
string in standard SQL format, e.g. ``project.dataset_id`` or
``project.dataset_id.table_id``.
Args:
dataset_id (str): ID of the dataset.
Expand All @@ -370,6 +382,15 @@ def dataset(self, dataset_id, project=None):
if project is None:
project = self.project

warnings.warn(
textwrap.fill(
"Client.dataset is deprecated and will be removed in a future version. "
"Use a string like 'my_project.my_dataset' or a "
"cloud.google.bigquery.DatasetReference object, instead."
),
PendingDeprecationWarning,
stacklevel=2,
)
return DatasetReference(project, dataset_id)

def _create_bqstorage_client(self):
Expand Down Expand Up @@ -419,7 +440,7 @@ def create_dataset(
>>> from google.cloud import bigquery
>>> client = bigquery.Client()
>>> dataset = bigquery.Dataset(client.dataset('my_dataset'))
>>> dataset = bigquery.Dataset('my_project.my_dataset')
>>> dataset = client.create_dataset(dataset)
"""
Expand Down Expand Up @@ -2584,7 +2605,7 @@ def list_partitions(self, table, retry=DEFAULT_RETRY, timeout=None):
) as guard:
meta_table = self.get_table(
TableReference(
self.dataset(table.dataset_id, project=table.project),
DatasetReference(table.project, table.dataset_id),
"%s$__PARTITIONS_SUMMARY__" % table.table_id,
),
retry=retry,
Expand Down
3 changes: 2 additions & 1 deletion bigquery/google/cloud/bigquery/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
from google.api_core.exceptions import NotFound
import google.auth
from google.cloud import bigquery
import google.cloud.bigquery.dataset
from google.cloud.bigquery.dbapi import _helpers
import six

Expand Down Expand Up @@ -534,7 +535,7 @@ def _cell_magic(line, query):
)
dataset_id, table_id = split
job_config.allow_large_results = True
dataset_ref = client.dataset(dataset_id)
dataset_ref = bigquery.dataset.DatasetReference(client.project, dataset_id)
destination_table_ref = dataset_ref.table(table_id)
job_config.destination = destination_table_ref
job_config.create_disposition = "CREATE_IF_NEEDED"
Expand Down
Loading

0 comments on commit 5a1bab8

Please sign in to comment.