] # Simulate updates keys = sorted(list(records.keys())) for _ in range(10): for key in keys: for j in range(1, grades_table.num_columns): value = randint(0, 20) records[key][j] = value keys = sorted(list(records.keys())) for key in keys: print(records[key]) print(records[key]) for key in keys: record = query.select(key, 0, [1, 1, 1, 1, 1])[0] error = False for i, column in enumerate(record.columns): if column != records[key][i]: error = True if error: print('select error on', key, ':', record, ', correct:', records[key]) print("Select finished") deleted_keys = sample(keys, 100) for key in deleted_keys: query.delete(key) records.pop(key, None) for i in range(0, 100): r = sorted(sample(range(0, len(keys)), 2))
temp_record = [1,1,1,1,1] temp_key = -1 insert_transactions[2].add_query(q.select, q.table, temp_key, 0, temp_record) for i in range(30, 40): insert_transactions[3].add_query(q.insert, q.table, *records[keys[i]]) pass for transaction_worker in transaction_workers: transaction_worker.run() db.close() db = Database() db.open('./ECS165') grades_table = db.get_table('Grades') # select records between 20 and 24 to ensure they are rolled back q = Query(grades_table) #print("testing insertion rollback") for i in range(20, 25): result = q.select(keys[i], 0, [1, 1, 1, 1, 1]) if result is False: print("record was rolled back nice :)") else: print("record not rolled back ;(") db.close()
[None, randrange(0, 100), None, None, None], [None, None, randrange(0, 100), None, None], [None, None, None, randrange(0, 100), None], [None, None, None, None, randrange(0, 100)], ] update_time_0 = process_time() for i in range(0, 10000): query.update(choice(keys), *(choice(update_cols))) update_time_1 = process_time() print("Updating 10k records took: \t\t\t", update_time_1 - update_time_0) # Measuring Select Performance select_time_0 = process_time() for i in range(0, 10000): query.select(choice(keys), 0, [1, 1, 1, 1, 1]) select_time_1 = process_time() print("Selecting 10k records took: \t\t\t", select_time_1 - select_time_0) # Measuring Aggregate Performance agg_time_0 = process_time() for i in range(0, 10000, 100): result = query.sum(i, 100, randrange(0, 5)) agg_time_1 = process_time() print("Aggregate 10k of 100 record batch took:\t", agg_time_1 - agg_time_0) # Measuring Delete Performance delete_time_0 = process_time() for i in range(0, 10000): query.delete(906659671 + i) delete_time_1 = process_time()
from template.db import Database from template.query import Query import os ''' READ ME!! Before using this demo, be sure that the Tail_Const is set to a value high enough to guaranteed that all updates are contained within the same block. config.py -> TAIL_CONST = 4 This program is meant to run sequentially through all parts starting with an empty ECS165 directory. ''' db2 = Database() db2.open("ECS165") #db2.open() print(db2) g_table = db2.get_table('Grades') q = Query(g_table) rec3 = q.select(92106429, 0, [1, 1, 1, 1, 1])[0] rec4 = q.select(92106430, 0, [1, 1, 1, 1, 1])[0] print("Rec = ", rec3) print("Rec2 = ", rec4) rec3f = q.selectFull(92106429, 0) rec4f = q.selectFull(92106430, 0) print("Rec_full = ", rec3f) print("Rec2_full = ", rec4f) db2.close()
key = 92106429 + i records[key] = [key, randint(0, 20), randint(0, 20), randint(0, 20), randint(0, 20)] query.insert(*records[key]) keys = sorted(list(records.keys())) print("Insert finished") grades_table.index.create_index(1) grades_table.index.create_index(2) grades_table.index.create_index(3) grades_table.index.create_index(4) _records = [records[key] for key in keys] for c in range(grades_table.num_columns): _keys = list(set([record[c] for record in _records])) index = {v: [record for record in _records if record[c] == v] for v in _keys} for key in _keys: results = [r.columns for r in query.select(key, c, [1, 1, 1, 1, 1])] error = False if len(results) != len(index[key]): error = True if not error: for record in index[key]: if record not in results: error = True break if error: print('select error on', key, ', column', c, ':', results, ', correct:', index[key]) print("Select finished") exit()
query.select, key, c, [1, 1, 1, 1, 1]) t += 1 for j in range(0, num_threads): for key in worker_keys[j]: updated_columns = [None, None, None, None, None] for i in range(1, grades_table.num_columns): value = randint(0, 20) updated_columns[i] = value records[key][i] = value query = Query(grades_table) update_transactions[j].add_query(query.update, key, *updated_columns) updated_columns = [None, None, None, None, None] for transaction_worker in transaction_workers: transaction_worker.run() score = len(keys) for key in keys: correct = records[key] query = Query(grades_table) #TODO: modify this line based on what your SELECT returns result = query.select(key, 0, [1, 1, 1, 1, 1])[0].columns if correct != result: print('select error on primary key', key, ':', result, ', correct:', correct) score -= 1 print('Score', score, '/', len(keys)) db.close()
Before using this demo, be sure that the Tail_Const is set to a value high enough to guaranteed that all updates are contained within the same block. config.py -> TAIL_CONST = 4 This program is meant to run sequentially through all parts starting with an empty ECS165 directory. ''' db = Database() db.open('ECS165') grades_table = db.get_table("Grades") q = Query(grades_table) keys = [] loop = 1000 rec = q.select(92106429, 0, [1, 1, 1, 1, 1])[0] rec2 = q.select(92106430, 0, [1, 1, 1, 1, 1])[0] print("Original Record Contents: ") print(rec) print(rec2) print("Update Test ", loop, " times:") record = q.select(92106429, 0, [1, 1, 1, 1, 1])[0] updater = [None, None, 100, None, None] updater2 = [None, None, None, 100, None] for x in range(loop): rec3 = q.select(92106429, 0, [1, 1, 1, 1, 1])[0] q.update(92106429, *updater) #print(rec3) q.update(92106430, *updater2)
Before using this demo, be sure that the Tail_Const is set to a value high enough to guaranteed that all updates are contained within the same block. config.py -> TAIL_CONST = 4 This program is meant to run sequentially through all parts starting with an empty ECS165 directory. ''' db = Database() db.open('ECS165') print("Creating tables: 'Grades'") grades_table = db.create_table('Grades', 5, 0) query = Query(grades_table) keys = [] # Measuring Insert Performance print("Inserting two records, Keys= 92106429, 2106430") query.insert(92106429, 93, 5, 7, 0) query.insert(92106430, 8, 7, 6, 5) rec = query.select(92106429, 0, [1, 1, 1, 1, 1])[0] rec2 = query.select(92106430, 0, [1, 1, 1, 1, 1])[0] print("Printing record data contents") print(rec) print(rec2) rec = query.selectFull(92106429, 0) rec2 = query.selectFull(92106430, 0) print("Printing full record contents") print(rec) print(rec2) db.close()
seed(3562901) for i in range(0, 1000): key = 92106429 + i records[key] = [ key, randint(0, 20), randint(0, 20), randint(0, 20), randint(0, 20) ] query.insert(*records[key]) keys = sorted(list(records.keys())) print("Insert finished") for key in keys: record = query.select(key, 0, [1, 1, 1, 1, 1])[0] # original line # record = query.select(key, [1, 1, 1, 1, 1])[0] # line to test functionality without index implemented error = False for i, column in enumerate(record.columns): if column != records[key][i]: error = True if error: print('select error on', key, ':', record, ', correct:', records[key]) # else: # print('select on', key, ':', record) print("Select finished") for _ in range(10): for key in keys: updated_columns = [None, None, None, None, None] for i in range(1, grades_table.num_columns):
grades_table.index.create_index(1) grades_table.index.create_index(2) grades_table.index.create_index(3) grades_table.index.create_index(4) _records = [records[key] for key in keys] for c in range(grades_table.num_columns): _keys = list(set(record[c] for record in _records)) index = { v: [record for record in _records if record[c] == v] for v in _keys } for key in _keys: # results = query.select(key, c, [1, 1, 1, 1, 1]) results = [r.columns for r in query.select(key, c, [1, 1, 1, 1, 1])] error = False if len(results) != len(index[key]): print("len incorrect") error = True if not error: for record in index[key]: if record not in results: error = True break if error: print('select error on', key, ', column', c, ':', results, ', correct:', index[key]) print("Select finished")
sys.exit() ''' # Student Id and 4 grades db = Database() db.open('ECS165') grades_table = db.create_table('Grades', 5, 0) query = Query(grades_table) keys = [] # Measuring Insert Performance query.insert(92106429, 93, 5, 7, 0) query.insert(92106430, 8, 7, 6, 5) rec = query.select(92106429, [1,1,1,1,1])[0] rec2 = query.select(92106430, [1,1,1,1,1])[0] print(rec) print(rec2) #print(rec.rid, rec.key, rec.columns) #print(rec2.rid, rec2.key, rec2.columns) # print("Update Test:") record = query.select(rec2.key, [1, 1, 1, 1, 1])[0] updater = [None,None,100,None,None] updater2 =[None,None,None,100,None] query.update(92106429, *updater) rec3 = query.select(92106429, [1,1,1,1,1])[0] print(rec3) query.update(92106429, *updater2) rec4 = query.select(92106429, [1,1,1,1,1])[0]
seed(3562901) for i in range(0, 1000): key = 92106429 + i records[key] = [ key, randint(0, 20), randint(0, 20), randint(0, 20), randint(0, 20) ] query.insert(*records[key]) keys = sorted(list(records.keys())) print("Insert finished") for key in keys: record = query.select(key, 0, [1, 1, 1, 1, 1])[0] error = False for i, column in enumerate(record.columns): if column != records[key][i]: error = True if error: print('select error on', key, ':', record, ', correct:', records[key]) # else: # print('select on', key, ':', record) print("Select finished") for i in range(1, 5): index.create_index(i) for _ in range(10): for key in keys: