當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。