def __init__(self, name, connection): self.name = name # This remains as legacy for HappyBase, but only the cluster # from it is needed. self.connection = connection self._low_level_table = None if self.connection is not None: self._low_level_table = _LowLevelTable(self.name, self.connection._cluster)
def delete_table(self, name, disable=False): """Delete the specified table. :type name: str :param name: The name of the table to be deleted. If ``table_prefix`` is set, a prefix will be added to the ``name``. :type disable: bool :param disable: Whether to first disable the table if needed. This is provided for compatibility with HappyBase, but is not relevant for Cloud Bigtable since it has no concept of enabled / disabled tables. :raises: :class:`ValueError <exceptions.ValueError>` if ``disable=True``. """ if disable: raise ValueError('The disable argument should not be used in ' 'delete_table(). Cloud Bigtable has no concept ' 'of enabled / disabled tables.') name = self._table_name(name) _LowLevelTable(name, self._cluster).delete()
def create_table(self, name, families): """Create a table. .. warning:: The only column family options from HappyBase that are able to be used with Cloud Bigtable are ``max_versions`` and ``time_to_live``. .. note:: This method is **not** atomic. The Cloud Bigtable API separates the creation of a table from the creation of column families. Thus this method needs to send 1 request for the table creation and 1 request for each column family. If any of these fails, the method will fail, but the progress made towards completion cannot be rolled back. Values in ``families`` represent column family options. In HappyBase, these are dictionaries, corresponding to the ``ColumnDescriptor`` structure in the Thrift API. The accepted keys are: * ``max_versions`` (``int``) * ``compression`` (``str``) * ``in_memory`` (``bool``) * ``bloom_filter_type`` (``str``) * ``bloom_filter_vector_size`` (``int``) * ``bloom_filter_nb_hashes`` (``int``) * ``block_cache_enabled`` (``bool``) * ``time_to_live`` (``int``) :type name: str :param name: The name of the table to be created. :type families: dict :param families: Dictionary with column family names as keys and column family options as the values. The options can be among * :class:`dict` * :class:`.GarbageCollectionRule` * :class:`.GarbageCollectionRuleUnion` * :class:`.GarbageCollectionRuleIntersection` :raises: :class:`TypeError <exceptions.TypeError>` if ``families`` is not a dictionary, :class:`ValueError <exceptions.ValueError>` if ``families`` has no entries """ if not isinstance(families, dict): raise TypeError('families arg must be a dictionary') if not families: raise ValueError('Cannot create table %r (no column ' 'families specified)' % (name,)) # Parse all keys before making any API requests. gc_rule_dict = {} for column_family_name, option in families.items(): if column_family_name.endswith(':'): column_family_name = column_family_name[:-1] gc_rule_dict[column_family_name] = _parse_family_option(option) # Create table instance and then make API calls. name = self._table_name(name) low_level_table = _LowLevelTable(name, self._cluster) low_level_table.create() for column_family_name, gc_rule in gc_rule_dict.items(): column_family = low_level_table.column_family( column_family_name, gc_rule=gc_rule) column_family.create()