dev
bill sun 3 years ago
parent c46ce578d4
commit ae51d8c622

@ -1,6 +1,6 @@
# AQuery Compiler
# AQuery++
AQuery Compiler that compiles AQuery into C++11.
AQuery++ Compiler that compiles AQuery into C++11.
Frontend built on top of [mo-sql-parsing](https://github.com/klahnakoski/mo-sql-parsing).
## Roadmap

@ -111,9 +111,6 @@ class TableInfo:
self.columns_byname[c['name']] = col_object
self.columns.append(col_object)
def construct(self):
for c in self.columns:
self.cxt.emit(f'{c.cname}:()')
@property
def n_cols(self):
return len(self.columns)

@ -48,6 +48,7 @@ class filter(ast_node):
def spawn(self, node):
# TODO: deal with subqueries
self.modified_node = node
return super().spawn(node)
def __materialize__(self):
if self.materialize:
@ -66,72 +67,6 @@ class filter(ast_node):
def consume(self, node):
# TODO: optimizations after converting expr to cnf
if type(node) is bool and node and self.materialize:
self.output = self.context.datasource if node else None
self.value = '1' if node else '0'
else:
if type(node) is dict:
def short_circuit(op, idx, inv = True):
v = filter(self, node[op][idx]).value
inv_filter = lambda x: not x if inv else x
if type(v) is bool and inv_filter(v):
self.value = inv_filter(v)
self.__materialize__()
return None
return v
def binary(l, r, _ty = '&'):
if type(l) is bool:
self.value = r
elif type(r) is bool:
self.value = l
elif type(l) is View:
if type(r) is View:
self.emit(f"{l.name}: {l.name} {_ty} {r.name if type(r) is View else f'({r})'}")
self.value = l
elif type(l) is str:
if type(r) is str:
self.value = f'({l}){_ty}({r})'
else:
self.emit(f'{r.name}:{r.name} {_ty} ({l})')
self.value = r
if 'and' in node:
l = short_circuit('and', 0)
if l is not None:
r = short_circuit('and', 1)
if r is not None:
binary(l, r)
elif 'or' in node:
l = short_circuit('or', 0, False)
if l is not None:
r = short_circuit('or', 1, False)
if r is not None:
binary(l, r, '|')
elif 'not' in node:
v = filter(self, node['not']).value
if type(v) is bool:
self.value = not v
self.__materialize__()
elif type(v) is View:
if len(v.table.columns) > 0:
all_rows = View(self.context, v.table)
self.emit(f'{all_rows.name}:(#{v.table.columns[0].cname})#1')
self.emit(f'{v.name}:{all_rows.name}-{v.name}')
self.value = v
else:
self.value = '~(' + v + ')'
# TODO: arithmetic ops connecting logical ops.
else:
e = expr(self, node)
if e.isvector:
v = View(self.context, self.datasource)
v.construct()
self.emit(f'{v.name}:{e.cexpr}')
self.value = v
else:
self.value = e.cexpr
self.__materialize__()
self.expr = expr(self, self.modified_node)
print(node)

@ -1,5 +1,5 @@
#include "./server/libaquery.h"
#include "./server/aggregations.h"
#include "./server/libaquery.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std;
@ -42,19 +42,19 @@ stocks_timestamp.emplace_back(15);
stocks_price.emplace_back(2);
stocks_timestamp.emplace_back(16);
stocks_price.emplace_back(5);
auto out_6gPn = new TableInfo<decays<decltype(max((stocks_price[0]-min(stocks_timestamp[0]))))>>("out_6gPn", 1);
cxt->tables.insert({"out_6gPn", out_6gPn});
auto& out_6gPn_maxstockspriceminstockstimestamp = *(ColRef<decays<decltype(max((stocks_price[0]-min(stocks_timestamp[0]))))>> *)(&out_6gPn->colrefs[0]);
out_6gPn_maxstockspriceminstockstimestamp.init();
out_6gPn_maxstockspriceminstockstimestamp = max((stocks_price-min(stocks_timestamp)));
print(*out_6gPn);
auto out_ZPYh = new TableInfo<decays<decltype(max((stocks_price[0]-min(stocks_timestamp[0]))))>>("out_ZPYh", 1);
cxt->tables.insert({"out_ZPYh", out_ZPYh});
auto& out_ZPYh_maxstockspriceminstockstimestamp = *(ColRef<decays<decltype(max((stocks_price[0]-min(stocks_timestamp[0]))))>> *)(&out_ZPYh->colrefs[0]);
out_ZPYh_maxstockspriceminstockstimestamp.init();
out_ZPYh_maxstockspriceminstockstimestamp = max((stocks_price-min(stocks_timestamp)));
print(*out_ZPYh);
auto out_7a2d = new TableInfo<decays<decltype(max((stocks_price[0]-mins(stocks_price[0]))))>>("out_7a2d", 1);
cxt->tables.insert({"out_7a2d", out_7a2d});
auto& out_7a2d_maxstockspriceminsstocksprice = *(ColRef<decays<decltype(max((stocks_price[0]-mins(stocks_price[0]))))>> *)(&out_7a2d->colrefs[0]);
out_7a2d_maxstockspriceminsstocksprice.init();
out_7a2d_maxstockspriceminsstocksprice = max((stocks_price-mins(stocks_price)));
print(*out_7a2d);
auto out_1ac3 = new TableInfo<decays<decltype(max((stocks_price[0]-mins(stocks_price[0]))))>>("out_1ac3", 1);
cxt->tables.insert({"out_1ac3", out_1ac3});
auto& out_1ac3_maxstockspriceminsstocksprice = *(ColRef<decays<decltype(max((stocks_price[0]-mins(stocks_price[0]))))>> *)(&out_1ac3->colrefs[0]);
out_1ac3_maxstockspriceminsstocksprice.init();
out_1ac3_maxstockspriceminsstocksprice = max((stocks_price-mins(stocks_price)));
print(*out_1ac3);
return 0;
}

@ -16,13 +16,22 @@ except Exception as e:
subprocess.call(['make', 'server.bin'])
cleanup = True
def rm():
global cleanup
if cleanup:
mm.seek(0,os.SEEK_SET)
mm.write(b'\x00\x00')
mm.flush()
try:
time.sleep(.001)
server.kill()
time.sleep(.001)
server.terminate()
except OSError:
pass
files = os.listdir('.')
for f in files:
if f.endswith('.shm'):
@ -30,14 +39,6 @@ def rm():
mm.close()
cleanup = False
def proc_alive(pid):
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
atexit.register(rm)
shm = base62uuid()
@ -72,7 +73,6 @@ res = parser.parse(q)
print(res)
# else:f
# if subprocess.call(['make', 'snippet']) == 0:
# mm.seek(0)
@ -89,7 +89,7 @@ keep = False
cxt = None
while test_parser:
try:
if not proc_alive(server.pid):
if server.poll() is not None:
server = subprocess.Popen(["./server.bin", shm])
q = input()
if q == 'exec':

@ -53,7 +53,7 @@ int main(int argc, char** argv) {
printf("running: %s\n", running? "true":"false");
printf("ready: %s\n", ready? "true":"false");
while (running) {
std::this_thread::sleep_for(100us);
std::this_thread::sleep_for(1ms);
if(ready){
printf("running: %s\n", running? "true":"false");
printf("ready: %s\n", ready? "true":"false");

Loading…
Cancel
Save