def list_column_families(self): """List the column families owned by this table. :rtype: dict :returns: Dictionary of column families attached to this table. Keys are strings (column family names) and values are :class:`.column_family.ColumnFamily` instances. :raises: :class:`ValueError <exceptions.ValueError>` if the column family name from the response does not agree with the computed name from the column family ID. """ request_pb = messages_pb2.GetTableRequest(name=self.name) client = self._cluster._client # We expect a `._generated.bigtable_table_data_pb2.Table` table_pb = client._table_stub.GetTable(request_pb, client.timeout_seconds) result = {} for column_family_id, value_pb in table_pb.column_families.items(): gc_rule = _gc_rule_from_pb(value_pb.gc_rule) column_family = self.column_family(column_family_id, gc_rule=gc_rule) if column_family.name != value_pb.name: raise ValueError('Column family name %s does not agree with ' 'name from request: %s.' % (column_family.name, value_pb.name)) result[column_family_id] = column_family return result
def _list_column_families_helper(self, column_family_name=None): from gcloud.bigtable._generated import ( bigtable_table_data_pb2 as data_pb2) from gcloud.bigtable._generated import ( bigtable_table_service_messages_pb2 as messages_pb2) from gcloud.bigtable._testing import _FakeStub project_id = 'project-id' zone = 'zone' cluster_id = 'cluster-id' table_id = 'table-id' timeout_seconds = 502 cluster_name = ('projects/' + project_id + '/zones/' + zone + '/clusters/' + cluster_id) client = _Client(timeout_seconds=timeout_seconds) cluster = _Cluster(cluster_name, client=client) table = self._makeOne(table_id, cluster) # Create request_pb table_name = cluster_name + '/tables/' + table_id request_pb = messages_pb2.GetTableRequest(name=table_name) # Create response_pb column_family_id = 'foo' if column_family_name is None: column_family_name = (table_name + '/columnFamilies/' + column_family_id) column_family = data_pb2.ColumnFamily(name=column_family_name) response_pb = data_pb2.Table( column_families={column_family_id: column_family}, ) # Patch the stub used by the API method. client._table_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = { column_family_id: table.column_family(column_family_id), } # Perform the method and check the result. result = table.list_column_families() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'GetTable', (request_pb, timeout_seconds), {}, )])