From 5a79d5dfee95a37501e8d9296775ddbb69984c31 Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Thu, 31 May 2018 23:06:42 +0530 Subject: [PATCH] BigTable: use client properties rather than private attrs (#5398) --- .../google/cloud/bigtable/column_family.py | 6 +-- bigtable/google/cloud/bigtable/instance.py | 16 +++---- bigtable/google/cloud/bigtable/row.py | 11 +++-- bigtable/google/cloud/bigtable/table.py | 47 +++++++++---------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/bigtable/google/cloud/bigtable/column_family.py b/bigtable/google/cloud/bigtable/column_family.py index 3e2f1cae818e..c0c5c47d6da3 100644 --- a/bigtable/google/cloud/bigtable/column_family.py +++ b/bigtable/google/cloud/bigtable/column_family.py @@ -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): @@ -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): @@ -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]) diff --git a/bigtable/google/cloud/bigtable/instance.py b/bigtable/google/cloud/bigtable/instance.py index 97b90e1ab9d4..67177c040b6c 100644 --- a/bigtable/google/cloud/bigtable/instance.py +++ b/bigtable/google/cloud/bigtable/instance.py @@ -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): @@ -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 @@ -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, @@ -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) @@ -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={}) @@ -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. @@ -274,7 +274,7 @@ def list_tables(self): :raises: :class:`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: diff --git a/bigtable/google/cloud/bigtable/row.py b/bigtable/google/cloud/bigtable/row.py index 73803801249f..f900e42d4720 100644 --- a/bigtable/google/cloud/bigtable/row.py +++ b/bigtable/google/cloud/bigtable/row.py @@ -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, @@ -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 @@ -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) diff --git a/bigtable/google/cloud/bigtable/table.py b/bigtable/google/cloud/bigtable/table.py index 22e889588d32..0e37fc28d77a 100644 --- a/bigtable/google/cloud/bigtable/table.py +++ b/bigtable/google/cloud/bigtable/table.py @@ -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): @@ -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. @@ -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(): @@ -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): @@ -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): @@ -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 @@ -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 @@ -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