Пример #1
0
def join():
    t_rows, t_cols = load(
        "/Users/amon/Documents/GitHub/W4111-HW3/Data/People.csv")
    t = CSVDataTable.CSVDataTable(table_name="People",
                                  column_names=t_cols,
                                  primary_key_columns=['playerID'])
    t.import_data(t_rows)
    print("T = ", t)

    t2_rows, t2_cols = load(
        "/Users/amon/Documents/GitHub/W4111-HW3/Data/Batting.csv")
    t2 = CSVDataTable.CSVDataTable(
        table_name="Batting",
        column_names=t2_cols,
        primary_key_columns=['playerID', 'teamID', 'yearID', 'stint'])
    t2.import_data(t2_rows)
    print("T2 = ", t2)

    j = t2.join(t, ['playerID'],
                where_clause={
                    "People.nameLast": "Williams",
                    "People.birthCity": "San Diego"
                },
                fields=[
                    "playerID", "People.nameLast", "People.nameFirst",
                    "Batting.teamID", "Batting.yearID", "Batting.stint",
                    "Batting.H", "Batting.AB"
                ],
                optimize=True)

    print("Result = ", j)
    print("All rows = ", json.dumps(j._rows, indent=2))
def test():
    new_r, cols = load("/Users/amon/Documents/GitHub/W4111-HW3/Data/rings.csv")
    t = CSVDataTable.CSVDataTable(table_name="rings", column_names=cols,
                                  primary_key_columns=['uni'],
                                  loadit=None)
    t.import_data(new_r)

    t.save()
Пример #3
0
def test2():
    i = CSVDataTable.Index(index_name="Smart",
                           index_columns=["last_name", "first_name"],
                           kind="INDEX")
    r = {"last_name": "Jordan", "first_name": "Bob", "uni": "bj1111"}
    kv = i.compute_key(r)
    print("key_value", kv)
    i.add_to_index(row=r, rid="2")
    print("I = ", i)
Пример #4
0
def test5():
    new_r, cols = load("/Users/amon/Documents/GitHub/W4111-HW3/Data/rings.csv")
    t = CSVDataTable.CSVDataTable(table_name="rings",
                                  column_names=cols,
                                  primary_key_columns=['uni'],
                                  loadit=None)

    t.import_data(new_r)

    temp = {'uni': 'og11', 'last_name': 'Gemgee', 'first_name': 'Gaffer'}

    result = t.delete(temp, new_r)
    print("The number of deleted rows = ", result)
Пример #5
0
def delete():
    new_r, cols = load("/Users/amon/Documents/GitHub/W4111-HW3/Data/rings.csv")
    t = CSVDataTable.CSVDataTable(table_name="rings", column_names=cols,
                                  primary_key_columns=['uni'],
                                  loadit=None)

    t.import_data(new_r)
    #t.add_index('last_name','first_name', "INDEX")

    temp = {'uni':'og11','last_name':'Gemgee','first_name':'Gaffer'}

    #result = t.find_by_template(temp,fields=None, use_index=True)

    result = t.delete(temp)
    print(t)
Пример #6
0
def test3():
    new_r, cols = load("/Users/amon/Documents/GitHub/W4111-HW3/Data/rings.csv")
    t = CSVDataTable.CSVDataTable(table_name="rings",
                                  column_names=cols,
                                  primary_key_columns=['uni'],
                                  loadit=None)

    r = {
        "last_name": "Jordan",
        "first_name": "Bob",
        "uni": "bj1111",
        "email": "boo"
    }

    t.insert(r)
    t.insert(r)
    print("t = ", t)
    cols = ["last_name", "first_name"]
    t.add_index("Name", cols, "INDEX")
Пример #7
0
def test4():

    new_r, cols = load(
        "/Users/amon/Documents/GitHub/W4111-HW3/Data/People.csv")
    t = CSVDataTable.CSVDataTable(table_name="People",
                                  column_names=cols,
                                  primary_key_columns=['playerID'],
                                  loadit=None)
    t.import_data(new_r)
    temp = {'playerID': 'willite01'}

    # start = time.time()
    # for i in range(0, 1000):
    #
    #     result = t.find_by_template(temp, fields= ['nameLast','nameFirst'], use_index=False)
    #     if i == 0:
    #         print("result", result)
    #         x = json.dumps(result._rows, indent= 2)
    #         print(x)
    # end = time.time()
    # elapsed = end - start
    # print("Elapsed time = ", elapsed)

    start = time.time()
    for i in range(0, 1000):

        result = t.find_by_template(temp,
                                    fields=['nameLast', 'nameFirst'],
                                    use_index=True)
        if i == 0:
            print("result", result)
            x = json.dumps(result._rows, indent=2)
            print(x)
    end = time.time()
    elapsed = end - start
    print("Elapsed time = ", elapsed)
Пример #8
0
def t1():
    t = CSVDataTable.CSVDataTable(table_name="Test", column_names=['foo','bar'], primary_key_columns=['foo'], loadit=None)
    print("t",t)