-
Notifications
You must be signed in to change notification settings - Fork 0
/
FutharkContext.py
71 lines (54 loc) · 1.88 KB
/
FutharkContext.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
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Contains the Class that initializes the
futhark context
"""
"""
from blazingsql import BlazingContext
bc = BlazingContext()
bc.create_table('game_1', df)
bc.sql('SELECT * FROM game_1 WHERE val > 4')
import numpy as np
import _sql
from futhark_ffi import Futhark
test = Futhark(_sql)
res = test.test3(np.arange(10))
test.from_futhark(res)
What am i trying to figure Out. How to match the API calls of blazingcontext
fc = FutharkContext() | test = Futhark(_sql)
fc.create_table('game_1', df) | add to dictionary of tables and names
fc.sql('select * from game_1 where val > 4') | parse_query && test.sql_query() && test.from_futhark
"""
from futhark_ffi import Futhark
from parse import sql_parse
import _main # Will be modified to something like sql_.fut
import numpy as np
from table import Table
class FutharkContext:
def __init__(self):
self.FutEnv = Futhark(_main)
self.tables = {}
def create_table(self, table_name, table):
"""
Stores a table if the table
"""
table = Table(table_name, table)
# possibly need to do an exception check here or line above
self.tables[table_name] = table
def drop_table(self, table_name):
del self.tables[table_name]
def sql(self, sql_statement):
"""
Should call something here that takes two arguements
sql_parse(tables, sql_statement)
"""
val_dic = sql_parse(self.tables, sql_statement)
t1 = val_dic["table"]
sel_cols = val_dic["select"]
if "groupbys" not in val_dic:
res = self.FutEnv.query_sel(t1, np.array(sel_cols))
return self.FutEnv.from_futhark(res)
else:
t_cols = val_dic["groupbys"]
g_col = val_dic["g_col"]
res = self.FutEnv.query_groupby(t1, g_col, np.array(sel_cols), np.array(t_cols))
return self.FutEnv.from_futhark(res)