本文整理汇总了Python中pycassa.ColumnFamily类的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily类的具体用法?Python ColumnFamily怎么用?Python ColumnFamily使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ColumnFamily类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
class Database:
def __init__(self, column_family):
"""
ColumnFamily:
- Thông tin người dùng
- Tìm kiếm
- Thông tin vé
- Nhật ký hệ thống
- Thông tin nhà cung cấp
"""
# Connect to Cassandra servers
client = connect(CASSANDRA_HOSTS)
self.db = ColumnFamily(client, CASSANDRA_KEYSPACE, column_family, super=False)
def insert(self, key, columns):
key = md5(capwords(key).lower()).hexdigest()
return self.db.insert(key, columns)
def get(self, key, columns=None):
key = md5(capwords(key).lower()).hexdigest()
return self.db.get(key=key, columns=columns)
def remove(self, key, column=None):
key = md5(capwords(key).lower()).hexdigest()
return self.db.remove(key=key, column=column)
开发者ID:AloneRoad,项目名称:MTS,代码行数:25,代码来源:database.py
示例2: get_connection
def get_connection():
"""
Creates a connection to Cassandra.
Returs:
pool
"""
cassandra_host = os.environ.get('CASSANDRA_HOST', 'localhost')
sys_mgr = SystemManager()
try:
sys_mgr.describe_ring(KEYSPACE)
except:
sys_mgr.create_keyspace(KEYSPACE, SIMPLE_STRATEGY, {'replication_factor': '1'})
pool = ConnectionPool(KEYSPACE, server_list=[cassandra_host])
for cf_name in [CF_LOGS, CF_LOGS_BY_APP, CF_LOGS_BY_HOST, CF_LOGS_BY_SEVERITY]:
try:
cf = ColumnFamily(pool, cf_name)
except:
sys_mgr.create_column_family(KEYSPACE, cf_name, comparator_type=TimeUUIDType())
cf = ColumnFamily(pool, cf_name)
cf.get_count(str(uuid.uuid4()))
sys_mgr.close()
return pool
开发者ID:hgdeoro,项目名称:daedalus,代码行数:26,代码来源:simple_client.py
示例3: test_null_pool_failover
def test_null_pool_failover(self):
listener = _TestListener()
pool = NullPool(keyspace='Keyspace1', credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160', 'localhost:9160'])
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
for i in range(1,5):
setattr(cf.client._connection.client, 'batch_mutate', _timeout)
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert('key', {'col': 'val'})
assert_equal(listener.failure_count, i)
cf.get('key')
pool.dispose()
listener.reset()
pool = NullPool(keyspace='Keyspace1', credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160', 'localhost:9160'])
threads = []
args = (pool, 'key', {'col':'val'})
for i in range(0, 5):
threads.append(threading.Thread(target=_five_fails, args=args))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.failure_count, 25)
pool.dispose()
开发者ID:dln,项目名称:pycassa,代码行数:35,代码来源:test_connection_pooling.py
示例4: remove
def remove(self, colfam, key, columns=None):
cf = ColumnFamily(self.db, colfam)
if columns is not None:
return cf.remove(key, columns)
else:
return cf.remove(key)
开发者ID:krone,项目名称:cass-orm,代码行数:7,代码来源:db.py
示例5: setUp
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,代码行数:33,代码来源:test_columnfamilymap.py
示例6: test_has_defaults
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)
开发者ID:anisnasir,项目名称:pycassa,代码行数:8,代码来源:test_columnfamilymap.py
示例7: test_has_defaults
def test_has_defaults(self):
key = "TestColumnFamilyMap.test_has_defaults"
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)
开发者ID:bwhite,项目名称:pycassa,代码行数:8,代码来源:test_columnfamilymap.py
示例8: test_basic_pools
def test_basic_pools(self):
pool = ConnectionPool('PycassaTestKeyspace', credentials=_credentials)
pool.dispose()
pool = pool.recreate()
cf = ColumnFamily(pool, 'Standard1')
cf.insert('key1', {'col':'val'})
pool.status()
pool.dispose()
开发者ID:amxn,项目名称:pycassa,代码行数:8,代码来源:test_connection_pooling.py
示例9: test_basic_pools
def test_basic_pools(self):
for pool_cls in _pools:
pool = pool_cls(keyspace='Keyspace1', credentials=_credentials)
pool.dispose()
pool = pool.recreate()
cf = ColumnFamily(pool, 'Standard1')
cf.insert('key1', {'col':'val'})
pool.status()
pool.dispose()
开发者ID:trhowe,项目名称:pycassa,代码行数:9,代码来源:test_connection_pooling.py
示例10: _five_fails
def _five_fails(pool, key, column):
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
for i in range(0,5):
setattr(cf.client._connection.client, 'batch_mutate', _timeout)
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert(key, column)
cf.get(key)
开发者ID:dln,项目名称:pycassa,代码行数:10,代码来源:test_connection_pooling.py
示例11: __init__
def __init__(self):
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument(
"-s",
"--source",
help="Generally the prod cassandra path, list of machines: \
localhost:9162 localhost:9163",
nargs="*",
required=True,
)
parser.add_argument(
"-d",
"--destination",
help="Cassandra path where you need your data: \
localhost:9160 localhost:9161",
nargs="*",
required=True,
)
parser.add_argument("-ks", "--keyspace", help="The keyspace: myks", required=True)
parser.add_argument("-cf", "--column_family", help="The Column family: mycf", required=True)
parser.add_argument("-k", "--key", help="A specific key to be imported", required=False)
parser.add_argument("-c", "--count", help="Total count of keys to be imported", required=False)
parser.add_argument("-a", "--all", action="store_true", help="Get all. Not recommended!", required=False)
args = vars(parser.parse_args())
"""Connection setting with cassandra
The script is meant to sync data. So source and destination KS
and CF shold be the same."""
try:
source_pool = ConnectionPool(args["keyspace"], args["source"])
destination_pool = ConnectionPool(args["keyspace"], args["destination"])
self.source_cf = ColumnFamily(source_pool, args["column_family"])
self.source_cf.autopack_names = False
self.source_cf.autopack_values = False
self.source_cf.autopack_keys = False
self.source_cf.default_validation_class = pycassa.types.UTF8Type()
self.destination_cf = ColumnFamily(destination_pool, args["column_family"])
self.destination_cf.autopack_names = False
self.destination_cf.autopack_values = False
self.destination_cf.autopack_keys = False
self.destination_cf.default_validation_class = pycassa.types.UTF8Type()
except Exception as e:
print "ERROR: The keyspace or the column family does not exist or request is timing out!"
sys.exit()
# Optional data
self.count = args["count"]
if self.count:
self.count = int(self.count)
self.key = args["key"]
self.all = args["all"]
开发者ID:utkarsh2012,项目名称:cassandra-importer,代码行数:54,代码来源:cass_importer.py
示例12: test_basic_pools
def test_basic_pools(self):
for pool_cls in _pools:
print "Pool class: %s" % pool_cls.__name__
pool = pool_cls(keyspace='Keyspace1', credentials=_credentials)
pool.dispose()
pool = pool.recreate()
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
cf.insert('key1', {'col':'val'})
pool.status()
pool.return_conn(conn)
开发者ID:dln,项目名称:pycassa,代码行数:11,代码来源:test_connection_pooling.py
示例13: get
def get(self, colfam, key, columns=None, column_start="", column_finish="",
column_reversed=False, column_count=100, include_timestamp=False,
super_column=None, read_consistency_level=None):
cf = ColumnFamily(self.db, colfam)
try:
return cf.get(key, columns, column_start, column_finish,
column_reversed, column_count, include_timestamp,
super_column, read_consistency_level)
except NotFoundException:
return None
开发者ID:krone,项目名称:cass-orm,代码行数:12,代码来源:db.py
示例14: initFromDB
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)
开发者ID:andrusha,项目名称:circlefy,代码行数:12,代码来源:Cassandra.py
示例15: setUp
def setUp(self):
credentials = {'username': 'jsmith', 'password': 'havebadpass'}
self.client = connect_thread_local('Keyspace1', credentials=credentials)
self.cf = ColumnFamily(self.client, 'Standard2')
self.cf_long = ColumnFamily(self.client, 'StdLong')
self.cf_int = ColumnFamily(self.client, 'StdInteger')
self.cf_time = ColumnFamily(self.client, 'StdTimeUUID')
self.cf_lex = ColumnFamily(self.client, 'StdLexicalUUID')
self.cf_ascii = ColumnFamily(self.client, 'StdAscii')
self.cf_utf8 = ColumnFamily(self.client, 'StdUTF8')
self.cf_bytes = ColumnFamily(self.client, 'StdBytes')
self.cf_suplong = ColumnFamily(self.client, 'SuperLong', super=True)
self.cf_supint = ColumnFamily(self.client, 'SuperInt', super=True)
self.cf_suptime = ColumnFamily(self.client, 'SuperTime', super=True)
self.cf_suplex = ColumnFamily(self.client, 'SuperLex', super=True)
self.cf_supascii = ColumnFamily(self.client, 'SuperAscii', super=True)
self.cf_suputf8 = ColumnFamily(self.client, 'SuperUTF8', super=True)
self.cf_supbytes = ColumnFamily(self.client, 'SuperBytes', super=True)
self.cf_suplong_sublong = ColumnFamily(self.client, 'SuperLongSubLong', super=True)
self.cf_suplong_subint = ColumnFamily(self.client, 'SuperLongSubInt', super=True)
self.cf_suplong_subtime = ColumnFamily(self.client, 'SuperLongSubTime', super=True)
self.cf_suplong_sublex = ColumnFamily(self.client, 'SuperLongSubLex', super=True)
self.cf_suplong_subascii = ColumnFamily(self.client, 'SuperLongSubAscii', super=True)
self.cf_suplong_subutf8 = ColumnFamily(self.client, 'SuperLongSubUTF8', super=True)
self.cf_suplong_subbytes = ColumnFamily(self.client, 'SuperLongSubBytes', super=True)
self.cf_valid_long = ColumnFamily(self.client, 'ValidatorLong')
self.cf_valid_int = ColumnFamily(self.client, 'ValidatorInt')
self.cf_valid_time = ColumnFamily(self.client, 'ValidatorTime')
self.cf_valid_lex = ColumnFamily(self.client, 'ValidatorLex')
self.cf_valid_ascii = ColumnFamily(self.client, 'ValidatorAscii')
self.cf_valid_utf8 = ColumnFamily(self.client, 'ValidatorUTF8')
self.cf_valid_bytes = ColumnFamily(self.client, 'ValidatorBytes')
self.cfs = [self.cf_long, self.cf_int, self.cf_time, self.cf_lex,
self.cf_ascii, self.cf_utf8, self.cf_bytes,
self.cf_suplong, self.cf_supint, self.cf_suptime,
self.cf_suplex, self.cf_supascii, self.cf_suputf8,
self.cf_supbytes,
self.cf_suplong_subint, self.cf_suplong_subint,
self.cf_suplong_subtime, self.cf_suplong_sublex,
self.cf_suplong_subascii, self.cf_suplong_subutf8,
self.cf_suplong_subbytes,
self.cf_valid_long, self.cf_valid_int, self.cf_valid_time,
self.cf_valid_lex, self.cf_valid_ascii, self.cf_valid_utf8,
self.cf_valid_bytes]
try:
self.timestamp_n = int(self.cf.get('meta')['timestamp'])
except NotFoundException:
self.timestamp_n = 0
self.clear()
开发者ID:jorgeecardona,项目名称:pycassa,代码行数:56,代码来源:test_autopacking.py
示例16: test_queue_threadlocal_failover
def test_queue_threadlocal_failover(self):
listener = _TestListener()
pool = ConnectionPool(pool_size=1, max_overflow=0, recycle=10000,
prefill=True, timeout=0.05,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=True,
server_list=['localhost:9160', 'localhost:9160'])
cf = ColumnFamily(pool, 'Standard1')
for i in range(1,5):
conn = pool.get()
setattr(conn, 'send_batch_mutate', conn._fail_once)
conn._should_fail = True
conn.return_to_pool()
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert('key', {'col': 'val%d' % i, 'col2': 'val'})
assert_equal(listener.failure_count, i)
assert_equal(cf.get('key'), {'col': 'val%d' % i, 'col2': 'val'})
pool.dispose()
listener.reset()
pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
prefill=True, timeout=0.05,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=True,
server_list=['localhost:9160', 'localhost:9160'])
cf = ColumnFamily(pool, 'Standard1')
for i in range(5):
conn = pool.get()
setattr(conn, 'send_batch_mutate', conn._fail_once)
conn._should_fail = True
conn.return_to_pool()
threads = []
args=('key', {'col': 'val', 'col2': 'val'})
for i in range(5):
threads.append(threading.Thread(target=cf.insert, args=args))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.failure_count, 5)
pool.dispose()
开发者ID:anisnasir,项目名称:pycassa,代码行数:50,代码来源:test_connection_pooling.py
示例17: setUp
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()
开发者ID:dln,项目名称:pycassa,代码行数:14,代码来源:test_batch_mutation.py
示例18: test_packing_enabled
def test_packing_enabled(self):
self.cf = ColumnFamily(pool, 'Standard1')
self.cf.insert('key', {'col': 'val'})
assert_raises(TypeError, self.cf.insert, args=('key', {123: 'val'}))
assert_raises(TypeError, self.cf.insert, args=('key', {'col': 123}))
assert_raises(TypeError, self.cf.insert, args=('key', {123: 123}))
self.cf.remove('key')
开发者ID:enki,项目名称:pycassa,代码行数:7,代码来源:test_autopacking.py
示例19: test_packing_disabled
def test_packing_disabled(self):
self.cf = ColumnFamily(pool, 'Standard1', autopack_names=False, autopack_values=False)
self.cf.insert('key', {'col': 'val'})
assert_raises(TypeError, self.cf.insert, args=('key', {123: 'val'}))
assert_raises(TypeError, self.cf.insert, args=('key', {'col': 123}))
assert_raises(TypeError, self.cf.insert, args=('key', {123: 123}))
self.cf.remove('key')
开发者ID:enki,项目名称:pycassa,代码行数:7,代码来源:test_autopacking.py
示例20: __init__
class Dictionary:
"""
Nhóm chức năng từ điển:
* Tra từ Anh-Việt
* Tra từ Việt-Anh
"""
def __init__(self):
# Connect to Cassandra servers
client = connect(cassandra_hosts)
self.d = ColumnFamily(client, cassandra_keyspace, 'Dictionary', super=True)
self.u = ColumnFamily(client, cassandra_keyspace, 'Users', super=True)
self.e = Error()
def _lookup(self, keyword, dict_type='en_vi'):
try:
return self.d.get(dict_type, super_column=str(keyword))
except (NotFoundException, InvalidRequestException):
return None
def lookup(self, environ):
try:
session_id = environ['request']['session_id']
except KeyError:
return self.e.authen_error("Thiếu session_id")
try:
self.u.get('session_id', super_column=session_id)
except (NotFoundException, InvalidRequestException):
return self.e.authen_error()
result = self._lookup(environ['request']['keyword'])
result2 = self._lookup(environ['request']['keyword'], 'vi_en')
result3 = self._lookup(environ['request']['keyword'], 'en_en')
if (result is None) and (result2 is None) and (result3 is None):
return self.e.not_found("Từ khóa bạn tìm không có trong từ điển")
xml = []
if result is not None:
xml.append('<result type="en_vi" keyword="%s" mean="%s" spell="%s" status_code="200"/>' \
% (xml_format(environ['request']['keyword']),
xml_format(result['nghia']),
xml_format(result['phien_am_quoc_te'])))
if result2 is not None:
xml.append('<result type="vi_en" keyword="%s" mean="%s" spell="" status_code="200"/>' \
% (xml_format(environ['request']['keyword']),
xml_format(result2['nghia'])))
return '\n\n'.join(xml)
def total_words(self, dict_type='en_vi'):
return self.d.get_count(dict_type)
开发者ID:AloneRoad,项目名称:MELS,代码行数:47,代码来源:dictionary.py
注:本文中的pycassa.ColumnFamily类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论