本文整理汇总了Python中pycassa.columnfamily.ColumnFamily.get方法的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily.get方法的具体用法?Python ColumnFamily.get怎么用?Python ColumnFamily.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycassa.columnfamily.ColumnFamily
的用法示例。
在下文中一共展示了ColumnFamily.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCustomTypes
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
class TestCustomTypes(unittest.TestCase):
class IntString(types.CassandraType):
@staticmethod
def pack(intval):
return str(intval)
@staticmethod
def unpack(strval):
return int(strval)
class IntString2(types.CassandraType):
def __init__(self, *args, **kwargs):
self.pack = lambda val: str(val)
self.unpack = lambda val: int(val)
def test_staticmethod_funcs(self):
self.cf = ColumnFamily(pool, 'Standard1')
self.cf.key_validation_class = TestCustomTypes.IntString()
self.cf.insert(1234, {'col': 'val'})
assert_equal(self.cf.get(1234), {'col': 'val'})
def test_constructor_lambdas(self):
self.cf = ColumnFamily(pool, 'Standard1')
self.cf.key_validation_class = TestCustomTypes.IntString2()
self.cf.insert(1234, {'col': 'val'})
assert_equal(self.cf.get(1234), {'col': 'val'})
示例2: test_alter_column_non_bytes_type
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def test_alter_column_non_bytes_type(self):
sys.create_column_family(TEST_KS, 'LongCF', comparator_type=LONG_TYPE)
sys.create_index(TEST_KS, 'LongCF', 3, LONG_TYPE)
pool = ConnectionPool(TEST_KS)
cf = ColumnFamily(pool, 'LongCF')
cf.insert('key', {3: 3})
assert_equal(cf.get('key')[3], 3)
sys.alter_column(TEST_KS, 'LongCF', 2, LONG_TYPE)
cf = ColumnFamily(pool, 'LongCF')
cf.insert('key', {2: 2})
assert_equal(cf.get('key')[2], 2)
示例3: test_static_composite
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def test_static_composite(cls):
sys = SystemManager()
have_composites = sys._conn.version != CASSANDRA_07
if not have_composites:
raise SkipTest("Cassandra < 0.8 does not composite types")
sys.create_column_family(TEST_KS, 'StaticComposite',
comparator_type=CompositeType(LongType(),
IntegerType(),
TimeUUIDType(reversed=True),
LexicalUUIDType(reversed=False),
AsciiType(),
UTF8Type(),
BytesType()))
cf = ColumnFamily(pool, 'StaticComposite')
colname = (127312831239123123, 1, uuid.uuid1(), uuid.uuid4(), 'foo', u'ba\u0254r', 'baz')
cf.insert('key', {colname: 'val'})
assert_equal(cf.get('key'), {colname: 'val'})
u1 = uuid.uuid1()
u4 = uuid.uuid4()
col0 = (0, 1, u1, u4, '', '', '')
col1 = (1, 1, u1, u4, '', '', '')
col2 = (1, 2, u1, u4, '', '', '')
col3 = (1, 3, u1, u4, '', '', '')
col4 = (2, 1, u1, u4, '', '', '')
cf.insert('key2', {col0: '', col1: '', col2: '', col3: '', col4: ''})
result = cf.get('key2', column_start=((1, True),), column_finish=((1, True),))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1,), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=((1, True),), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, ), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=((0, False), ), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, 1), column_finish=(1, 3))
assert_equal(result, {col1: '', col2: ''})
result = cf.get('key2', column_start=(1, 1), column_finish=(1, (3, True)))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, (1, True)), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
sys.drop_column_family(TEST_KS, 'StaticComposite')
示例4: test_column_validators
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def test_column_validators(self):
validators = {'name': UTF8_TYPE, 'age': LONG_TYPE}
sys.create_column_family(TEST_KS, 'ValidatedCF',
column_validation_classes=validators)
pool = ConnectionPool(TEST_KS)
cf = ColumnFamily(pool, 'ValidatedCF')
cf.insert('key', {'name': 'John', 'age': 40})
self.assertEquals(cf.get('key'), {'name': 'John', 'age': 40})
validators = {'name': ASCII_TYPE, 'age': INT_TYPE}
sys.alter_column_family(TEST_KS, 'ValidatedCF',
column_validation_classes=validators)
cf.load_schema()
self.assertEquals(cf.get('key'), {'name': 'John', 'age': 40})
示例5: test_static_composite_slicing
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def test_static_composite_slicing(self):
cf = ColumnFamily(pool, 'StaticComposite')
u1 = uuid.uuid1()
u4 = uuid.uuid4()
col0 = (0, 1, u1, u4, '', '', '')
col1 = (1, 1, u1, u4, '', '', '')
col2 = (1, 2, u1, u4, '', '', '')
col3 = (1, 3, u1, u4, '', '', '')
col4 = (2, 1, u1, u4, '', '', '')
cf.insert('key2', {col0: '', col1: '', col2: '', col3: '', col4: ''})
result = cf.get('key2', column_start=((1, True),), column_finish=((1, True),))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1,), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=((1, True),), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, ), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=((0, False), ), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, 1), column_finish=(1, 3))
assert_equal(result, {col1: '', col2: ''})
result = cf.get('key2', column_start=(1, 1), column_finish=(1, (3, True)))
assert_equal(result, {col1: '', col2: '', col3: ''})
result = cf.get('key2', column_start=(1, (1, True)), column_finish=((2, False), ))
assert_equal(result, {col1: '', col2: '', col3: ''})
示例6: test_static_composite_slicing
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def test_static_composite_slicing(self):
cf = ColumnFamily(pool, "StaticComposite")
u1 = uuid.uuid1()
u4 = uuid.uuid4()
col0 = (0, 1, u1, u4, "", "", "")
col1 = (1, 1, u1, u4, "", "", "")
col2 = (1, 2, u1, u4, "", "", "")
col3 = (1, 3, u1, u4, "", "", "")
col4 = (2, 1, u1, u4, "", "", "")
cf.insert("key2", {col0: "", col1: "", col2: "", col3: "", col4: ""})
result = cf.get("key2", column_start=((1, True),), column_finish=((1, True),))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=(1,), column_finish=((2, False),))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=((1, True),), column_finish=((2, False),))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=(1,), column_finish=((2, False),))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=((0, False),), column_finish=((2, False),))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=(1, 1), column_finish=(1, 3))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=(1, 1), column_finish=(1, (3, True)))
assert_equal(result, {col1: "", col2: "", col3: ""})
result = cf.get("key2", column_start=(1, (1, True)), column_finish=((2, False),))
assert_equal(result, {col1: "", col2: "", col3: ""})
示例7: Processor
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
class Processor(Llama):
def __init__(self, client, qname):
super(Processor, self).__init__(client, qname)
self.pool = ConnectionPool('processing_llama_Processor')
self.trends = ColumnFamily(self.pool, 'Trend')
def get_sleep_time():
return 60
def do_message(self, message):
if not isinstance(message, tuple) or len(message) != 4:
return
woeid, as_of, trend_name, query = message
try:
trend = self.trends.get(trend_name, super_column=woeid)
trend['lastseen'] = as_of
trend['number_seen'] += 1
trend = { woeid: trend }
self.trends.insert(trend_name, trend)
except ttypes.NotFoundException:
self.trends.insert(trend_name, { woeid: { 'firstseen': as_of, 'lastseen': as_of, 'number_seen': 1}})
self.trends.insert(trend_name, {'data': { 'query': query, 'tracking': "False" }})
def has_many_woeids(self, x):
key, values = x
return len(values) > 2 # one woeid plus general data
def do_action(self):
try:
for trend_name, country_specifics in filter(self.has_many_woeids, self.trends.get_range()):
if country_specifics['data']['tracking'] == "False":
self.track_trend(trend_name, country_specifics['data']['query'], filter(lambda x: x != "data", country_specifics.keys()))
except:
exc, value, exctraceback = sys.exc_info()
logging.error("Error in processing_llama.processor.Processor.do_action:\n" + traceback.format_exc())
traceback.print_tb(exctraceback)
def track_trend(self, trend_name, query, woeids):
logging.info("Tracking %s from %s" % (trend_name, woeids))
self.mark_tracking(trend_name)
self.publish((trend_name, query, woeids), "trend_to_track")
def mark_tracking(self, trend_name):
try:
trend = self.trends.get(trend_name, super_column='data')
trend['tracking'] = "True"
self.trends.insert(trend_name, { 'data': trend })
except ttypes.NotFoundException:
pass
示例8: get_builder
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def get_builder(self, builder_id):
"""Obtain info about a builder from its ID."""
cf = ColumnFamily(self.pool, 'builders')
try:
return cf.get(builder_id)
except NotFoundException:
return None
示例9: get_reverse
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def get_reverse(columnFamily, key) :
"select values in a given column family"
try :
column = ColumnFamily(pool, columnFamily)
return column.get(key,column_reversed=True)
except:
return {'status':0}
示例10: get_row_key_id
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def get_row_key_id(domain):
counter_column, counter_lock = domain_counter_map[domain]
## acquire lock before getting value of
counter_lock.acquire()
try:
client = db_connection.get_client()
cf = ColumnFamily(client, CONFIG_DOMAIN)
## get new key id
id_key = cf.get(CONFIG_ROW, counter_column)[counter_column]
## increment value if not None
if id_key:
new_id_key = id_key + 1
cf.insert(CONFIG_ROW, {counter_column: new_id_key}, write_consistency_level=ConsistencyLevel.ALL)
return id_key
"""
if id_key:
str_id_key = str(id_key)
str_id_key.zfill(MAX_PADDING_RANGE)
return str_id_key
else:
return None
"""
finally:
## release lock before returning from this function
counter_lock.release()
示例11: CassandraRepository
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
class CassandraRepository(object):
def __init__(self, keyspace, column_family_name):
self.pool = ConnectionPool(keyspace,
cassandra_settings.NODE_POOL)
self.cf = ColumnFamily(self.pool, column_family_name)
self.batch = {}
def add_batch(self, batch, start_time=None):
"""
:param batch:
"""
self.cf.batch_insert(batch)
if start_time is not None:
print 'time to insert batch: %s ms' % (int(time.time() * 1000) - start_time)
def get(self, timestamp):
return self.cf.get(str(timestamp))
def get_range(self, start, end):
return list(self.cf.get_range(start=str(start), finish=str(end)))
def close(self):
self.sys.close()
示例12: _get_analytics_ttls
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def _get_analytics_ttls(self):
ret_row = {}
try:
col_family = ColumnFamily(self._pool, SYSTEM_OBJECT_TABLE)
row = col_family.get(SYSTEM_OBJECT_ANALYTICS)
except Exception as e:
self._logger.error("Exception: analytics_start_time Failure %s" % e)
ret_row[SYSTEM_OBJECT_FLOW_DATA_TTL] = AnalyticsFlowTTL
ret_row[SYSTEM_OBJECT_STATS_DATA_TTL] = AnalyticsStatisticsTTL
ret_row[SYSTEM_OBJECT_CONFIG_AUDIT_TTL] = AnalyticsConfigAuditTTL
ret_row[SYSTEM_OBJECT_GLOBAL_DATA_TTL] = AnalyticsTTL
return ret_row
if (SYSTEM_OBJECT_FLOW_DATA_TTL not in row):
ret_row[SYSTEM_OBJECT_FLOW_DATA_TTL] = AnalyticsFlowTTL
else:
ret_row[SYSTEM_OBJECT_FLOW_DATA_TTL] = row[SYSTEM_OBJECT_FLOW_DATA_TTL]
if (SYSTEM_OBJECT_STATS_DATA_TTL not in row):
ret_row[SYSTEM_OBJECT_STATS_DATA_TTL] = AnalyticsStatisticsTTL
else:
ret_row[SYSTEM_OBJECT_STATS_DATA_TTL] = row[SYSTEM_OBJECT_STATS_DATA_TTL]
if (SYSTEM_OBJECT_CONFIG_AUDIT_TTL not in row):
ret_row[SYSTEM_OBJECT_CONFIG_AUDIT_TTL] = AnalyticsConfigAuditTTL
else:
ret_row[SYSTEM_OBJECT_CONFIG_AUDIT_TTL] = row[SYSTEM_OBJECT_CONFIG_AUDIT_TTL]
if (SYSTEM_OBJECT_GLOBAL_DATA_TTL not in row):
ret_row[SYSTEM_OBJECT_GLOBAL_DATA_TTL] = AnalyticsTTL
else:
ret_row[SYSTEM_OBJECT_GLOBAL_DATA_TTL] = row[SYSTEM_OBJECT_GLOBAL_DATA_TTL]
return ret_row
示例13: build_from_id
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def build_from_id(self, build_id):
"""Obtain information about a build from its ID."""
cf = ColumnFamily(self.pool, 'builds')
try:
return cf.get(build_id)
except NotFoundException:
return None
示例14: _get_analytics_start_time
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def _get_analytics_start_time(self):
try:
col_family = ColumnFamily(self._pool, SYSTEM_OBJECT_TABLE)
row = col_family.get(SYSTEM_OBJECT_ANALYTICS)
except Exception as e:
self._logger.error("Exception: analytics_start_time Failure %s" % e)
return None
# Initialize the dictionary before returning
if (SYSTEM_OBJECT_START_TIME not in row):
return None
ret_row = {}
ret_row[SYSTEM_OBJECT_START_TIME] = row[SYSTEM_OBJECT_START_TIME]
if (SYSTEM_OBJECT_FLOW_START_TIME not in row):
ret_row[SYSTEM_OBJECT_FLOW_START_TIME] = row[SYSTEM_OBJECT_START_TIME]
else:
ret_row[SYSTEM_OBJECT_FLOW_START_TIME] = row[SYSTEM_OBJECT_FLOW_START_TIME]
if (SYSTEM_OBJECT_STAT_START_TIME not in row):
ret_row[SYSTEM_OBJECT_STAT_START_TIME] = row[SYSTEM_OBJECT_START_TIME]
else:
ret_row[SYSTEM_OBJECT_STAT_START_TIME] = row[SYSTEM_OBJECT_STAT_START_TIME]
if (SYSTEM_OBJECT_MSG_START_TIME not in row):
ret_row[SYSTEM_OBJECT_MSG_START_TIME] = row[SYSTEM_OBJECT_START_TIME]
else:
ret_row[SYSTEM_OBJECT_MSG_START_TIME] = row[SYSTEM_OBJECT_MSG_START_TIME]
return ret_row
示例15: getByTag
# 需要导入模块: from pycassa.columnfamily import ColumnFamily [as 别名]
# 或者: from pycassa.columnfamily.ColumnFamily import get [as 别名]
def getByTag(tag):
con = util.getConnection()
vidCF = ColumnFamily(con, 'videos')
tagCF = ColumnFamily(con, 'tag_videos')
movies = tagCF.get(tag.strip().lower())
for key, val in movies.iteritems():
vidId = key.split('_')[1]
movieDetail = vidCF.get(vidId)
print '''
{{
user: {0},
movie: {1},
tags: {2}
}}'''.format(movieDetail['user_name'], movieDetail['title'], movieDetail['tags_csv'])
con.dispose()