|
|
@ -24,7 +24,7 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Language definition here:
|
|
|
|
# Language definition here:
|
|
|
|
# http://ltworf.github.io/relational/grammar.html
|
|
|
|
# http://ltworf.github.io/relational/grammar.html
|
|
|
|
from typing import Optional, Union, List, Any
|
|
|
|
from typing import Optional, Union, List, Any, Dict
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
|
|
|
|
from relational import rtypes
|
|
|
|
from relational import rtypes
|
|
|
@ -233,13 +233,24 @@ class Unary(Node):
|
|
|
|
if self.name == PROJECTION:
|
|
|
|
if self.name == PROJECTION:
|
|
|
|
prop = '\"%s\"' % prop.replace(' ', '').replace(',', '\",\"')
|
|
|
|
prop = '\"%s\"' % prop.replace(' ', '').replace(',', '\",\"')
|
|
|
|
elif self.name == RENAME:
|
|
|
|
elif self.name == RENAME:
|
|
|
|
prop = '{\"%s\"}' % prop.replace(
|
|
|
|
prop = repr(self.rename_dict())
|
|
|
|
',', '\",\"').replace(ARROW, '\":\"').replace(' ', '')
|
|
|
|
|
|
|
|
else: # Selection
|
|
|
|
else: # Selection
|
|
|
|
prop = repr(prop)
|
|
|
|
prop = repr(prop)
|
|
|
|
|
|
|
|
|
|
|
|
return '%s.%s(%s)' % (self.child._toPython(), op_functions[self.name], prop)
|
|
|
|
return '%s.%s(%s)' % (self.child._toPython(), op_functions[self.name], prop)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rename_dict(self) -> Dict[str, str]:
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
Returns the dictionary that the rename operation wants
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
if self.name != RENAME:
|
|
|
|
|
|
|
|
raise ValueError('This is only supported on rename nodes')
|
|
|
|
|
|
|
|
r = {}
|
|
|
|
|
|
|
|
for i in self.prop.split(','):
|
|
|
|
|
|
|
|
q = i.split(ARROW)
|
|
|
|
|
|
|
|
r[q[0].strip()] = q[1].strip()
|
|
|
|
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_tokens(expression: List[Union[list, str]]) -> Node:
|
|
|
|
def parse_tokens(expression: List[Union[list, str]]) -> Node:
|
|
|
|