Skip to content

Commit

Permalink
BigTable: use client properties rather than private attrs (#5398)
Browse files Browse the repository at this point in the history
  • Loading branch information
aneepct authored and tseaver committed May 31, 2018
1 parent d303d51 commit 5a79d5d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions bigtable/google/cloud/bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def create(self):
client = self._table._instance._client
# data it contains are the GC rule and the column family ID already
# stored on this instance.
client._table_admin_client.modify_column_families(
client.table_admin_client.modify_column_families(
self._table.name, [modification])

def update(self):
Expand All @@ -247,7 +247,7 @@ def update(self):
client = self._table._instance._client
# data it contains are the GC rule and the column family ID already
# stored on this instance.
client._table_admin_client.modify_column_families(
client.table_admin_client.modify_column_families(
self._table.name, [modification])

def delete(self):
Expand All @@ -259,7 +259,7 @@ def delete(self):
client = self._table._instance._client
# data it contains are the GC rule and the column family ID already
# stored on this instance.
client._table_admin_client.modify_column_families(
client.table_admin_client.modify_column_families(
self._table.name, [modification])


Expand Down
16 changes: 8 additions & 8 deletions bigtable/google/cloud/bigtable/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def name(self):
:rtype: str
:returns: Return a fully-qualified instance string.
"""
return self._client._instance_admin_client.instance_path(
return self._client.instance_admin_client.instance_path(
project=self._client.project, instance=self.instance_id)

def __eq__(self, other):
Expand All @@ -165,7 +165,7 @@ def __ne__(self, other):

def reload(self):
"""Reload the metadata for this instance."""
instance_pb = self._client._instance_admin_client.get_instance(
instance_pb = self._client.instance_admin_client.get_instance(
self.name)

# NOTE: _update_from_pb does not check that the project and
Expand Down Expand Up @@ -194,9 +194,9 @@ def create(self):
"""
clusters = {}
cluster_id = '{}-cluster'.format(self.instance_id)
cluster_name = self._client._instance_admin_client.cluster_path(
cluster_name = self._client.instance_admin_client.cluster_path(
self._client.project, self.instance_id, cluster_id)
location = self._client._instance_admin_client.location_path(
location = self._client.instance_admin_client.location_path(
self._client.project, self._cluster_location_id)
cluster = instance_pb2.Cluster(
name=cluster_name, location=location,
Expand All @@ -208,7 +208,7 @@ def create(self):
clusters[cluster_id] = cluster
parent = self._client.project_path

return self._client._instance_admin_client.create_instance(
return self._client.instance_admin_client.create_instance(
parent=parent, instance_id=self.instance_id, instance=instance,
clusters=clusters)

Expand All @@ -227,7 +227,7 @@ def update(self):
before calling :meth:`update`.
"""
type = enums.Instance.Type.TYPE_UNSPECIFIED
self._client._instance_admin_client.update_instance(
self._client.instance_admin_client.update_instance(
name=self.name, display_name=self.display_name, type_=type,
labels={})

Expand All @@ -253,7 +253,7 @@ def delete(self):
irrevocably disappear from the API, and their data will be
permanently deleted.
"""
self._client._instance_admin_client.delete_instance(name=self.name)
self._client.instance_admin_client.delete_instance(name=self.name)

def table(self, table_id):
"""Factory to create a table associated with this instance.
Expand All @@ -274,7 +274,7 @@ def list_tables(self):
:raises: :class:`ValueError <exceptions.ValueError>` if one of the
returned tables has a name that is not of the expected format.
"""
table_list_pb = self._client._table_admin_client.list_tables(self.name)
table_list_pb = self._client.table_admin_client.list_tables(self.name)

result = []
for table_pb in table_list_pb:
Expand Down
11 changes: 6 additions & 5 deletions bigtable/google/cloud/bigtable/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ def commit(self):
raise ValueError('%d total mutations exceed the maximum allowable '
'%d.' % (num_mutations, MAX_MUTATIONS))

data_client = self._table._instance._client.table_data_client
commit = functools.partial(
self._table._instance._client._table_data_client.mutate_row,
data_client.mutate_row,
self._table.name, self._row_key, mutations_list)
retry_ = retry.Retry(
predicate=_retry_commit_exception,
Expand Down Expand Up @@ -532,8 +533,8 @@ def commit(self):
'mutations and %d false mutations.' % (
MAX_MUTATIONS, num_true_mutations, num_false_mutations))

client = self._table._instance._client
resp = client._table_data_client.check_and_mutate_row(
data_client = self._table._instance._client.table_data_client
resp = data_client.check_and_mutate_row(
table_name=self._table.name, row_key=self._row_key,)
self.clear()
return resp[0].predicate_matched
Expand Down Expand Up @@ -815,8 +816,8 @@ def commit(self):
raise ValueError('%d total append mutations exceed the maximum '
'allowable %d.' % (num_mutations, MAX_MUTATIONS))

client = self._table._instance._client
row_response = client._table_data_client.read_modify_write_row(
data_client = self._table._instance._client.table_data_client
row_response = data_client.read_modify_write_row(
table_name=self._table.name, row_key=self._row_key,
rules=self._rule_pb_list)

Expand Down
47 changes: 23 additions & 24 deletions bigtable/google/cloud/bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def name(self):
"""
project = self._instance._client.project
instance_id = self._instance.instance_id
return self._instance._client._table_admin_client.table_path(
table_client = self._instance._client.table_admin_client
return table_client.table_path(
project=project, instance=instance_id, table=self.table_id)

def column_family(self, column_family_id, gc_rule=None):
Expand Down Expand Up @@ -182,16 +183,15 @@ def create(self):
:class:`._generated.table_pb2.Table` but we don't use
this response.
"""
client = self._instance._client
table_client = self._instance._client.table_admin_client
instance_name = self._instance.name
client._table_admin_client.create_table(parent=instance_name,
table_id=self.table_id,
table={})
table_client.create_table(
parent=instance_name, table_id=self.table_id, table={})

def delete(self):
"""Delete this table."""
client = self._instance._client
client._table_admin_client.delete_table(name=self.name)
table_client = self._instance._client.table_admin_client
table_client.delete_table(name=self.name)

def list_column_families(self):
"""List the column families owned by this table.
Expand All @@ -204,8 +204,8 @@ def list_column_families(self):
family name from the response does not agree with the computed
name from the column family ID.
"""
client = self._instance._client
table_pb = client._table_admin_client.get_table(self.name)
table_client = self._instance._client.table_admin_client
table_pb = table_client.get_table(self.name)

result = {}
for column_family_id, value_pb in table_pb.column_families.items():
Expand Down Expand Up @@ -234,9 +234,8 @@ def read_row(self, row_key, filter_=None):
request_pb = _create_row_request(
self.name, row_key=row_key, filter_=filter_,
app_profile_id=self._app_profile_id)
client = self._instance._client
rows_data = PartialRowsData(client._table_data_client._read_rows,
request_pb)
data_client = self._instance._client.table_data_client
rows_data = PartialRowsData(data_client._read_rows, request_pb)

rows_data.consume_all()
if rows_data.state not in (rows_data.NEW_ROW, rows_data.START):
Expand Down Expand Up @@ -280,12 +279,11 @@ def read_rows(self, start_key=None, end_key=None, limit=None,
the streamed results.
"""
request_pb = _create_row_request(
self.name, start_key=start_key, end_key=end_key, filter_=filter_,
limit=limit, end_inclusive=end_inclusive,
self.name, start_key=start_key, end_key=end_key,
filter_=filter_, limit=limit, end_inclusive=end_inclusive,
app_profile_id=self._app_profile_id)
client = self._instance._client
return PartialRowsData(client._table_data_client._read_rows,
request_pb)
data_client = self._instance._client.table_data_client
return PartialRowsData(data_client._read_rows, request_pb)

def yield_rows(self, start_key=None, end_key=None, limit=None,
filter_=None):
Expand Down Expand Up @@ -317,9 +315,9 @@ def yield_rows(self, start_key=None, end_key=None, limit=None,
request_pb = _create_row_request(
self.name, start_key=start_key, end_key=end_key, filter_=filter_,
limit=limit, app_profile_id=self._app_profile_id)
client = self._instance._client
generator = YieldRowsData(client._table_data_client._read_rows,
request_pb)
data_client = self._instance._client.table_data_client
generator = YieldRowsData(data_client._read_rows, request_pb)

for row in generator.read_rows():
yield row

Expand Down Expand Up @@ -388,9 +386,10 @@ def sample_row_keys(self):
or by casting to a :class:`list` and can be cancelled by
calling ``cancel()``.
"""
client = self._instance._client
response_iterator = client._table_data_client.sample_row_keys(
data_client = self._instance._client.table_data_client
response_iterator = data_client.sample_row_keys(
self.name, app_profile_id=self._app_profile_id)

return response_iterator


Expand Down Expand Up @@ -478,8 +477,8 @@ def _do_mutate_retryable_rows(self):
mutate_rows_request = _mutate_rows_request(
self.table_name, retryable_rows,
app_profile_id=self.app_profile_id)
responses = self.client._table_data_client._mutate_rows(
mutate_rows_request, retry=None)
data_client = self.client.table_data_client
responses = data_client._mutate_rows(mutate_rows_request, retry=None)

num_responses = 0
num_retryable_responses = 0
Expand Down

0 comments on commit 5a79d5d

Please sign in to comment.