Exemplo n.º 1
0
    def list_column_families(self):
        """List the column families owned by this table.

        For example:

        .. literalinclude:: snippets_table.py
            :start-after: [START bigtable_list_column_families]
            :end-before: [END bigtable_list_column_families]

        :rtype: dict
        :returns: Dictionary of column families attached to this table. Keys
                  are strings (column family names) and values are
                  :class:`.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.
        """
        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():
            gc_rule = _gc_rule_from_pb(value_pb.gc_rule)
            column_family = self.column_family(column_family_id,
                                               gc_rule=gc_rule)
            result[column_family_id] = column_family
        return result
Exemplo n.º 2
0
    def list_column_families(self):
        """List the column families owned by this table.

        For example:

        .. literalinclude:: snippets_table.py
            :start-after: [START bigtable_list_column_families]
            :end-before: [END bigtable_list_column_families]

        :rtype: dict
        :returns: Dictionary of column families attached to this table. Keys
                  are strings (column family names) and values are
                  :class:`.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.
        """
        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():
            gc_rule = _gc_rule_from_pb(value_pb.gc_rule)
            column_family = self.column_family(column_family_id, gc_rule=gc_rule)
            result[column_family_id] = column_family
        return result
Exemplo n.º 3
0
def test__gc_rule_from_pb_max_num_versions():
    from google.cloud.bigtable.column_family import _gc_rule_from_pb
    from google.cloud.bigtable.column_family import MaxVersionsGCRule

    orig_rule = MaxVersionsGCRule(1)
    gc_rule_pb = orig_rule.to_pb()
    result = _gc_rule_from_pb(gc_rule_pb)
    assert isinstance(result, MaxVersionsGCRule)
    assert result == orig_rule
Exemplo n.º 4
0
def test__gc_rule_from_pb_max_age():
    import datetime
    from google.cloud.bigtable.column_family import _gc_rule_from_pb
    from google.cloud.bigtable.column_family import MaxAgeGCRule

    orig_rule = MaxAgeGCRule(datetime.timedelta(seconds=1))
    gc_rule_pb = orig_rule.to_pb()
    result = _gc_rule_from_pb(gc_rule_pb)
    assert isinstance(result, MaxAgeGCRule)
    assert result == orig_rule
Exemplo n.º 5
0
def test__gc_rule_from_pb_unknown_field_name():
    from google.cloud.bigtable.column_family import _gc_rule_from_pb

    class MockProto(object):

        names = []

        _pb = {}

        @classmethod
        def WhichOneof(cls, name):
            cls.names.append(name)
            return "unknown"

    MockProto._pb = MockProto

    assert MockProto.names == []

    with pytest.raises(ValueError):
        _gc_rule_from_pb(MockProto)

    assert MockProto.names == ["rule"]
Exemplo n.º 6
0
def test__gc_rule_from_pb_intersection():
    import datetime
    from google.cloud.bigtable.column_family import _gc_rule_from_pb
    from google.cloud.bigtable.column_family import GCRuleIntersection
    from google.cloud.bigtable.column_family import MaxAgeGCRule
    from google.cloud.bigtable.column_family import MaxVersionsGCRule

    rule1 = MaxVersionsGCRule(1)
    rule2 = MaxAgeGCRule(datetime.timedelta(seconds=1))
    orig_rule = GCRuleIntersection([rule1, rule2])
    gc_rule_pb = orig_rule.to_pb()
    result = _gc_rule_from_pb(gc_rule_pb)
    assert isinstance(result, GCRuleIntersection)
    assert result == orig_rule
Exemplo n.º 7
0
    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:`.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.
        """
        client = self._instance._client
        table_pb = client._table_admin_client.get_table(self.name)

        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)
            result[column_family_id] = column_family
        return result
Exemplo n.º 8
0
    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:`.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 = table_admin_messages_v2_pb2.GetTableRequest(
            name=self.name)
        client = self._instance._client
        # We expect a `._generated.table_pb2.Table`
        table_pb = client._table_stub.GetTable(request_pb)

        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)
            result[column_family_id] = column_family
        return result
    def _call_fut(self, *args, **kwargs):
        from google.cloud.bigtable.column_family import _gc_rule_from_pb

        return _gc_rule_from_pb(*args, **kwargs)
Exemplo n.º 10
0
 def _callFUT(self, *args, **kwargs):
     from google.cloud.bigtable.column_family import _gc_rule_from_pb
     return _gc_rule_from_pb(*args, **kwargs)
Exemplo n.º 11
0
def test__gc_rule_from_pb_empty():
    from google.cloud.bigtable.column_family import _gc_rule_from_pb

    gc_rule_pb = _GcRulePB()
    assert _gc_rule_from_pb(gc_rule_pb) is None