本文整理汇总了Python中pycassa.ColumnFamily.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily.truncate方法的具体用法?Python ColumnFamily.truncate怎么用?Python ColumnFamily.truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycassa.ColumnFamily
的用法示例。
在下文中一共展示了ColumnFamily.truncate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initFromDB
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import truncate [as 别名]
def initFromDB(self, mysql, sql, family, id_name, val_name):
cursor = mysql.cursor(MySQLdb.cursors.DictCursor)
cursor.execute(sql)
inserting = defaultdict(dict)
for row in cursor.fetchall():
val = row[val_name]
id = pack(row[id_name])
inserting[id][val] = val
fam = ColumnFamily(self.connection, family)
fam.truncate()
logging.info('Initializing %s' % family)
fam.batch_insert(inserting)
示例2: setUp
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import truncate [as 别名]
#.........这里部分代码省略.........
result = self.cf.multiget_count(keys, column_finish='2')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, column_start='1', column_finish='2')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, column_start='1', column_finish='1')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 1)
result = self.cf.multiget_count(keys, columns=['1','2'])
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, columns=['1'])
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 1)
def test_insert_get_range(self):
keys = ['TestColumnFamily.test_insert_get_range%s' % i for i in xrange(5)]
columns = {'1': 'val1', '2': 'val2'}
for key in keys:
self.cf.insert(key, columns)
rows = list(self.cf.get_range(start=keys[0], finish=keys[-1]))
assert len(rows) == len(keys)
for i, (k, c) in enumerate(rows):
assert k == keys[i]
assert c == columns
def test_get_range_batching(self):
self.cf.truncate()
keys = []
columns = {'c': 'v'}
for i in range(100, 201):
keys.append('key%d' % i)
self.cf.insert('key%d' % i, columns)
for i in range(201, 301):
self.cf.insert('key%d' % i, columns)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=10):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=1000):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=150):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=7):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
示例3: TestColumnFamily
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import truncate [as 别名]
#.........这里部分代码省略.........
result = self.cf.multiget_count(keys, column_finish='2')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, column_start='1', column_finish='2')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, column_start='1', column_finish='1')
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 1)
result = self.cf.multiget_count(keys, columns=['1','2'])
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 2)
result = self.cf.multiget_count(keys, columns=['1'])
assert_equal(len(result), 3)
assert_equal(result[keys[0]], 1)
def test_insert_get_range(self):
keys = ['TestColumnFamily.test_insert_get_range%s' % i for i in xrange(5)]
columns = {'1': 'val1', '2': 'val2'}
for key in keys:
self.cf.insert(key, columns)
rows = list(self.cf.get_range(start=keys[0], finish=keys[-1]))
assert_equal(len(rows), len(keys))
for i, (k, c) in enumerate(rows):
assert_equal(k, keys[i])
assert_equal(c, columns)
def test_get_range_batching(self):
self.cf.truncate()
keys = []
columns = {'c': 'v'}
for i in range(100, 201):
keys.append('key%d' % i)
self.cf.insert('key%d' % i, columns)
for i in range(201, 301):
self.cf.insert('key%d' % i, columns)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=10):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=1000):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=150):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
assert_equal(count, 100)
count = 0
for (k,v) in self.cf.get_range(row_count=100, buffer_size=7):
assert_true(k in keys, 'key "%s" should be in keys' % k)
count += 1
示例4: TestMutator
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import truncate [as 别名]
class TestMutator(unittest.TestCase):
def setUp(self):
credentials = {'username': 'jsmith', 'password': 'havebadpass'}
self.client = connect('Keyspace1', credentials=credentials)
self.cf = ColumnFamily(self.client, 'Standard2',
write_consistency_level=ConsistencyLevel.ONE,
timestamp=self.timestamp)
self.scf = ColumnFamily(self.client, 'Super1',
write_consistency_level=ConsistencyLevel.ONE,
super=True, timestamp=self.timestamp)
try:
self.timestamp_n = int(self.cf.get('meta')['timestamp'])
except NotFoundException:
self.timestamp_n = 0
self.clear()
def clear(self):
self.cf.truncate()
self.scf.truncate()
def timestamp(self):
self.timestamp_n += 1
return self.timestamp_n
def test_insert(self):
batch = self.cf.batch()
for key, cols in ROWS.iteritems():
batch.insert(key, cols)
batch.send()
for key, cols in ROWS.items():
assert self.cf.get(key) == cols
def test_insert_supercolumns(self):
batch = self.scf.batch()
batch.insert('one', ROWS)
batch.insert('two', ROWS)
batch.insert('three', ROWS)
batch.send()
assert self.scf.get('one') == ROWS
assert self.scf.get('two') == ROWS
assert self.scf.get('three') == ROWS
def test_queue_size(self):
batch = self.cf.batch(queue_size=2)
batch.insert('1', ROWS['1'])
batch.insert('2', ROWS['2'])
batch.insert('3', ROWS['3'])
assert self.cf.get('1') == ROWS['1']
assert_raises(NotFoundException, self.cf.get, '3')
batch.send()
for key, cols in ROWS.items():
assert self.cf.get(key) == cols
def test_remove_key(self):
batch = self.cf.batch()
batch.insert('1', ROWS['1'])
batch.remove('1')
batch.send()
assert_raises(NotFoundException, self.cf.get, '1')
def test_remove_columns(self):
batch = self.cf.batch()
batch.insert('1', {'a':'123', 'b':'123'})
batch.remove('1', ['a'])
batch.send()
assert self.cf.get('1') == {'b':'123'}
def test_remove_supercolumns(self):
batch = self.scf.batch()
batch.insert('one', ROWS)
batch.insert('two', ROWS)
batch.insert('three', ROWS)
batch.remove('two', ['b'], '2')
batch.send()
assert self.scf.get('one') == ROWS
assert self.scf.get('two')['2'] == {'a': '234'}
assert self.scf.get('three') == ROWS
def test_chained(self):
batch = self.cf.batch()
batch.insert('1', ROWS['1']).insert('2', ROWS['2']).insert('3', ROWS['3']).send()
assert self.cf.get('1') == ROWS['1']
assert self.cf.get('2') == ROWS['2']
assert self.cf.get('3') == ROWS['3']
def test_contextmgr(self):
if sys.version_info < (2,5):
raise SkipTest("No context managers in Python < 2.5")
exec """with self.cf.batch(queue_size=2) as b:
b.insert('1', ROWS['1'])
b.insert('2', ROWS['2'])
b.insert('3', ROWS['3'])
assert self.cf.get('3') == ROWS['3']"""
def test_multi_column_family(self):
batch = self.client.batch()
cf2 = self.cf
batch.insert(self.cf, '1', ROWS['1'])
batch.insert(self.cf, '2', ROWS['2'])
#.........这里部分代码省略.........