parent
c46ce578d4
commit
ae51d8c622
@ -1,144 +1,144 @@
|
|||||||
from concurrent.futures import thread
|
from concurrent.futures import thread
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import aquery_parser as parser
|
import aquery_parser as parser
|
||||||
import engine
|
import engine
|
||||||
import subprocess
|
import subprocess
|
||||||
import mmap
|
import mmap
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from engine.utils import base62uuid
|
from engine.utils import base62uuid
|
||||||
import atexit
|
import atexit
|
||||||
try:
|
try:
|
||||||
os.remove('server.bin')
|
os.remove('server.bin')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(type(e), e)
|
print(type(e), e)
|
||||||
|
|
||||||
subprocess.call(['make', 'server.bin'])
|
subprocess.call(['make', 'server.bin'])
|
||||||
cleanup = True
|
cleanup = True
|
||||||
def rm():
|
|
||||||
if cleanup:
|
def rm():
|
||||||
mm.seek(0,os.SEEK_SET)
|
global cleanup
|
||||||
mm.write(b'\x00\x00')
|
if cleanup:
|
||||||
mm.flush()
|
mm.seek(0,os.SEEK_SET)
|
||||||
time.sleep(.001)
|
mm.write(b'\x00\x00')
|
||||||
server.kill()
|
mm.flush()
|
||||||
files = os.listdir('.')
|
|
||||||
for f in files:
|
try:
|
||||||
if f.endswith('.shm'):
|
time.sleep(.001)
|
||||||
os.remove(f)
|
server.kill()
|
||||||
mm.close()
|
time.sleep(.001)
|
||||||
cleanup = False
|
server.terminate()
|
||||||
|
except OSError:
|
||||||
def proc_alive(pid):
|
pass
|
||||||
try:
|
|
||||||
os.kill(pid, 0)
|
files = os.listdir('.')
|
||||||
except OSError:
|
for f in files:
|
||||||
return False
|
if f.endswith('.shm'):
|
||||||
else:
|
os.remove(f)
|
||||||
return True
|
mm.close()
|
||||||
|
cleanup = False
|
||||||
atexit.register(rm)
|
|
||||||
|
atexit.register(rm)
|
||||||
shm = base62uuid()
|
|
||||||
if sys.platform != 'win32':
|
shm = base62uuid()
|
||||||
import readline
|
if sys.platform != 'win32':
|
||||||
shm += '.shm'
|
import readline
|
||||||
basecmd = ['bash', '-c', 'rlwrap k']
|
shm += '.shm'
|
||||||
mm = None
|
basecmd = ['bash', '-c', 'rlwrap k']
|
||||||
if not os.path.isfile(shm):
|
mm = None
|
||||||
# create initial file
|
if not os.path.isfile(shm):
|
||||||
with open(shm, "w+b") as handle:
|
# create initial file
|
||||||
handle.write(b'\x01\x00') # [running, new job]
|
with open(shm, "w+b") as handle:
|
||||||
handle.flush()
|
handle.write(b'\x01\x00') # [running, new job]
|
||||||
mm = mmap.mmap(handle.fileno(), 2, access=mmap.ACCESS_WRITE, offset=0)
|
handle.flush()
|
||||||
if mm is None:
|
mm = mmap.mmap(handle.fileno(), 2, access=mmap.ACCESS_WRITE, offset=0)
|
||||||
exit(1)
|
if mm is None:
|
||||||
else:
|
exit(1)
|
||||||
basecmd = ['bash.exe', '-c', 'rlwrap ./k']
|
else:
|
||||||
mm = mmap.mmap(0, 2, shm)
|
basecmd = ['bash.exe', '-c', 'rlwrap ./k']
|
||||||
mm.write(b'\x01\x00')
|
mm = mmap.mmap(0, 2, shm)
|
||||||
mm.flush()
|
mm.write(b'\x01\x00')
|
||||||
server = subprocess.Popen(["./server.bin", shm])
|
mm.flush()
|
||||||
|
server = subprocess.Popen(["./server.bin", shm])
|
||||||
test_parser = True
|
|
||||||
|
test_parser = True
|
||||||
# code to test parser
|
|
||||||
ws = re.compile(r'\s+')
|
# code to test parser
|
||||||
|
ws = re.compile(r'\s+')
|
||||||
q = 'SELECT p.Name, v.Name FROM Production.Product p JOIN Purchasing.ProductVendor pv ON p.ProductID = pv.ProductID JOIN Purchasing.Vendor v ON pv.BusinessEntityID = v.BusinessEntityID WHERE ProductSubcategoryID = 15 ORDER BY v.Name;'
|
|
||||||
|
q = 'SELECT p.Name, v.Name FROM Production.Product p JOIN Purchasing.ProductVendor pv ON p.ProductID = pv.ProductID JOIN Purchasing.Vendor v ON pv.BusinessEntityID = v.BusinessEntityID WHERE ProductSubcategoryID = 15 ORDER BY v.Name;'
|
||||||
res = parser.parse(q)
|
|
||||||
|
res = parser.parse(q)
|
||||||
print(res)
|
|
||||||
|
print(res)
|
||||||
|
|
||||||
# else:f
|
# else:f
|
||||||
# if subprocess.call(['make', 'snippet']) == 0:
|
# if subprocess.call(['make', 'snippet']) == 0:
|
||||||
# mm.seek(0)
|
# mm.seek(0)
|
||||||
# mm.write(b'\x01\x01')
|
# mm.write(b'\x01\x01')
|
||||||
# time.sleep(.1)
|
# time.sleep(.1)
|
||||||
# mm.seek(0)
|
# mm.seek(0)
|
||||||
# print(mm.read(2))
|
# print(mm.read(2))
|
||||||
|
|
||||||
# mm.close()
|
# mm.close()
|
||||||
# handle.close()
|
# handle.close()
|
||||||
# os.remove(shm)
|
# os.remove(shm)
|
||||||
# exit()
|
# exit()
|
||||||
keep = False
|
keep = False
|
||||||
cxt = None
|
cxt = None
|
||||||
while test_parser:
|
while test_parser:
|
||||||
try:
|
try:
|
||||||
if not proc_alive(server.pid):
|
if server.poll() is not None:
|
||||||
server = subprocess.Popen(["./server.bin", shm])
|
server = subprocess.Popen(["./server.bin", shm])
|
||||||
q = input()
|
q = input()
|
||||||
if q == 'exec':
|
if q == 'exec':
|
||||||
if not keep or cxt is None:
|
if not keep or cxt is None:
|
||||||
cxt = engine.initialize()
|
cxt = engine.initialize()
|
||||||
stmts_stmts = stmts['stmts']
|
stmts_stmts = stmts['stmts']
|
||||||
if type(stmts_stmts) is list:
|
if type(stmts_stmts) is list:
|
||||||
for s in stmts_stmts:
|
for s in stmts_stmts:
|
||||||
engine.generate(s, cxt)
|
engine.generate(s, cxt)
|
||||||
else:
|
else:
|
||||||
engine.generate(stmts_stmts, cxt)
|
engine.generate(stmts_stmts, cxt)
|
||||||
print(cxt.ccode)
|
print(cxt.ccode)
|
||||||
with open('out.cpp', 'wb') as outfile:
|
with open('out.cpp', 'wb') as outfile:
|
||||||
outfile.write((cxt.finalize()).encode('utf-8'))
|
outfile.write((cxt.finalize()).encode('utf-8'))
|
||||||
if subprocess.call(['make', 'snippet']) == 0:
|
if subprocess.call(['make', 'snippet']) == 0:
|
||||||
mm.seek(0,os.SEEK_SET)
|
mm.seek(0,os.SEEK_SET)
|
||||||
mm.write(b'\x01\x01')
|
mm.write(b'\x01\x01')
|
||||||
continue
|
continue
|
||||||
elif q == 'k':
|
elif q == 'k':
|
||||||
subprocess.call(basecmd)
|
subprocess.call(basecmd)
|
||||||
continue
|
continue
|
||||||
elif q == 'print':
|
elif q == 'print':
|
||||||
print(stmts)
|
print(stmts)
|
||||||
continue
|
continue
|
||||||
elif q == 'keep':
|
elif q == 'keep':
|
||||||
keep = not keep
|
keep = not keep
|
||||||
continue
|
continue
|
||||||
elif q=='format' or q == 'fmt':
|
elif q=='format' or q == 'fmt':
|
||||||
subprocess.call(['clang-format', 'out.cpp'])
|
subprocess.call(['clang-format', 'out.cpp'])
|
||||||
elif q == 'exit':
|
elif q == 'exit':
|
||||||
break
|
break
|
||||||
elif q == 'r':
|
elif q == 'r':
|
||||||
if subprocess.call(['make', 'snippet']) == 0:
|
if subprocess.call(['make', 'snippet']) == 0:
|
||||||
mm.seek(0,os.SEEK_SET)
|
mm.seek(0,os.SEEK_SET)
|
||||||
mm.write(b'\x01\x01')
|
mm.write(b'\x01\x01')
|
||||||
continue
|
continue
|
||||||
trimed = ws.sub(' ', q.lower()).split(' ')
|
trimed = ws.sub(' ', q.lower()).split(' ')
|
||||||
if trimed[0].startswith('f'):
|
if trimed[0].startswith('f'):
|
||||||
fn = 'stock.a' if len(trimed) <= 1 or len(trimed[1]) == 0 \
|
fn = 'stock.a' if len(trimed) <= 1 or len(trimed[1]) == 0 \
|
||||||
else trimed[1]
|
else trimed[1]
|
||||||
|
|
||||||
with open(fn, 'r') as file:
|
with open(fn, 'r') as file:
|
||||||
contents = file.read()
|
contents = file.read()
|
||||||
stmts = parser.parse(contents)
|
stmts = parser.parse(contents)
|
||||||
continue
|
continue
|
||||||
stmts = parser.parse(q)
|
stmts = parser.parse(q)
|
||||||
print(stmts)
|
print(stmts)
|
||||||
except (ValueError, FileNotFoundError) as e:
|
except (ValueError, FileNotFoundError) as e:
|
||||||
rm()
|
rm()
|
||||||
print(type(e), e)
|
print(type(e), e)
|
||||||
|
|
||||||
rm()
|
rm()
|
@ -1,10 +1,10 @@
|
|||||||
CREATE TABLE test(a INT, b INT, c INT, d INT)
|
CREATE TABLE test(a INT, b INT, c INT, d INT)
|
||||||
|
|
||||||
LOAD DATA INFILE "test.csv"
|
LOAD DATA INFILE "test.csv"
|
||||||
INTO TABLE test
|
INTO TABLE test
|
||||||
FIELDS TERMINATED BY ","
|
FIELDS TERMINATED BY ","
|
||||||
|
|
||||||
SELECT sum(c), b, d
|
SELECT sum(c), b, d
|
||||||
FROM test
|
FROM test
|
||||||
group by a,b,d
|
group by a,b,d
|
||||||
-- order by d DESC, b ASC
|
-- order by d DESC, b ASC
|
||||||
|
Loading…
Reference in new issue