示例#1
0
db = Database()

db.open('ECS165')
grades_table = db.create_table('Grades', 5, 0)

keys = []
records = {}
seed(3562901)
num_threads = 8

# Generate random records
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(*records[key])

# Create transactions and assign them to workers
transactions = []
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker())

for i in range(10000):
    key = choice(keys)
    record = records[key]
    c = record[1]
    transaction = Transaction()
    for i in range(5):
        c += 1
    #transaction_workers[i].add_transaction(select_transactions[i])
    #transaction_workers[i].add_transaction(update_transactions[i])
worker_keys = [ {} for t in transaction_workers ]

'''
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [key, randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20)]
    q = Query(grades_table)
    insert_transactions[i].add_query(q.insert, q.table, *records[key])
    worker_keys[i][key] = True
'''

q = Query(grades_table)
for i in range(0, 100):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [key, randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20)]

# test to see if the same key can be inserted twice

for i in range(0, 5):
    insert_transactions[0].add_query(q.insert, q.table, *records[keys[i]])

for i in range(6, 10):
    insert_transactions[0].add_query(q.insert, q.table, *records[keys[i]])
    
from template.db import Database
from template.query import Query

from random import choice, randint, sample, seed

db = Database()
db.open('ECS165')
# Student Id and 4 grades
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)

records = {}
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")

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])]
示例#4
0
from template.db import Database
from template.query import Query
# from lstore.config import init

from random import choice, randint, sample, seed
from colorama import Fore, Back, Style

# Student Id and 4 grades
# init()
db = Database()
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)

records = {}

seed(3562901)

for i in range(0, 10):
    key = 92106429 + randint(0, 9000)
    while key in records:
        key = 92106429 + randint(0, 9000)
    records[key] = [
        key,
        randint(0, 20),
        randint(0, 20),
        randint(0, 20),
        randint(0, 20)
    ]
    query.insert(*records[key])
    print('inserted', records[key])
示例#5
0
from random import choice, randrange
import sys
# Student Id and 4 grades
'''
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.
'''
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]
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()
示例#7
0
    transaction_workers[i].add_transaction(update_transactions[i])
worker_keys = [{} for t in transaction_workers]

for i in range(0, 1000):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [
        key,
        randint(i * 20, (i + 1) * 20),
        randint(i * 20, (i + 1) * 20),
        randint(i * 20, (i + 1) * 20),
        randint(i * 20, (i + 1) * 20)
    ]
    #records[key] = [key, randint(0, 20), randint(0, 20), randint(0, 20), randint(0, 20)]
    q = Query(grades_table)
    insert_transactions[i].add_query(q.insert, *records[key])
    worker_keys[i][key] = True

t = 0
_records = [records[key] for key in keys]
for c in range(grades_table.num_columns):
    _keys = sorted(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:
        found = True
        for record in index[key]:
            if record[0] not in worker_keys[t % num_threads]:
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])
示例#9
0
# Student Id and 4 grades
'''
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.
'''

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)
示例#10
0
db = Database()
db.open('ECS165')
grades_table = db.create_table('Grades', 5, 0)

keys = []
records = {}
num_threads = 8
seed(8739878934)

# Generate random records
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(*records[key])

# create TransactionWorkers
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker([]))

# generates 10k random transactions
# each transaction will increment the first column of a record 5 times
for i in range(10000):
    k = randint(0, 2000 - 1)
    transaction = Transaction(q)
    for j in range(5):
        key = keys[k * 5 + j]
        q = Query(grades_table)
keys = []
records = {}
seed(3562901)

insert_transactions = []
transaction_workers = []
for i in range(num_threads):
    insert_transactions.append(Transaction())
    transaction_workers.append(TransactionWorker())
    transaction_workers[i].add_transaction(insert_transactions[i])

for i in range(0, 1000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [
        key,
        randint(0, 20),
        randint(0, 20),
        randint(0, 20),
        randint(0, 20)
    ]
    q = Query(grades_table)
    t = insert_transactions[i % num_threads]
    t.add_query(q.insert, q.table, *records[key])

# Commit to disk
for i in range(num_threads):
    transaction_workers[i].run()

db.close()
from template.db import Database
from template.query import Query
import os

db2 = Database()
db2.open("ECS165")
#db2.open()
print(db2)
g_table = db2.get_table('Grades')
q = Query(g_table)
rec3 = q.select(92106429, [1, 1, 1, 1, 1])[0]
print("Rec3 = ", rec3)
db2.close()
示例#13
0
import sys
'''
print(os.getcwd())
os.chdir('~/ECS165/')
#os.chdir('~')
print(os.getcwd())

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, 0, [1,1,1,1,1])[0]
rec2 = query.select(92106430, 0, [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:")
print(rec2.key)
print(rec.key)
示例#14
0
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)))
示例#15
0
from template.db import Database
from template.query import Query
#from template.config import init

from random import choice, randint, sample, seed
#init()

db = Database()
db.open('./ECS165')

grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)

# repopulate with random data
records = {}
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]
示例#16
0
from template.db import Database
from template.query import Query
#from template.config import init

from random import choice, randint, sample, seed
#init()

db = Database()
db.open('./ECS165')

grades_table = db.get_table('Grades')
query = Query(grades_table)

# repopulate with random data
records = {}
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)
    ]

# Simulate updates
keys = sorted(list(records.keys()))
for _ in range(10):
    for key in keys:
        for j in range(1, grades_table.num_columns):
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.
'''
db = Database()
db.open("ECS165")
print(db)
g_table = db.get_table('Grades')
q = Query(g_table)

print("Merge Start")
q.table.merge(0)
print("Merge End")

db.close()