def test_create_with_column_families(self): from google.cloud.bigtable.column_family import ColumnFamily from google.cloud.bigtable.column_family import MaxVersionsGCRule cf_id1 = 'col-fam-id1' cf1 = ColumnFamily(cf_id1, None) cf_id2 = 'col-fam-id2' gc_rule = MaxVersionsGCRule(42) cf2 = ColumnFamily(cf_id2, None, gc_rule=gc_rule) initial_split_keys = None column_families = [cf1, cf2] self._create_test_helper(initial_split_keys, column_families=column_families)
def create(self, initial_split_keys=[], column_families={}): """Creates this table. .. note:: A create request returns a :class:`._generated.table_pb2.Table` but we don't use this response. :type initial_split_keys: list :param initial_split_keys: (Optional) list of row keys in bytes that will be used to initially split the table into several tablets. :type column_families: dict :param column_failies: (Optional) A map columns to create. The key is the column_id str and the value is a :class:`GarbageCollectionRule` """ table_client = self._instance._client.table_admin_client instance_name = self._instance.name families = { id: ColumnFamily(id, self, rule).to_pb() for (id, rule) in column_families.items() } table = admin_messages_v2_pb2.Table(column_families=families) split = table_admin_messages_v2_pb2.CreateTableRequest.Split splits = [split(key=_to_bytes(key)) for key in initial_split_keys] table_client.create_table(parent=instance_name, table_id=self.table_id, table=table, initial_splits=splits)
def column_family(self, column_family_id, gc_rule=None): """Factory to create a column family associated with this table. :type column_family_id: str :param column_family_id: The ID of the column family. Must be of the form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``. :type gc_rule: :class:`.GarbageCollectionRule` :param gc_rule: (Optional) The garbage collection settings for this column family. :rtype: :class:`.ColumnFamily` :returns: A column family owned by this table. """ return ColumnFamily(column_family_id, self, gc_rule=gc_rule)
def column_family(self, column_family_id, gc_rule=None): """Factory to create a column family associated with this table. For example: .. literalinclude:: snippets_table.py :start-after: [START bigtable_table_column_family] :end-before: [END bigtable_table_column_family] :type column_family_id: str :param column_family_id: The ID of the column family. Must be of the form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``. :type gc_rule: :class:`.GarbageCollectionRule` :param gc_rule: (Optional) The garbage collection settings for this column family. :rtype: :class:`.ColumnFamily` :returns: A column family owned by this table. """ return ColumnFamily(column_family_id, self, gc_rule=gc_rule)
def _make_column_family(*args, **kwargs): from google.cloud.bigtable.column_family import ColumnFamily return ColumnFamily(*args, **kwargs)