def __init__(self):
 
     dbconn = cql.connect(config_local.cassandra_host, config_local.cassandra_port) 
     cursor = dbconn.cursor()
     
     try:
         cursor.execute(""" USE :keyspace """, dict(keyspace = config_global.cassandra_default_keyspace))
     except cql.ProgrammingError as programmingError:
         print programmingError
     
     try:    
         cursor.execute(""" DROP COLUMNFAMILY :columnfamily; """, dict(columnfamily = config_global.dbname_usersByItemId))
         pass
     except cql.ProgrammingError as programmingError:
         print programmingError
     try:
         cursor.execute(""" CREATE COLUMNFAMILY :columnfamily ( 
             item_id bigint PRIMARY KEY )
             WITH comparator=timestamp AND default_validation=int; """, 
             dict(columnfamily = config_global.dbname_usersByItemId))
     except cql.ProgrammingError as programmingError:
         print programmingError
     
 
     currentTime = getTimestamp.gettimeStampInMicroseconds()
     print "currentTime: "
     print int(currentTime)
     
     for item_id in xrange(5):
         for i in xrange(5):
             #currentTime = int(time.time())
             currentTime = getTimestamp.gettimeStampInMicroseconds()
             #print int(currentTime)
 
             user_id = int( random.uniform(0,10000) )
             cursor.execute(""" INSERT INTO :table (item_id, :currentTime) VALUES (:item_id, :user_id)
             USING TTL 10""", 
                             dict(table=config_global.dbname_usersByItemId, 
                             currentTime = currentTime,
                             user_id = user_id,
                             item_id = item_id
                             ) 
                            )
             #time.sleep(0.5)
     
 
     cursor.execute("SELECT * FROM :table WHERE item_id = 1", dict(table=config_global.dbname_usersByItemId))
     print cursor.fetchall()
     print cursor.description
Example #2
0
	def __init__(self, json_string=None, mode='cassandra', incomingTime = None):
		super(rawJsonModel, self).__init__(mode)
		
		self.mode = mode
		if incomingTime == None:
			self.timestamp = getTimestamp.gettimeStampInMicroseconds()
		else:
			self.timestamp = incomingTime
		self.json_string = json_string
		
		if (mode == 'redis'):
			self.redis_con = redis.Redis("localhost")
			
			
		if (mode == 'cassandra'):
			self.column_family = config_global.dbname_rawJson
				
			try:
				self.conn.cursor.execute("USE " + config_global.cassandra_default_keyspace)
								
			except cql.ProgrammingError as programmingError:
				print programmingError
				
		if (mode == 'sqlite'):
					import sqlite3
					self.conn = sqlite3.connect('/home/karisu/database/sqlite_storage') 
					''' @todo: change the path '''
Example #3
0
 def save(self, user_id):
     self.conn.cursor.execute("""USE :keyspace""", dict(keyspace = config_global.cassandra_default_keyspace))
     currentTime = getTimestamp.gettimeStampInMicroseconds()        
     self.conn.cursor.execute(""" INSERT INTO :table (item_id, :currentTime) 
                                 VALUES (:item_id, :user_id) """, 
                         dict(table=config_global.dbname_usersByItemId, 
                         currentTime = currentTime,
                         item_id = self.item_id,
                         user_id = user_id
                         ) 
                        )
    def test_SaveMessage_interpretedJson_async(self):
        ''' tests the generation of the writeBack of the interpreted data coming in from the contest messages
        '''
        backends = [config_global.SAVE_HADOOP_SINK, config_global.SAVE_RANDOM_RECOMMENDER]
        userid = 5678
        domainid = 8

        sM = SaveMessage()
        for itemid in xrange(5):
            timestamp = getTimestamp.gettimeStampInMicroseconds()
            id_list = {'userid': userid, 'itemid': itemid, 'timestamp': timestamp, 'domainid': domainid}

            sM.save(id_list, async=True, api='id_list', backends=backends)
    def __init__(self):
        columnfamily = config_global.dbname_message_ids

        dbconn = cql.connect(config_local.cassandra_host, config_local.cassandra_port)
        cursor = dbconn.cursor()

        try:
            cursor.execute(""" USE :keyspace """, dict(keyspace=config_global.cassandra_default_keyspace))
        except cql.ProgrammingError as programmingError:
            print programmingError

        try:
            cursor.execute(""" DROP COLUMNFAMILY :columnfamily; """, dict(columnfamily=columnfamily))
            pass
        except cql.ProgrammingError as programmingError:
            print programmingError
        try:
            cursor.execute(
                """ CREATE COLUMNFAMILY :columnfamily ( 
                KEY varchar PRIMARY KEY )
                WITH comparator=timeuuid AND default_validation=bigint; """,
                dict(columnfamily=columnfamily),
            )
        except cql.ProgrammingError as programmingError:
            print programmingError

        currentTime = getTimestamp.gettimeStampInMicroseconds()
        print "currentTime: "
        print int(currentTime)

        for impression_id in xrange(5000):
            # currentTime = getTimestamp.gettimeStampInMicroseconds()
            currentTime = impression_id
            cursor.execute(
                """ INSERT INTO :table ( KEY , :currentTime) 
            VALUES (impression_list, :impression_id)
            USING TTL 10""",
                dict(table=columnfamily, currentTime=currentTime, impression_id=1327522),
            )

        # cursor.execute("SELECT FIRST 5 REVERSED 7..3 FROM :table WHERE KEY = 'impression_list'",
        #               dict(table=columnfamily))

        cursor.execute(
            "SELECT FIRST 5000 REVERSED * FROM :table WHERE KEY = 'impression_list'", dict(table=columnfamily)
        )
        result = cursor.fetchone()
        print result
        print len(result)
	def __init__(self, id, data = None, mode = 'redis'):
		""" init """
		if (mode == 'redis'):
			""" @todo redis implementation """
			
		elif (mode == 'cassandra'):
		
			super(interpretedJsonModel, self).__init__(mode)
			self.column_family = config_global.dbname_interpretedJson
		
			self.timestamp = getTimestamp.gettimeStampInMicroseconds() 
			""" wrong place for this """
			
			self.obligatoryData = dict(column_family = self.column_family, id = id)
			self.data = data
		
			try:
				self.conn.cursor.execute("USE " + config_global.cassandra_default_keyspace)
							
			except cql.ProgrammingError as programmingError:
				print programmingError