pack(*), truncate, bug fixes

This commit is contained in:
2022-10-15 04:12:17 +08:00
parent dc6ad1aa8f
commit a9b0c185e1
9 changed files with 96 additions and 17 deletions
+21 -4
View File
@@ -274,10 +274,17 @@ class projection(ast_node):
# Create table into context
out_typenames = [None] * len(proj_map)
def get_proj_name(proj_name):
if '*' in proj_name:
lst_names = self.datasource.get_cols(proj_name)
return ', '.join([self.pyname2cname[n.name] for n in lst_names])
else:
return self.pyname2cname[proj_name]
for key, val in proj_map.items():
if type(val[1]) is str:
x = True
y = lambda t: self.pyname2cname[t]
y = get_proj_name
count = lambda : '0'
if vid2cname:
count = lambda : f'{vid2cname[0]}.size'
@@ -286,7 +293,7 @@ class projection(ast_node):
val[1] = val[1](False)
if val[0] == LazyT:
decltypestring = val[2].eval(x,y,gettype=True)(True)
decltypestring = val[2].eval(x,y,gettype=True,c_code=True)(True)
decltypestring = f'value_type<decays<decltype({decltypestring})>>'
out_typenames[key] = decltypestring
else:
@@ -740,8 +747,18 @@ class join(ast_node):
print(f'Error: table {node} not found.')
def get_cols(self, colExpr: str) -> Optional[ColRef]:
if colExpr == '*':
return self.all_cols(ordered = True, stripped = True)
if '*' in colExpr:
if colExpr == '*':
return self.all_cols(ordered = True, stripped = True)
elif colExpr.endswith('.*'):
tbl = colExpr.split('.')
if len(tbl) > 2:
raise KeyError(f'Invalid expression: {colExpr}')
if tbl[0] in self.tables_dir:
tbl : TableInfo= self.tables_dir[tbl[0]]
return tbl.all_cols(ordered = True)
else:
raise KeyError(f'Invalid table name: {colExpr}')
for t in self.tables:
if colExpr in t.columns_byname:
col = t.columns_byname[colExpr]
+17 -2
View File
@@ -124,8 +124,22 @@ class expr(ast_node):
if key == 'count' and type(val) is dict and 'distinct' in val:
count_distinct = True
val = val['distinct']
val = enlist(val)
exp_vals = [expr(self, v, c_code = self.c_code) for v in val]
exp_vals = []
for v in val:
if (
type(v) is str and
'*' in v and
key != 'count'
):
cols = self.datasource.get_cols(v)
if cols:
for c in cols:
exp_vals.append(expr(self, c.name, c_code=self.c_code))
else:
exp_vals.append(expr(self, v, c_code=self.c_code))
self.children = exp_vals
self.opname = key
@@ -151,7 +165,8 @@ class expr(ast_node):
self.sql = op(self.c_code, *str_vals)
special_func = [*self.context.udf_map.keys(), *self.context.module_map.keys(),
"maxs", "mins", "avgs", "sums", "deltas", "last", "first", "ratios"]
"maxs", "mins", "avgs", "sums", "deltas", "last", "first",
"ratios", "pack", "truncate"]
if self.context.special_gb:
special_func = [*special_func, *self.ext_aggfuncs]