当前位置: 首页>>代码示例>>Python>>正文


Python ColumnFamilyMap.get_range方法代码示例

本文整理汇总了Python中pycassa.ColumnFamilyMap.get_range方法的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamilyMap.get_range方法的具体用法?Python ColumnFamilyMap.get_range怎么用?Python ColumnFamilyMap.get_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycassa.ColumnFamilyMap的用法示例。


在下文中一共展示了ColumnFamilyMap.get_range方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSuperColumnFamilyMap

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestSuperColumnFamilyMap(unittest.TestCase):

    def setUp(self):
        self.map = ColumnFamilyMap(TestUTF8, pool, SCF)

    def tearDown(self):
        for scols in self.map.get_range():
            for instance in scols.values():
                self.map.remove(instance)

    def instance(self, super_column):
        instance = TestUTF8()
        instance.key = uuid.uuid4()
        instance.super_column = super_column
        instance.strcol = '1'
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)

        return instance

    def test_super(self):
        instance = self.instance('super1')
        assert_raises(NotFoundException, self.map.get, instance.key)
        self.map.insert(instance)
        res = self.map.get(instance.key)[instance.super_column]
        assert_equal(res, instance)
        assert_equal(self.map.multiget([instance.key])[instance.key][instance.super_column], instance)
        assert_equal(list(self.map.get_range(start=instance.key, finish=instance.key)), [{instance.super_column: instance}])

    def test_super_remove(self):
        instance1 = self.instance('super1')
        assert_raises(NotFoundException, self.map.get, instance1.key)
        self.map.insert(instance1)

        instance2 = self.instance('super2')
        self.map.insert(instance2)

        self.map.remove(instance2)
        assert_equal(len(self.map.get(instance1.key)), 1)
        assert_equal(self.map.get(instance1.key)[instance1.super_column], instance1)

    def test_batch_insert_super(self):
        instances = []
        for i in range(3):
            instance = self.instance('super_batch%s' % (i + 1))
            instances.append(instance)

        for i in instances:
            assert_raises(NotFoundException, self.map.get, i.key)

        self.map.batch_insert(instances)

        for i in instances:
            result = self.map.get(i.key)
            get_instance = result[i.super_column]
            assert_equal(len(result), 1)
            assert_equal(get_instance.key, i.key)
            assert_equal(get_instance.super_column, i.super_column)
            assert_equal(get_instance.strcol, i.strcol)
开发者ID:anisnasir,项目名称:pycassa,代码行数:62,代码来源:test_columnfamilymap.py

示例2: setUp

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestSuperColumnFamilyMap:
    def setUp(self):
        credentials = {'username': 'jsmith', 'password': 'havebadpass'}
        self.pool = ConnectionPool(keyspace='Keyspace1', credentials=credentials)
        self.cf = ColumnFamily(self.pool, 'Super2')
        self.map = ColumnFamilyMap(TestUTF8, self.cf)

    def tearDown(self):
        for key, columns in self.cf.get_range():
            self.cf.remove(key)

    def instance(self, key, super_column):
        instance = TestUTF8()
        instance.key = key
        instance.super_column = super_column
        instance.strcol = '1'
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)
        instance.intstrcol = 8
        instance.floatstrcol = 4.6
        instance.datetimestrcol = datetime.now().replace(microsecond=0)

        return instance

    def test_super(self):
        instance = self.instance('TestSuperColumnFamilyMap.test_super', 'super1')
        assert_raises(NotFoundException, self.map.get, instance.key)
        self.map.insert(instance)
        res = self.map.get(instance.key)[instance.super_column]
        assert_equal(res, instance)
        assert_equal(self.map.multiget([instance.key])[instance.key][instance.super_column], instance)
        assert_equal(list(self.map.get_range(start=instance.key, finish=instance.key)), [{instance.super_column: instance}])
开发者ID:trhowe,项目名称:pycassa,代码行数:35,代码来源:test_columnfamilymap.py

