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


Python ColumnFamilyMap.batch_insert方法代码示例

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


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

示例1: TestSuperColumnFamilyMap

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import batch_insert [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: TestColumnFamilyMap

# 需要导入模块: from pycassa import ColumnFamilyMap [as 别名]
# 或者: from pycassa.ColumnFamilyMap import batch_insert [as 别名]

#.........这里部分代码省略.........
        # 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':
            raise SkipTest('Cannot use RandomPartitioner for this test')

        instances = [self.instance() for i in range(5)]
        instances = sorted(instances, key=lambda instance: instance.key)
        for instance in instances:
            self.map.insert(instance)

        rows = list(self.map.get_range(start=instances[0].key, finish=instances[-1].key))
        assert_equal(len(rows), len(instances))
        assert_equal(rows, instances)

    def test_remove(self):
        instance = self.instance()

        self.map.insert(instance)
        self.map.remove(instance)
        assert_raises(NotFoundException, self.map.get, instance.key)

    def test_does_not_insert_extra_column(self):
        instance = self.instance()
        instance.othercol = 'Test'

        self.map.insert(instance)

        get_instance = self.map.get(instance.key)
        assert_equal(get_instance.strcol, instance.strcol)
        assert_equal(get_instance.intcol, instance.intcol)
        assert_equal(get_instance.floatcol, instance.floatcol)
        assert_equal(get_instance.datetimecol, instance.datetimecol)
        assert_raises(AttributeError, getattr, get_instance, 'othercol')

    def test_has_defaults(self):
        key = uuid.uuid4()
        ColumnFamily.insert(self.map, key, {'strcol': '1'})
        instance = self.map.get(key)

        assert_equal(instance.intcol, TestUTF8.intcol.default)
        assert_equal(instance.floatcol, TestUTF8.floatcol.default)
        assert_equal(instance.datetimecol, TestUTF8.datetimecol.default)

    def test_batch_insert(self):
        instances = []
        for i in range(3):
            instance = TestUTF8()
            instance.key = uuid.uuid4()
            instance.strcol = 'instance%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:
            get_instance = self.map.get(i.key)
            assert_equal(get_instance.key, i.key)
            assert_equal(get_instance.strcol, i.strcol)
开发者ID:anisnasir,项目名称:pycassa,代码行数:104,代码来源:test_columnfamilymap.py


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