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.
        """
        if disable:
            _WARN(_DISABLE_DELETE_MSG)

        name = self._table_name(name)
        _LowLevelTable(name, self._instance).delete()
Ejemplo n.º 2
0
 def __init__(self, name, connection):
     self.name = name
     # This remains as legacy for HappyBase, but only the instance
     # from the connection 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._instance)
    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``.

        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`

        :raises TypeError: If ``families`` is not a dictionary.
        :raises ValueError: If ``families`` has no entries.
        :raises AlreadyExists: If creation fails due to an already
                               existing table.
        :raises NetworkError: If creation fails for a reason other than
                              table exists.
        """
        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 isinstance(column_family_name, six.binary_type):
                column_family_name = column_family_name.decode('utf-8')
            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._instance)
        column_families = (
            low_level_table.column_family(column_family_name, gc_rule=gc_rule)
            for column_family_name, gc_rule in six.iteritems(gc_rule_dict))
        try:
            low_level_table.create(column_families=column_families)
        except face.NetworkError as network_err:
            if network_err.code == interfaces.StatusCode.ALREADY_EXISTS:
                raise AlreadyExists(name)
            else:
                raise