示例3: setUp

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestSuperColumnFamilyMap:
    def setUp(self):
        self.map = ColumnFamilyMap(TestUTF8, pool, SCF)

    def tearDown(self):
        for scols in self.map.get_range():
            for instance in scols.values():
                self.map.remove(instance)

    def instance(self, key, super_column):
        instance = TestUTF8()
        instance.key = key
        instance.super_column = super_column
        instance.strcol = "1"
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)

        return instance

    def test_super(self):
        instance = self.instance("TestSuperColumnFamilyMap.test_super", "super1")
        assert_raises(NotFoundException, self.map.get, instance.key)
        self.map.insert(instance)
        res = self.map.get(instance.key)[instance.super_column]
        assert_equal(res, instance)
        assert_equal(self.map.multiget([instance.key])[instance.key][instance.super_column], instance)
        assert_equal(
            list(self.map.get_range(start=instance.key, finish=instance.key)), [{instance.super_column: instance}]
        )

    def test_super_remove(self):
        instance1 = self.instance("TestSuperColumnFamilyMap.test_super_remove", "super1")
        assert_raises(NotFoundException, self.map.get, instance1.key)
        self.map.insert(instance1)

        instance2 = self.instance("TestSuperColumnFamilyMap.test_super_remove", "super2")
        self.map.insert(instance2)

        self.map.remove(instance2)
        assert_equal(len(self.map.get(instance1.key)), 1)
        assert_equal(self.map.get(instance1.key)[instance1.super_column], instance1)
开发者ID:bwhite,项目名称:pycassa,代码行数:44,代码来源:test_columnfamilymap.py

示例4: setUp

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestSuperColumnFamilyMap:
    def setUp(self):
        self.client = connect_thread_local()
        self.client.login('Keyspace1', {'username': 'jsmith', 'password': 'havebadpass'})
        self.cf = ColumnFamily(self.client, 'Keyspace1', 'Super2',
                               write_consistency_level=ConsistencyLevel.ONE,
                               timestamp=self.timestamp,
                               super=True)
        self.map = ColumnFamilyMap(TestUTF8, self.cf)
        try:
            self.timestamp_n = int(self.cf.get('meta')['meta']['timestamp'])
        except NotFoundException:
            self.timestamp_n = 0
        self.clear()

    def tearDown(self):
        self.cf.insert('meta', {'meta': {'timestamp': str(self.timestamp_n)}})

    # Since the timestamp passed to Cassandra will be in the same second
    # with the default timestamp function, causing problems with removing
    # and inserting (Cassandra doesn't know which is later), we supply our own
    def timestamp(self):
        self.timestamp_n += 1
        return self.timestamp_n

    def clear(self):
        for key, columns in self.cf.get_range(include_timestamp=True):
            for subcolumns in columns.itervalues():
                for value, timestamp in subcolumns.itervalues():
                    self.timestamp_n = max(self.timestamp_n, timestamp)
            self.cf.remove(key)

    def instance(self, key, super_column):
        instance = TestUTF8()
        instance.key = key
        instance.super_column = super_column
        instance.strcol = '1'
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)
        instance.intstrcol = 8
        instance.floatstrcol = 4.6
        instance.datetimestrcol = datetime.now().replace(microsecond=0)

        return instance

    def test_super(self):
        instance = self.instance('TestSuperColumnFamilyMap.test_super', 'super1')
        assert_raises(NotFoundException, self.map.get, instance.key)
        self.map.insert(instance)
        assert self.map.get(instance.key)[instance.super_column] == instance
        assert self.map.multiget([instance.key])[instance.key][instance.super_column] == instance
        assert list(self.map.get_range(start=instance.key, finish=instance.key)) == [{instance.super_column: instance}]
开发者ID:SethCLong,项目名称:pycassa,代码行数:55,代码来源:test_columnfamilymap.py

示例5: setUp

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestSuperColumnFamilyMap:
    def setUp(self):
        self.map = ColumnFamilyMap(TestUTF8, scf)

    def tearDown(self):
        for key, columns in scf.get_range():
            scf.remove(key)

    def instance(self, key, super_column):
        instance = TestUTF8()
        instance.key = key
        instance.super_column = super_column
        instance.strcol = '1'
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)
        instance.intstrcol = 8
        instance.floatstrcol = 4.6
        instance.datetimestrcol = datetime.now().replace(microsecond=0)

        return instance

    def test_super(self):
        instance = self.instance('TestSuperColumnFamilyMap.test_super', 'super1')
        assert_raises(NotFoundException, self.map.get, instance.key)
        self.map.insert(instance)
        res = self.map.get(instance.key)[instance.super_column]
        assert_equal(res, instance)
        assert_equal(self.map.multiget([instance.key])[instance.key][instance.super_column], instance)
        assert_equal(list(self.map.get_range(start=instance.key, finish=instance.key)), [{instance.super_column: instance}])

    def test_super_remove(self):
        instance1 = self.instance('TestSuperColumnFamilyMap.test_super_remove', 'super1')
        assert_raises(NotFoundException, self.map.get, instance1.key)
        self.map.insert(instance1)

        instance2 = self.instance('TestSuperColumnFamilyMap.test_super_remove', 'super2')
        self.map.insert(instance2)

        self.map.remove(instance2)
        assert_equal(len(self.map.get(instance1.key)), 1)
        assert_equal(self.map.get(instance1.key)[instance1.super_column], instance1)
