def exportJsonDB(json_data, frameNum): """ Exports the JSON data to the Accumulo database """ conn = Accumulo(host="localhost", port=50096, user="******", password="******") json_data_parsed = json.loads( json_data) #put json data back into dictionary table = json_data_parsed['videoMetadata'][ 'videoName'] #get the video name and set that as the table name table = table.replace('.', '_') table = table.encode('ascii', 'ignore') if not conn.table_exists(table): conn.create_table(table) m = Mutation("row_%d" % frameNum) #table row number is the frame number m.put(cf="cf2", cq="cq2", val=json_data_parsed['imageBase64'] ) #saves the frame image separately from the metadata if 'LabeledImage' in json_data_parsed.keys(): m.put(cf="cf3", cq="cq3", val=json_data_parsed['LabeledImage'] ) #saves the labeled image separately from the metadata json_data_parsed.pop( 'LabeledImage', None) #delete the base64 representation of the labeled frame json_data_parsed.pop( 'imageBase64', None) #delete the base64 representation of the frame json_data = json.dumps(json_data_parsed) m.put(cf="cf1", cq="cq1", val=json_data) #set the first column to now only the metadata. conn.write(table, m) conn.close()
def printTableDB(table): """ Displays the data in the database """ conn = Accumulo(host="localhost", port=50096, user="******", password="******") for entry in conn.scan(table): print(entry.row, entry.cf, entry.cq, entry.cv, entry.ts, entry.val) conn.close()
wr.close() if conn.table_exists(table1): conn.delete_table(table1) conn.create_table(table1) wr = conn.create_batch_writer(table1) print "Ingesting some data ..." f = open("/bdsetup/drilllogs.txt", "rb") for i in range(250): line = f.readline().rstrip() label = '%04d' % i mut = Mutation('r_%s' % label) mut.put(cq='cq1', val=line) #mut.put(cf='cf_%s'%label, cq='cq1', val=line) #mut.put(cf='cf_%s'%label, cq='cq2', val=line) wr.add_mutation(mut) i += 1 wr.close() # print "Rows 001 through 003 ..." # for entry in conn.scan(table, scanrange=Range(srow='r_0001', erow='r_0003'), cols=[]): # print entry # print "Rows 001 and 011 ..." # for entry in conn.batch_scan(table, scanranges=[Range(srow='r_001', erow='r_001'), Range(srow='r_011', erow='r_011')]): # print entry conn.close()
table = "pythontest" conn = Accumulo(host=settings.HOST, port=settings.PORT, user=settings.USER, password=settings.PASSWORD) if conn.table_exists(table): conn.delete_table(table) conn.create_table(table) wr = conn.create_batch_writer(table) print "Ingesting some data ..." for num in range(1, 100): label = '%03d'%num mut = Mutation('r_%s'%label) mut.put(cf='cf_%s'%label, cq='cq1', val='value_%s'%label) mut.put(cf='cf_%s'%label, cq='cq2', val='value_%s'%label) wr.add_mutation(mut) wr.close() print "Rows 001 through 003 ..." for entry in conn.scan(table, scanrange=Range(srow='r_001', erow='r_003'), cols=[]): print entry print "Rows 001 and 011 ..." for entry in conn.batch_scan(table, scanranges=[Range(srow='r_001', erow='r_001'), Range(srow='r_011', erow='r_011')]): print entry conn.close()