Skip to content

Commit

Permalink
Refactor table() methods into shared implementation. (#7516)
Browse files Browse the repository at this point in the history
The method and docstring for the table() method are identical for
Dataset, DatasetReference, and DatasetListItem. This commit moves the
implementation to a shared method to reduce code duplication.
  • Loading branch information
tswast authored Mar 18, 2019
1 parent 67a6b85 commit 457da24
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions bigquery/google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
from google.cloud.bigquery.table import TableReference


def _get_table_reference(self, table_id):
"""Constructs a TableReference.
Args:
table_id (str): The ID of the table.
Returns:
google.cloud.bigquery.table.TableReference:
A table reference for a table in this dataset.
"""
return TableReference(self, table_id)


class AccessEntry(object):
"""Represents grant of an access role to an entity.
Expand Down Expand Up @@ -191,17 +204,7 @@ def path(self):
"""str: URL path for the dataset based on project and dataset ID."""
return "/projects/%s/datasets/%s" % (self.project, self.dataset_id)

def table(self, table_id):
"""Constructs a TableReference.
Args:
table_id (str): The ID of the table.
Returns:
google.cloud.bigquery.table.TableReference:
A table reference for a table in this dataset.
"""
return TableReference(self, table_id)
table = _get_table_reference

@classmethod
def from_api_repr(cls, resource):
Expand Down Expand Up @@ -578,17 +581,7 @@ def _build_resource(self, filter_fields):

return partial

def table(self, table_id):
"""Constructs a TableReference.
Args:
table_id (str): the ID of the table.
Returns:
google.cloud.bigquery.table.TableReference:
A TableReference for a table in this dataset.
"""
return TableReference(self.reference, table_id)
table = _get_table_reference

def __repr__(self):
return "Dataset({})".format(repr(self.reference))
Expand Down Expand Up @@ -668,14 +661,4 @@ def reference(self):
"""
return DatasetReference(self.project, self.dataset_id)

def table(self, table_id):
"""Constructs a TableReference.
Args:
table_id (str): the ID of the table.
Returns:
google.cloud.bigquery.table.TableReference:
A TableReference for a table in this dataset.
"""
return TableReference(self.reference, table_id)
table = _get_table_reference

0 comments on commit 457da24

Please sign in to comment.