diff --git a/aquery_parser/sql_parser.py b/aquery_parser/sql_parser.py index e24479b..fe0ebd9 100644 --- a/aquery_parser/sql_parser.py +++ b/aquery_parser/sql_parser.py @@ -16,18 +16,6 @@ from aquery_parser.types import get_column_type, time_functions from aquery_parser.utils import * from aquery_parser.windows import window - -def no_dashes(tokens, start, string): - if "-" in tokens[0]: - index = tokens[0].find("-") - raise ParseException( - tokens.type, - start + index + 1, # +1 TO ENSURE THIS MESSAGE HAS PRIORITY - string, - """Ambiguity: Use backticks (``) around identifiers with dashes, or add space around subtraction operator.""", - ) - - digit = Char("0123456789") simple_ident = ( Char(FIRST_IDENT_CHAR) diff --git a/csv.so b/csv.so new file mode 100644 index 0000000..5c230b8 Binary files /dev/null and b/csv.so differ diff --git a/engine/ast.py b/engine/ast.py index 40d6782..aa23aef 100644 --- a/engine/ast.py +++ b/engine/ast.py @@ -1,6 +1,12 @@ from typing import List -import uuid +# replace column info with this later. +class ColRef: + def __init__(self, k9name, type, cobj, cnt): + self.k9name = k9name + self.type = type + self.cobj = cobj + self.cnt = cnt class TableInfo: def __init__(self, table_name, cols, cxt:'Context'): diff --git a/engine/expr.py b/engine/expr.py index 3722a3b..adf0819 100644 --- a/engine/expr.py +++ b/engine/expr.py @@ -4,12 +4,23 @@ from engine.ast import ast_node class expr(ast_node): name='expr' builtin_func_maps = { - 'max': 'max', - 'min': 'min', + 'max': 'max', + 'min': 'min', + 'avg':'avg', + 'sum':'sum', - } - binary_ops = {'sub':'-', 'plus':'+'} - unary_ops = [] + } + binary_ops = { + 'sub':'-', + 'add':'+', + 'mul':'*', + 'div':'%', + + } + unary_ops = { + 'neg' : '-', + + } def __init__(self, parent, node): from engine.projection import projection if type(parent) in [projection, expr]: @@ -29,18 +40,19 @@ class expr(ast_node): # if type(val) in [dict, str]: self.k9expr += expr(self, val).k9expr - self.k9expr+=')' + self.k9expr += ')' elif key in self.binary_ops: l = expr(self, val[0]).k9expr r = expr(self, val[1]).k9expr self.k9expr += f'({l}{self.binary_ops[key]}{r})' - print(f'binary{key}') elif key in self.unary_ops: - print(f'unary{key}') + self.k9expr += f'({expr(self, val).k9expr}{self.unary_ops[key]})' else: - print(key) + print(f'Undefined expr: {key}{val}') elif type(node) is str: self.k9expr = self.datasource.parse_tablenames(node) + else: + self.k9expr = f'{node}' def __str__(self): return self.k9expr \ No newline at end of file diff --git a/engine/projection.py b/engine/projection.py index 3e444b7..40d02b8 100644 --- a/engine/projection.py +++ b/engine/projection.py @@ -47,7 +47,9 @@ class projection(ast_node): if self.datasource is None: raise ValueError('spawn error: from clause') - + if 'where' in node: + # apply filter + pass def consume(self, node): diff --git a/moving_avg.csv b/moving_avg.csv index e304cc2..f6b2570 100644 --- a/moving_avg.csv +++ b/moving_avg.csv @@ -1,6 +1,6 @@ -Month sales -1 100 -2 120 -4 140 -3 140 -5 130 +Month,sales +1,100 +2,120 +4,140 +3,140 +5,130 diff --git a/run.py b/run.py index afec3cc..09db800 100644 --- a/run.py +++ b/run.py @@ -1,3 +1,4 @@ +from multiprocessing.sharedctypes import Value import re import aquery_parser as parser import engine @@ -18,11 +19,18 @@ while test_parser: q = input() if q == 'exec': cxt = engine.initialize() - for s in stmts['stmts']: - engine.generate(s, cxt) + stmts_stmts = stmts['stmts'] + if type(stmts_stmts) is list: + for s in stmts_stmts: + engine.generate(s, cxt) + else: + engine.generate(stmts_stmts, cxt) print(cxt.k9code) with open('out.k', 'wb') as outfile: - outfile.write(cxt.k9code) + outfile.write(cxt.k9code.encode('utf-8')) + continue + elif q == 'print': + print(stmts) continue trimed = ws.sub(' ', q.lower()).split(' ') if trimed[0] == 'file': @@ -35,6 +43,6 @@ while test_parser: continue stmts = parser.parse(q) print(stmts) - except Exception as e: + except ValueError as e: print(type(e), e)