This commit is contained in:
2022-04-14 03:16:29 +08:00
parent c46ce578d4
commit ae51d8c622
7 changed files with 171 additions and 239 deletions
-3
View File
@@ -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)
+2 -67
View File
@@ -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)