-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_db.py
58 lines (52 loc) · 1.47 KB
/
init_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import io
import pandas as pd
import duckdb
con = duckdb.connect(database="data/exercices_sql_tables.duckdb", read_only=False)
# -------------------------------------------------------------
# EXERCISES LIST
# -------------------------------------------------------------
data = {
"theme": ["Cross Joins", "Cross Joins"],
"exercise_name": ["beverages_and_food", "sizes_and_trademarks"],
"tables": [["beverages", "food_items"], ["sizes", "trademarks"]],
"last_reviewed": ["1980-01-01", "1970-01-01"],
}
memory_state = pd.DataFrame(data)
con.execute("CREATE TABLE IF NOT EXISTS memory_state AS SELECT * FROM memory_state")
# -------------------------------------------------------------
# CROSS JOIN EXERCISES
# -------------------------------------------------------------
CSV = """
beverage,price
orange juice, 2.5
Expresso,2
Tea,3
"""
beverages = pd.read_csv(io.StringIO(CSV))
con.execute("CREATE TABLE IF NOT EXISTS beverages AS SELECT * FROM beverages")
CSV2 = """
food_item,food_price
cookie,2.5
chocolatine,2
muffin,3
"""
food_items = pd.read_csv(io.StringIO(CSV2))
con.execute("CREATE TABLE IF NOT EXISTS food_items AS SELECT * FROM food_items")
sizes = """
size
XS
M
L
XL
"""
sizes = pd.read_csv(io.StringIO(sizes))
con.execute("CREATE TABLE IF NOT EXISTS sizes AS SELECT * FROM sizes")
trademarks = """
trademark
Nike
Asphalte
Abercrombie
Lewis
"""
trademarks = pd.read_csv(io.StringIO(trademarks))
con.execute("CREATE TABLE IF NOT EXISTS trademarks AS SELECT * FROM trademarks")