def test_get_indexed_slices(self): sys = SystemManager() for cf, keys in self.type_groups: sys.create_index(TEST_KS, cf.column_family, 'birthdate', LongType()) cf = ColumnFamily(pool, cf.column_family) for key in keys: cf.insert(key, {'birthdate': 1}) expr = create_index_expression('birthdate', 1) clause = create_index_clause([expr]) rows = list(cf.get_indexed_slices(clause)) assert_equal(len(rows), len(keys)) for k, c in rows: assert_true(k in keys) assert_equal(c, {'birthdate': 1})
def setup_package(): sys = SystemManager() if TEST_KS in sys.list_keyspaces(): sys.drop_keyspace(TEST_KS) try: sys.create_keyspace(TEST_KS, 'SimpleStrategy', {'replication_factor': '1'}) sys.create_column_family(TEST_KS, 'Standard1') sys.create_column_family(TEST_KS, 'Super1', super=True) sys.create_column_family(TEST_KS, 'Indexed1') sys.create_index(TEST_KS, 'Indexed1', 'birthdate', 'LongType') sys.create_column_family(TEST_KS, 'Counter1', default_validation_class='CounterColumnType') sys.create_column_family(TEST_KS, 'SuperCounter1', super=True, default_validation_class='CounterColumnType') except Exception, e: print e try: sys.drop_keyspace(TEST_KS) except: pass raise e
def create_cfs(self): """ Creates the Cassandra Column Families (if not exist) """ sys_mgr = None pool = None try: sys_mgr = SystemManager() pool = ConnectionPool(settings.KEYSPACE, server_list=settings.CASSANDRA_HOSTS) try: cf = ColumnFamily(pool, CF_LOGS) except: logger.info("create_cfs(): Creating column family %s", CF_LOGS) #======================================== # Column key -> CompositeType #======================================== # 1. UUID + Timestamp # 2. Host / Origin # 3. Application # 4. Severiry comparator = CompositeType(TimeUUIDType(), UTF8Type(), UTF8Type(), UTF8Type()) sys_mgr.create_column_family(settings.KEYSPACE, CF_LOGS, comparator_type=comparator) cf = ColumnFamily(pool, CF_LOGS) # cf.get_count(str(uuid.uuid4())) try: cf = ColumnFamily(pool, CF_METADATA) except: logger.info("create_cfs(): Creating column family %s", CF_METADATA) sys_mgr.create_column_family(settings.KEYSPACE, CF_METADATA, comparator_type=UTF8Type()) cf = ColumnFamily(pool, CF_METADATA) cf.get_count(str(uuid.uuid4())) try: cf = ColumnFamily(pool, CF_TIMESTAMP_BITMAP) except: logger.info("create_cfs(): Creating column family %s", CF_TIMESTAMP_BITMAP) sys_mgr.create_column_family(settings.KEYSPACE, CF_TIMESTAMP_BITMAP, comparator_type=IntegerType()) cf = ColumnFamily(pool, CF_TIMESTAMP_BITMAP) try: cf = ColumnFamily(pool, CF_MULTI_MESSAGELOGS) except: logger.info("create_cfs(): Creating column family %s", CF_MULTI_MESSAGELOGS) sys_mgr.create_column_family(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, comparator_type=UTF8Type()) cf = ColumnFamily(pool, CF_MULTI_MESSAGELOGS) sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:host', UTF8_TYPE, index_name='multimsg_host_index') sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:application', UTF8_TYPE, index_name='multimsg_application_index') sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:status', UTF8_TYPE, index_name='multimsg_finish_status_index') finally: if pool: pool.dispose() if sys_mgr: sys_mgr.close()
def create_cfs(self): """ Creates the Cassandra Column Families (if not exist) """ sys_mgr = None pool = None try: sys_mgr = SystemManager() pool = ConnectionPool(settings.KEYSPACE, server_list=settings.CASSANDRA_HOSTS) try: cf = ColumnFamily(pool, CF_LOGS) except: logger.info("create_cfs(): Creating column family %s", CF_LOGS) #======================================== # Column key -> CompositeType #======================================== # 1. UUID + Timestamp # 2. Host / Origin # 3. Application # 4. Severiry comparator = CompositeType( TimeUUIDType(), UTF8Type(), UTF8Type(), UTF8Type() ) sys_mgr.create_column_family(settings.KEYSPACE, CF_LOGS, comparator_type=comparator) cf = ColumnFamily(pool, CF_LOGS) # cf.get_count(str(uuid.uuid4())) try: cf = ColumnFamily(pool, CF_METADATA) except: logger.info("create_cfs(): Creating column family %s", CF_METADATA) sys_mgr.create_column_family(settings.KEYSPACE, CF_METADATA, comparator_type=UTF8Type()) cf = ColumnFamily(pool, CF_METADATA) cf.get_count(str(uuid.uuid4())) try: cf = ColumnFamily(pool, CF_TIMESTAMP_BITMAP) except: logger.info("create_cfs(): Creating column family %s", CF_TIMESTAMP_BITMAP) sys_mgr.create_column_family(settings.KEYSPACE, CF_TIMESTAMP_BITMAP, comparator_type=IntegerType()) cf = ColumnFamily(pool, CF_TIMESTAMP_BITMAP) try: cf = ColumnFamily(pool, CF_MULTI_MESSAGELOGS) except: logger.info("create_cfs(): Creating column family %s", CF_MULTI_MESSAGELOGS) sys_mgr.create_column_family(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, comparator_type=UTF8Type()) cf = ColumnFamily(pool, CF_MULTI_MESSAGELOGS) sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:host', UTF8_TYPE, index_name='multimsg_host_index') sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:application', UTF8_TYPE, index_name='multimsg_application_index') sys_mgr.create_index(settings.KEYSPACE, CF_MULTI_MESSAGELOGS, 'meta:status', UTF8_TYPE, index_name='multimsg_finish_status_index') finally: if pool: pool.dispose() if sys_mgr: sys_mgr.close()
""" Create the Cassandra database. """ import pycassa from pycassa.system_manager import SystemManager mgr = SystemManager() mgr.create_keyspace('drought', strategy_options={'replication_factor': '1'}) mgr.create_column_family('drought', 'cmip5') mgr.create_column_family('drought', 'zipcodes') mgr.alter_column('drought', 'zipcodes', 'ZIPCODE', pycassa.types.IntegerType()) mgr.create_index('drought', 'zipcodes', 'ZIPCODE', pycassa.types.IntegerType()) mgr.alter_column('drought', 'zipcodes', 'CENTER_LATITUDE', pycassa.types.FloatType()) mgr.alter_column('drought', 'zipcodes', 'CENTER_LONGITUDE', pycassa.types.FloatType()) mgr.create_column_family('drought', 'counties') mgr.close()