开发者ID:amxn,项目名称:pycassa,代码行数:44,代码来源:test_columnfamilymap.py

示例6: TestColumnFamilyMap

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestColumnFamilyMap(unittest.TestCase):

    def setUp(self):
        self.map = ColumnFamilyMap(TestUTF8, pool, CF)
        self.indexed_map = ColumnFamilyMap(TestIndex, pool, INDEXED_CF)
        self.empty_map = ColumnFamilyMap(TestEmpty, pool, CF, raw_columns=True)

    def tearDown(self):
        for instance in self.map.get_range():
            self.map.remove(instance)
        for instance in self.indexed_map.get_range():
            self.indexed_map.remove(instance)

    def instance(self):
        instance = TestUTF8()
        instance.key = uuid.uuid4()
        instance.strcol = '1'
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)

        return instance

    def test_empty(self):
        key = uuid.uuid4()
        assert_raises(NotFoundException, self.map.get, key)
        assert_equal(len(self.map.multiget([key])), 0)

    def test_insert_get(self):
        instance = self.instance()
        assert_raises(NotFoundException, self.map.get, instance.key)
        ts = self.map.insert(instance)
        assert_true(isinstance(ts, (int, long)))
        assert_equal(self.map.get(instance.key), instance)

    def test_insert_get_omitting_columns(self):
        """
        When omitting columns, pycassa should not try to insert the CassandraType
        instance on a ColumnFamilyMap object
        """
        instance2 = TestUTF8()
        instance2.key = uuid.uuid4()
        instance2.strcol = 'lol'
        instance2.intcol = 2
        assert_raises(NotFoundException, self.map.get, instance2.key)
        self.map.insert(instance2)
        ret_inst = self.map.get(instance2.key)
        assert_equal(ret_inst.key, instance2.key)
        assert_equal(ret_inst.strcol, instance2.strcol)
        assert_equal(ret_inst.intcol, instance2.intcol)

        ## these lines are commented out because, though they should work, wont
        ## because CassandraTypes are not descriptors when used on a ColumnFamilyMap
        ## instance, they are merely class attributes that are overwritten at runtime

        # assert_equal(ret_inst.floatcol, instance2.floatcol)
        # assert_equal(ret_inst.datetimecol, instance2.datetimecol)
        # assert_equal(self.map.get(instance2.key), instance2)

    def test_insert_get_indexed_slices(self):
        instance1 = TestIndex()
        instance1.key = 'key1'
        instance1.birthdate = 1L
        self.indexed_map.insert(instance1)

        instance2 = TestIndex()
        instance2.key = 'key2'
        instance2.birthdate = 1L
        self.indexed_map.insert(instance2)

        instance3 = TestIndex()
        instance3.key = 'key3'
        instance3.birthdate = 2L
        self.indexed_map.insert(instance3)

        expr = index.create_index_expression(column_name='birthdate', value=2L)
        clause = index.create_index_clause([expr])

        result = self.indexed_map.get_indexed_slices(index_clause=clause)
        count = 0
        for instance in result:
            assert_equal(instance, instance3)
            count += 1
        assert_equal(count, 1)

    def test_insert_multiget(self):
        instance1 = self.instance()
        instance2 = self.instance()
        missing_key = uuid.uuid4()

        self.map.insert(instance1)
        self.map.insert(instance2)
        rows = self.map.multiget([instance1.key, instance2.key, missing_key])
        assert_equal(len(rows), 2)
        assert_equal(rows[instance1.key], instance1)
        assert_equal(rows[instance2.key], instance2)
        assert_true(missing_key not in rows)

    def test_insert_get_range(self):
        if sys_man.describe_partitioner() == 'RandomPartitioner':
