from template.db import Database from template.query import Query from template.transaction import Transaction from template.transaction_worker import TransactionWorker from template.config import init from template.lock_manager_config import * from random import choice, randint, sample, seed # TESTING REMOVEAL ABORT init() db = Database() db.open('./ECS165') grades_table = db.create_table('Grades', 5, 0) keys = [] records = {} seed(3562901) num_threads = 4 try: grades_table.index.create_index(1) grades_table.index.create_index(2) grades_table.index.create_index(3) grades_table.index.create_index(4) except Exception as e: print('Index API not implemented properly, tests may fail.') transaction_workers = [] insert_transactions = [] select_transactions = [] update_transactions = []
from template.db import Database from template.query import Query from time import process_time from random import choice, randrange # Student Id and 4 grades db = Database() grades_table = db.create_table('Grades', 0, 5) query = Query(grades_table) keys = [] insert_time_0 = process_time() for i in range(0, 10000): query.insert(906659671 + i, 93, 0, 0, 0) keys.append(906659671 + i) insert_time_1 = process_time() print("Inserting 10k records took: \t\t\t", insert_time_1 - insert_time_0) # Measuring update Performance update_cols = [ [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), 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)))
from template.db import Database database = Database() grades_table = database.create_table('Grades', 5, 0) # retValue = database.get_table('Grades') # print(retValue) # db_length = len(database.tables_directory) # print(db_length) sec_grades_table = database.create_table('Grades2', 5, 0) retNewTable = database.get_table('Grades2') print(retNewTable) db_length2 = len(database.tables_directory) print("Data base length:",db_length2) print("Table name:",sec_grades_table.name) print("Table key",sec_grades_table.Table_key) print("Table columns:",sec_grades_table.num_columns) print("Table page directory:",sec_grades_table.page_directory) print("Table index:",sec_grades_table.index) print("Table record directory:",sec_grades_table.record_directory) print("Table prange:",sec_grades_table.prange_num) print("Table free base rid:",sec_grades_table.free_brid) print("Table free tail rid:",sec_grades_table.free_trid) print("Before calling drop", len(database.tables_directory)) database.drop_table('Grades') print("After calling drop", len(database.tables_directory))
from template.table import * import pickle import io import os from template.query import * from random import choice, randint, sample, seed from template.db import Database from time import process_time db = Database() db.open('./ECS165') newtable = db.create_table('nidaye', 5, 0) query = Query(newtable) keys = [] for i in range(0, 5): query.insert(1 + i, 93, 0, 0, 0) keys.append(1 + i) # update_time_0 = process_time() for i in range(0, 4): up = [0, 94, 1, 1, 1] query.update(1 + i, *up) for i in range(0, 2): up = [0, 95, 2, 1, 1] query.update(1 + i, *up) # query.update(906659671, 5, 5, 5, 5, 5) # query.update(906659671, 5, 5, 5, 6, 5) # query.update(906659671, 5, 2, 5, 6, 5) records = query.select(95, 1, [1, 1, 1, 1, 1])
#query.update(9999,*update_data) #[9999, 4, 3, None, 1] #query.update(9999,*update_data2) #[9999, 4, 2, 4, 1] #query.update(9990, *update_data3) #[9990, 4, 2, None, 2] #query.update(9999, *update_data4) #[9999, None, None, None, None] # value = query.sum(4, 5, 1) # # data = table.read_record(9999) # print(value) db = Database() db.open('./ECS165') os.mkdir('./ECS165/table1') os.mkdir('./ECS165/table2') f = open('./ECS165/table1/table1.pkl', 'wb') # f = open('./ECS165/table1/table.pkl') grades_table = db.create_table('table1', 5, 0) # grades_table.index = None query = Query(grades_table) keys = [] insert_time_0 = process_time() for i in range(0, 10): query.insert(906659671 + i, 93, 0, 0, 0) keys.append(906659671 + i) # insert_time_1 = process_time() indexFile = open('./ECS165/table1/table1_index.txt', 'w') for node in grades_table.index.indices[0].iteritems(): # indexFile.write(str(node.key())) key = node[0] # print(key) indexFile.write(str(key) + "+")
from template.db import Database from template.query import Query from template.index import * import time db = Database() db.open("./ECS165") grades_table = db.create_table('QueryTester', 5, 0) #index = Index(grades_table) query = Query(grades_table) # print("Inserting 1M items") for i in range(1_001): query.insert(*[i, i, i + 1, i + 2, i + 3]) for record in query.select_range(500, 525, 0, [1, 1, 1, 1, 1]): print(record.columns) #query.insert(*[1, 2, 3, 4, 5]) # <- #query.insert(*[1, 3, 4, 5, 6]) #query.insert(*[2, 1, 3, 3, 4]) # query.select(2, 1, [None, None, None, None, 1])[0].columns #index.drop_index(1) #print(query.select(2, 1, [1, 1, 1, 1, 1])[0].columns) #print(query.select(4, 2, [1, None, None, None, None])[0].columns[0]) """print(query.delete(1)) print(query.select(2, 1, [None, None, None, None, 1])) print(query.select(3, 1, [None, None, None, None, 1])) print(query.select(2,0,[None, None, None, None, 1]))""" query.insert(*[42, 42, 3, 4, 5])
from template.db import Database from template.query import Query from time import process_time from random import choice, randrange # Student Id and 4 grades db = Database() grades_table = db.create_table('Grades', 5, 0) # Swapped the 0 and 5 query = Query(grades_table) keys = [] insert_time_0 = process_time() for i in range(0, 10000): query.insert(906659671 + i, 93, 0, 0, 0) keys.append(906659671 + i) insert_time_1 = process_time() print("Inserting 10k records took: \t\t\t", insert_time_1 - insert_time_0) # Measuring update Performance update_cols = [ [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), 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)))