#.........这里部分代码省略.........
开发者ID:anisnasir,项目名称:pycassa,代码行数:103,代码来源:test_columnfamilymap.py

示例7: TestColumnFamilyMap

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import get_range [as 别名]
class TestColumnFamilyMap(unittest.TestCase):
    def setUp(self):
        self.map = ColumnFamilyMap(TestUTF8, pool, CF)
        self.indexed_map = ColumnFamilyMap(TestIndex, pool, INDEXED_CF)
        self.empty_map = ColumnFamilyMap(TestEmpty, pool, CF, raw_columns=True)

    def tearDown(self):
        for instance in self.map.get_range():
            self.map.remove(instance)
        for instance in self.indexed_map.get_range():
            self.indexed_map.remove(instance)

    def instance(self, key):
        instance = TestUTF8()
        instance.key = key
        instance.strcol = "1"
        instance.intcol = 2
        instance.floatcol = 3.5
        instance.datetimecol = datetime.now().replace(microsecond=0)

        return instance

    def test_empty(self):
        key = "TestColumnFamilyMap.test_empty"
        assert_raises(NotFoundException, self.map.get, key)
        assert_equal(len(self.map.multiget([key])), 0)

    def test_insert_get(self):
        instance = self.instance("TestColumnFamilyMap.test_insert_get")
        assert_raises(NotFoundException, self.map.get, instance.key)
        ts = self.map.insert(instance)
        assert_true(isinstance(ts, int))
        assert_equal(self.map.get(instance.key), instance)

    def test_insert_get_omitting_columns(self):
        r"""
        When omitting columns, pycassa should not try to insert the CassandraType
        instance on a ColumnFamilyMap object
        """
        instance2 = TestUTF8()
        instance2.key = "TestColumnFamilyMap.test_insert_get_2"
        instance2.strcol = "lol"
        instance2.intcol = 2
        assert_raises(NotFoundException, self.map.get, instance2.key)
        self.map.insert(instance2)
        ret_inst = self.map.get(instance2.key)
        assert_equal(ret_inst.key, instance2.key)
        assert_equal(ret_inst.strcol, instance2.strcol)
        assert_equal(ret_inst.intcol, instance2.intcol)

        ## these lines are commented out because, though they should work, wont
        ## because CassandraTypes are not descriptors when used on a ColumnFamilyMap
        ## instance, they are merely class attributes that are overwritten at runtime

        # assert_equal(ret_inst.floatcol, instance2.floatcol)
        # assert_equal(ret_inst.datetimecol, instance2.datetimecol)
        # assert_equal(self.map.get(instance2.key), instance2)

    def test_insert_get_indexed_slices(self):
        instance1 = TestIndex()
        instance1.key = "key1"
        instance1.birthdate = 1L
        self.indexed_map.insert(instance1)

        instance2 = TestIndex()
        instance2.key = "key2"
        instance2.birthdate = 1L
        self.indexed_map.insert(instance2)

        instance3 = TestIndex()
        instance3.key = "key3"
        instance3.birthdate = 2L
        self.indexed_map.insert(instance3)

        expr = index.create_index_expression(column_name="birthdate", value=2L)
        clause = index.create_index_clause([expr])

        result = self.indexed_map.get_indexed_slices(index_clause=clause)
        count = 0
        for instance in result:
            assert_equal(instance, instance3)
            count += 1
        assert_equal(count, 1)

    def test_insert_multiget(self):
        instance1 = self.instance("TestColumnFamilyMap.test_insert_multiget1")
        instance2 = self.instance("TestColumnFamilyMap.test_insert_multiget2")
        missing_key = "TestColumnFamilyMap.test_insert_multiget3"

        self.map.insert(instance1)
        self.map.insert(instance2)
        rows = self.map.multiget([instance1.key, instance2.key, missing_key])
        assert_equal(len(rows), 2)
        assert_equal(rows[instance1.key], instance1)
        assert_equal(rows[instance2.key], instance2)
        assert_true(missing_key not in rows)

    def test_insert_get_range(self):
        if sys_man.describe_partitioner() == "RandomPartitioner":
            raise SkipTest("Cannot use RandomPartitioner for this test")
#.........这里部分代码省略.........
开发者ID:bshanks,项目名称:pycassa,代码行数:103,代码来源:test_columnfamilymap.py


注:本文中的pycassa.ColumnFamilyMap.get_range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。