dev
bill sun 3 years ago
parent a81fd176e9
commit 70d7167c1e

@ -20,6 +20,10 @@ Frontend built on top of [mo-sql-parsing](https://github.com/klahnakoski/mo-sql-
- [ ] Subqueries - [ ] Subqueries
- [ ] -> Optimizing Compiler - [ ] -> Optimizing Compiler
## TODO:
- [ ] C++ Meta-Programming: Elimilate template recursions as much as possible.
- [ ] IPC: Better ways to communicate between Interpreter (Python) and Executer (C++).
- [ ] Sockets? stdin/stdout capture?
## Introduction ## Introduction
## Requirements ## Requirements

@ -143,8 +143,8 @@ class TableInfo:
def get_col_d(self, col_name): def get_col_d(self, col_name):
col = self.columns_byname[col_name] col = self.columns_byname[col_name]
if type(self.rec) is list: if type(self.rec) is set:
self.rec.append(col) self.rec.add(col)
return col return col
def get_ccolname_d(self, col_name): def get_ccolname_d(self, col_name):
@ -167,12 +167,12 @@ class TableInfo:
self.alias.add(alias) self.alias.add(alias)
def parse_tablenames(self, colExpr, materialize = True, raw = False): def parse_tablenames(self, colExpr, materialize = True, raw = False):
self.get_col = self.get_col if materialize else self.get_col_d # get_col = self.get_col if materialize else self.get_col_d
parsedColExpr = colExpr.split('.') parsedColExpr = colExpr.split('.')
ret = None ret = None
if len(parsedColExpr) <= 1: if len(parsedColExpr) <= 1:
ret = self.get_col(colExpr) ret = self.get_col_d(colExpr)
else: else:
datasource = self.cxt.tables_byname[parsedColExpr[0]] datasource = self.cxt.tables_byname[parsedColExpr[0]]
if datasource is None: if datasource is None:
@ -184,6 +184,7 @@ class TableInfo:
if self.groupinfo is not None and ret and ret in self.groupinfo.raw_groups: if self.groupinfo is not None and ret and ret in self.groupinfo.raw_groups:
string = f'get<{self.groupinfo.raw_groups.index(ret)}>({{y}})' string = f'get<{self.groupinfo.raw_groups.index(ret)}>({{y}})'
return string, ret if raw else string return string, ret if raw else string
class View: class View:
def __init__(self, context, table = None, tmp = True): def __init__(self, context, table = None, tmp = True):
self.table: TableInfo = table self.table: TableInfo = table
@ -200,6 +201,7 @@ class Context:
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std; using namespace std;
using namespace types; using namespace types;
''' '''
def __init__(self): def __init__(self):
self.tables:List[TableInfo] = [] self.tables:List[TableInfo] = []

@ -89,43 +89,19 @@ class outfile(ast_node):
out_table:TableInfo = self.parent.out_table out_table:TableInfo = self.parent.out_table
filename = node['loc']['literal'] if 'loc' in node else node['literal'] filename = node['loc']['literal'] if 'loc' in node else node['literal']
sep = ',' if 'term' not in node else node['term']['literal'] sep = ',' if 'term' not in node else node['term']['literal']
self.context.headers.add('fstream') file_pointer = 'fp_' + base62uuid(6)
cout_backup_buffer = 'stdout_' + base62uuid(4) self.emit(f'FILE* {file_pointer} = fopen("{filename}", "w");')
ofstream = 'ofstream_' + base62uuid(6) self.emit(f'{out_table.cxt_name}->printall("{sep}", "\\n", nullptr, {file_pointer});')
self.emit(f'fclose({file_pointer});')
self.emit(f'auto {cout_backup_buffer} = cout.rdbuf();') # self.context.headers.add('fstream')
self.emit(f'auto {ofstream} = ofstream("{filename}");') # cout_backup_buffer = 'stdout_' + base62uuid(4)
self.emit(f'cout.rdbuf({ofstream}.rdbuf());') # ofstream = 'ofstream_' + base62uuid(6)
# self.emit(f'auto {cout_backup_buffer} = cout.rdbuf();')
self.emit_no_ln(f"\"{filename}\"1:`csv@(+(") # self.emit(f'auto {ofstream} = ofstream("{filename}");')
l_compound = False # self.emit(f'cout.rdbuf({ofstream}.rdbuf());')
l_cols = '' # TODO: ADD STMTS.
l_keys = '' # self.emit(f'cout.rdbuf({cout_backup_buffer});')
ending = lambda x: x[:-1] if len(x) > 0 and x[-1]==';' else x # self.emit(f'{ofstream}.close();')
for i, c in enumerate(out_table.columns):
c:ColRef
l_keys += '`' + c.name
if c.compound:
if l_compound:
l_cols=f'flatBOTH\'+(({ending(l_cols)});{c.cname})'
else:
l_compound = True
if i >= 1:
l_cols = f'flatRO\'+(({ending(l_cols)});{c.cname})'
else:
l_cols = c.cname + ';'
elif l_compound:
l_cols = f'flatLO\'+(({ending(l_cols)});{c.cname})'
else:
l_cols += f"{c.cname};"
if not l_compound:
self.emit_no_ln(l_keys + '!(' + ending(l_cols) + ')')
else:
self.emit_no_ln(f'{l_keys}!+,/({ending(l_cols)})')
self.emit('))')
self.emit(f'cout.rdbuf({cout_backup_buffer});')
self.emit(f'{ofstream}.close();')
import sys import sys

@ -11,10 +11,10 @@ class expr(ast_node):
'avg': 'avg', 'avg': 'avg',
'sum': 'sum', 'sum': 'sum',
'count' : 'count', 'count' : 'count',
'mins': ['mins', 'minsw'], 'mins': ['mins', 'minw'],
'maxs': ['maxs', 'maxsw'], 'maxs': ['maxs', 'maxw'],
'avgs': ['avgs', 'avgsw'], 'avgs': ['avgs', 'avgw'],
'sums': ['sums', 'sumsw'], 'sums': ['sums', 'sumw'],
} }
binary_ops = { binary_ops = {
@ -47,6 +47,9 @@ class expr(ast_node):
self.materialize_cols = materialize_cols self.materialize_cols = materialize_cols
self.raw_col = None self.raw_col = None
self.__abs = abs_col self.__abs = abs_col
self.inside_agg = False
if(type(parent) is expr):
self.inside_agg = parent.inside_agg
ast_node.__init__(self, parent, node, None) ast_node.__init__(self, parent, node, None)
def init(self, _): def init(self, _):
@ -67,7 +70,8 @@ class expr(ast_node):
if type(node) is dict: if type(node) is dict:
for key, val in node.items(): for key, val in node.items():
if key in self.func_maps: if key in self.func_maps:
# if type(val) in [dict, str]: # TODO: distinguish between UDF agg functions and other UDF functions.
self.inside_agg = True
self.context.headers.add('"./server/aggregations.h"') self.context.headers.add('"./server/aggregations.h"')
if type(val) is list and len(val) > 1: if type(val) is list and len(val) > 1:
cfunc = self.func_maps[key] cfunc = self.func_maps[key]
@ -81,6 +85,7 @@ class expr(ast_node):
self._expr += f"{funcname}(" self._expr += f"{funcname}("
self._expr += expr(self, val)._expr self._expr += expr(self, val)._expr
self._expr += ')' self._expr += ')'
self.inside_agg = False
elif key in self.binary_ops: elif key in self.binary_ops:
l = expr(self, val[0])._expr l = expr(self, val[0])._expr
r = expr(self, val[1])._expr r = expr(self, val[1])._expr
@ -112,7 +117,7 @@ class expr(ast_node):
self._expr, self.raw_col = self.datasource.parse_tablenames(node, self.materialize_cols, True) self._expr, self.raw_col = self.datasource.parse_tablenames(node, self.materialize_cols, True)
self.raw_col = self.raw_col if type(self.raw_col) is ColRef else None self.raw_col = self.raw_col if type(self.raw_col) is ColRef else None
if self.__abs and self.raw_col: if self.__abs and self.raw_col:
self._expr = self.raw_col.reference() + index_expr self._expr = self.raw_col.reference() + ("" if self.inside_agg else index_expr)
elif type(node) is bool: elif type(node) is bool:
self._expr = '1' if node else '0' self._expr = '1' if node else '0'
else: else:

@ -12,7 +12,7 @@ class groupby(ast_node):
self.group_type = 'record_type' + base62uuid(7) self.group_type = 'record_type' + base62uuid(7)
self.datasource = self.parent.datasource self.datasource = self.parent.datasource
self.scanner = None self.scanner = None
self.datasource.rec = [] self.datasource.rec = set()
self.raw_groups = [] self.raw_groups = []
def produce(self, node): def produce(self, node):

@ -4,7 +4,7 @@ from engine.join import join
from engine.expr import expr from engine.expr import expr
from engine.orderby import orderby from engine.orderby import orderby
from engine.scan import filter from engine.scan import filter
from engine.utils import base62uuid, enlist, base62alp from engine.utils import base62uuid, enlist, base62alp, has_other
from engine.ddl import create_table, outfile from engine.ddl import create_table, outfile
import copy import copy
@ -88,26 +88,39 @@ class projection(ast_node):
for i, proj in enumerate(self.projections): for i, proj in enumerate(self.projections):
cname = '' cname = ''
compound = False compound = False
self.datasource.rec = [] self.datasource.rec = set()
if type(proj) is dict: if type(proj) is dict:
if 'value' in proj: if 'value' in proj:
e = proj['value'] e = proj['value']
sname = expr(self, e)._expr sname = expr(self, e)._expr
fname = expr.toCExpr(sname) # fastest access method at innermost context fname = expr.toCExpr(sname) # fastest access method at innermost context
absname = expr(self, e, abs_col=True)._expr # absolute name at function scope absname = expr(self, e, abs_col=True)._expr # absolute name at function scope
compound = True compound = True # compound column
cexprs.append(fname) cexprs.append(fname)
cname = e if type(e) is str else ''.join([a if a in base62alp else '' for a in expr.toCExpr(absname)()]) cname = e if type(e) is str else ''.join([a if a in base62alp else '' for a in expr.toCExpr(absname)()])
if 'name' in proj: # renaming column by AS keyword if 'name' in proj: # renaming column by AS keyword
cname = proj['name'] cname = proj['name']
new_names.append(cname) new_names.append(cname)
compound = compound and has_groupby and self.datasource.rec not in self.group_node.referenced elif type(proj) is str:
col = self.datasource.get_col_d(proj)
if type(col) is ColRef:
col.reference()
compound = compound and has_groupby and has_other(self.datasource.rec, self.group_node.referenced)
self.datasource.rec = None
typename = ''
if not compound:
typename = f'value_type<decays<decltype({absname})>>'
else :
typename = f'decays<decltype({absname})>'
cols.append(ColRef(cname, expr.toCExpr(typename)(), self.out_table, 0, None, cname, i, compound=compound))
cols.append(ColRef(cname, expr.toCExpr(f'decays<decltype({absname})>')(0), self.out_table, 0, None, cname, i, compound=compound))
self.out_table.add_cols(cols, False) self.out_table.add_cols(cols, False)
if has_groupby: if has_groupby:
create_table(self, self.out_table) create_table(self, self.out_table) # only initializes out_table.
self.group_node.finalize(cexprs, self.out_table) self.group_node.finalize(cexprs, self.out_table)
else: else:
create_table(self, self.out_table, cexpr = cexprs) create_table(self, self.out_table, cexpr = cexprs)
@ -129,8 +142,6 @@ class projection(ast_node):
if flatten: if flatten:
if len(self.projections) > 1 and not self.inv:
self.emit(f"{disp_varname}:+{disp_varname}")
outfile(self, node['outfile']) outfile(self, node['outfile'])
if self.datasource_changed: if self.datasource_changed:

@ -16,4 +16,10 @@ def enlist(l):
return l if type(l) is list else [l] return l if type(l) is list else [l]
def seps(s, i, l): def seps(s, i, l):
return s if i < len(l) - 1 else '' return s if i < len(l) - 1 else ''
def has_other(a, b):
for ai in a:
if ai not in b:
return True
return False

@ -6,7 +6,7 @@ FIELDS TERMINATED BY "\t"
SELECT Month,avgs(3,sales) SELECT Month,avgs(3,sales)
FROM sale FROM sale
ASSUMING ASC Month -- ASSUMING ASC Month
INTO OUTFILE "moving_avg_output.csv" INTO OUTFILE "moving_avg_output.csv"
FIELDS TERMINATED BY "," FIELDS TERMINATED BY ","

@ -93,6 +93,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -108,6 +109,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -123,6 +125,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -138,6 +141,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

@ -0,0 +1,145 @@
from engine.ast import ColRef, TableInfo, ast_node, Context, include
from engine.groupby import groupby
from engine.join import join
from engine.expr import expr
from engine.orderby import orderby
from engine.scan import filter
from engine.utils import base62uuid, enlist, base62alp
from engine.ddl import create_table, outfile
import copy
class projection(ast_node):
name='select'
def __init__(self, parent:ast_node, node, context:Context = None, outname = None, disp = True):
self.disp = disp
self.outname = outname
self.group_node = None
self.assumption = None
self.where = None
ast_node.__init__(self, parent, node, context)
def init(self, _):
if self.outname is None:
self.outname = self.context.gen_tmptable()
def produce(self, node):
p = node['select']
self.projections = p if type(p) is list else [p]
print(node)
def spawn(self, node):
self.datasource = None
if 'from' in node:
from_clause = node['from']
if type(from_clause) is list:
# from joins
join(self, from_clause)
elif type(from_clause) is dict:
if 'value' in from_clause:
value = from_clause['value']
if type(value) is dict:
if 'select' in value:
# from subquery
projection(self, from_clause, disp = False)
else:
# TODO: from func over table
print(f'from func over table{node}')
elif type(value) is str:
self.datasource = self.context.tables_byname[value]
if 'assumptions' in from_clause:
self.assumption = orderby(self, enlist(from_clause['assumptions']))
elif type(from_clause) is str:
self.datasource = self.context.tables_byname[from_clause]
if self.datasource is None:
raise ValueError('spawn error: from clause')
if self.datasource is not None:
self.datasource_changed = True
self.prev_datasource = self.context.datasource
self.context.datasource = self.datasource
if 'where' in node:
self.where = filter(self, node['where'], True)
# self.datasource = filter(self, node['where'], True).output
#self.context.datasource = self.datasource
if 'groupby' in node:
self.group_node = groupby(self, node['groupby'])
self.datasource = copy.copy(self.datasource) # shallow copy
self.datasource.groupinfo = self.group_node
else:
self.group_node = None
def consume(self, node):
self.inv = True
disp_varname = 'd'+base62uuid(7)
has_groupby = False
if self.group_node is not None:
# There is group by;
has_groupby = True
cexprs = []
flatten = False
cols = []
self.out_table = TableInfo('out_'+base62uuid(4), [], self.context)
if 'outfile' in node:
flatten = True
new_names = []
for i, proj in enumerate(self.projections):
cname = ''
compound = False
self.datasource.rec = set()
if type(proj) is dict:
if 'value' in proj:
e = proj['value']
sname = expr(self, e)._expr
fname = expr.toCExpr(sname) # fastest access method at innermost context
absname = expr(self, e, abs_col=True)._expr # absolute name at function scope
compound = True
cexprs.append(fname)
cname = e if type(e) is str else ''.join([a if a in base62alp else '' for a in expr.toCExpr(absname)()])
if 'name' in proj: # renaming column by AS keyword
cname = proj['name']
new_names.append(cname)
elif type(proj) is str:
col = self.datasource.get_col_d(proj)
if type(col) is ColRef:
col.reference()
compound = compound and has_groupby and self.datasource.rec not in self.group_node.referenced
self.datasource.rec = None
cols.append(ColRef(cname, expr.toCExpr(f'decays<decltype({absname})>')(0), self.out_table, 0, None, cname, i, compound=compound))
self.out_table.add_cols(cols, False)
if has_groupby:
create_table(self, self.out_table)
self.group_node.finalize(cexprs, self.out_table)
else:
create_table(self, self.out_table, cexpr = cexprs)
self.datasource.group_node = None
if self.where is not None:
self.where.finalize()
has_orderby = 'orderby' in node
if has_orderby:
self.datasource = self.out_table
self.context.datasource = self.out_table # discard current ds
orderby_node = orderby(self, node['orderby'])
self.emit(f'auto {disp_varname} ={self.out_table.reference()}->order_by_view<{",".join([f"{c}" for c in orderby_node.col_list])}>();')
else:
disp_varname = f'*{self.out_table.cxt_name}'
if self.disp:
self.emit(f'print({disp_varname});')
if flatten:
if len(self.projections) > 1 and not self.inv:
self.emit(f"{disp_varname}:+{disp_varname}")
outfile(self, node['outfile'])
if self.datasource_changed:
self.context.datasource = self.prev_datasource
import sys
include(sys.modules[__name__])

@ -0,0 +1,90 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>ccc243f5-663e-45b7-a6de-b2468c58b3a7</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>
</StartupFile>
<SearchPath>..\msvs-py</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>msvs-py</Name>
<RootNamespace>msvs-py</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Folder Include="aquery_parser\" />
<Folder Include="aquery_parser\__pycache__\" />
<Folder Include="engine\" />
<Folder Include="engine\__pycache__\" />
</ItemGroup>
<ItemGroup>
<Compile Include="aquery_parser\keywords.py" />
<Compile Include="aquery_parser\sql_parser.py" />
<Compile Include="aquery_parser\types.py" />
<Compile Include="aquery_parser\utils.py" />
<Compile Include="aquery_parser\windows.py" />
<Compile Include="aquery_parser\__init__.py" />
<Compile Include="engine\ast.py" />
<Compile Include="engine\ddl.py" />
<Compile Include="engine\expr.py" />
<Compile Include="engine\groupby.py" />
<Compile Include="engine\join.py" />
<Compile Include="engine\orderby.py" />
<Compile Include="engine\projection.py" />
<Compile Include="engine\scan.py" />
<Compile Include="engine\types.py" />
<Compile Include="engine\utils.py" />
<Compile Include="engine\__init__.py" />
<Compile Include="prompt.py" />
</ItemGroup>
<ItemGroup>
<Content Include="aquery_parser\__pycache__\keywords.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\keywords.cpython-39.pyc" />
<Content Include="aquery_parser\__pycache__\sql_parser.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\sql_parser.cpython-39.pyc" />
<Content Include="aquery_parser\__pycache__\types.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\types.cpython-39.pyc" />
<Content Include="aquery_parser\__pycache__\utils.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\utils.cpython-39.pyc" />
<Content Include="aquery_parser\__pycache__\windows.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\windows.cpython-39.pyc" />
<Content Include="aquery_parser\__pycache__\__init__.cpython-310.pyc" />
<Content Include="aquery_parser\__pycache__\__init__.cpython-39.pyc" />
<Content Include="engine\__pycache__\ast.cpython-310.pyc" />
<Content Include="engine\__pycache__\ast.cpython-39.pyc" />
<Content Include="engine\__pycache__\ddl.cpython-310.pyc" />
<Content Include="engine\__pycache__\ddl.cpython-39.pyc" />
<Content Include="engine\__pycache__\expr.cpython-310.pyc" />
<Content Include="engine\__pycache__\expr.cpython-39.pyc" />
<Content Include="engine\__pycache__\groupby.cpython-310.pyc" />
<Content Include="engine\__pycache__\join.cpython-310.pyc" />
<Content Include="engine\__pycache__\join.cpython-39.pyc" />
<Content Include="engine\__pycache__\orderby.cpython-310.pyc" />
<Content Include="engine\__pycache__\projection.cpython-310.pyc" />
<Content Include="engine\__pycache__\projection.cpython-39.pyc" />
<Content Include="engine\__pycache__\scan.cpython-310.pyc" />
<Content Include="engine\__pycache__\types.cpython-310.pyc" />
<Content Include="engine\__pycache__\utils.cpython-310.pyc" />
<Content Include="engine\__pycache__\utils.cpython-39.pyc" />
<Content Include="engine\__pycache__\__init__.cpython-310.pyc" />
<Content Include="engine\__pycache__\__init__.cpython-39.pyc" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>

@ -1,12 +1,13 @@
#include "csv.h"
#include "./server/hasher.h"
#include <unordered_map> #include <unordered_map>
#include "./server/aggregations.h"
#include "./server/libaquery.h" #include "./server/libaquery.h"
#include "./server/hasher.h"
#include "./server/aggregations.h"
#include "csv.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std; using namespace std;
using namespace types; using namespace types;
auto test = new TableInfo<int,int,int,int>("test", 4); auto test = new TableInfo<int,int,int,int>("test", 4);
cxt->tables.insert({"test", test}); cxt->tables.insert({"test", test});
auto& test_a = *(ColRef<int> *)(&test->colrefs[0]); auto& test_a = *(ColRef<int> *)(&test->colrefs[0]);
@ -17,45 +18,40 @@ test_a.init();
test_b.init(); test_b.init();
test_c.init(); test_c.init();
test_d.init(); test_d.init();
io::CSVReader<4> csv_reader_53LkPG("test.csv"); io::CSVReader<4> csv_reader_4bTMJ9("test.csv");
csv_reader_53LkPG.read_header(io::ignore_extra_column, "a","b","c","d"); csv_reader_4bTMJ9.read_header(io::ignore_extra_column, "a","b","c","d");
int tmp_43xeYChp; int tmp_78E1nhZJ;
int tmp_3Vnt4fLK; int tmp_4wnHGd9t;
int tmp_1HKZwQBO; int tmp_5OL9GlRp;
int tmp_6IwJuIpg; int tmp_155GVQC6;
while(csv_reader_53LkPG.read_row(tmp_43xeYChp,tmp_3Vnt4fLK,tmp_1HKZwQBO,tmp_6IwJuIpg)) { while(csv_reader_4bTMJ9.read_row(tmp_78E1nhZJ,tmp_4wnHGd9t,tmp_5OL9GlRp,tmp_155GVQC6)) {
test_a.emplace_back(tmp_43xeYChp); test_a.emplace_back(tmp_78E1nhZJ);
test_b.emplace_back(tmp_3Vnt4fLK); test_b.emplace_back(tmp_4wnHGd9t);
test_c.emplace_back(tmp_1HKZwQBO); test_c.emplace_back(tmp_5OL9GlRp);
test_d.emplace_back(tmp_6IwJuIpg); test_d.emplace_back(tmp_155GVQC6);
} }
typedef record<decltype(test_a[0]),decltype(test_b[0]),decltype(test_d[0])> record_type1CmZCvh; typedef record<decltype(test_a[0]),decltype(test_b[0]),decltype(test_d[0])> record_type6jn8Y49;
unordered_map<record_type1CmZCvh, vector_type<uint32_t>, transTypes<record_type1CmZCvh, hasher>> g6nov6MR; unordered_map<record_type6jn8Y49, vector_type<uint32_t>, transTypes<record_type6jn8Y49, hasher>> g5gn6KEb;
for (uint32_t i4I = 0; i4I < test_a.size; ++i4I){ for (uint32_t i3V = 0; i3V < test_a.size; ++i3V){
g6nov6MR[forward_as_tuple(test_a[i4I],test_b[i4I],test_d[i4I])].emplace_back(i4I); g5gn6KEb[forward_as_tuple(test_a[i3V],test_b[i3V],test_d[i3V])].emplace_back(i3V);
} }
auto out_684r = new TableInfo<decays<decltype(sum(test_c[0]))>,decays<decltype(test_b[0])>,decays<decltype(test_d[0])>>("out_684r", 3); auto out_4DCN = new TableInfo<decays<decltype(sum(test_c))>,value_type<decays<decltype(test_b)>>,value_type<decays<decltype(test_d)>>>("out_4DCN", 3);
cxt->tables.insert({"out_684r", out_684r}); cxt->tables.insert({"out_4DCN", out_4DCN});
auto& out_684r_sumtestc = *(ColRef<decays<decltype(sum(test_c[0]))>> *)(&out_684r->colrefs[0]); auto& out_4DCN_sumtestc = *(ColRef<decays<decltype(sum(test_c))>> *)(&out_4DCN->colrefs[0]);
auto& out_684r_b = *(ColRef<decays<decltype(test_b[0])>> *)(&out_684r->colrefs[1]); auto& out_4DCN_b = *(ColRef<value_type<decays<decltype(test_b)>>> *)(&out_4DCN->colrefs[1]);
auto& out_684r_d = *(ColRef<decays<decltype(test_d[0])>> *)(&out_684r->colrefs[2]); auto& out_4DCN_d = *(ColRef<value_type<decays<decltype(test_d)>>> *)(&out_4DCN->colrefs[2]);
out_684r_sumtestc.init(); out_4DCN_sumtestc.init();
out_684r_b.init(); out_4DCN_b.init();
out_684r_d.init(); out_4DCN_d.init();
for(auto& i3d : g6nov6MR) { for(auto& i1s : g5gn6KEb) {
auto &key_1TaM8D7 = i3d.first; auto &key_4Q0aEyH = i1s.first;
auto &val_129np3x = i3d.second; auto &val_7BUMR6d = i1s.second;
out_684r_sumtestc.emplace_back(sum(test_c[val_129np3x])); out_4DCN_sumtestc.emplace_back(sum(test_c[val_7BUMR6d]));
out_684r_b.emplace_back(get<1>(key_1TaM8D7)); out_4DCN_b.emplace_back(get<1>(key_4Q0aEyH));
out_684r_d.emplace_back(get<2>(key_1TaM8D7)); out_4DCN_d.emplace_back(get<2>(key_4Q0aEyH));
} }
auto d2X3bP6l =out_684r->order_by_view<-3,1>(); auto d6X0PMzl =out_4DCN->order_by_view<-3,1>();
puts("a"); print(d6X0PMzl);
print(*(out_684r->order_by<-3,1>()));
puts("b");
print(out_684r->order_by_view<-3,1>());
puts("e");
print(*out_684r);
return 0; return 0;
} }

@ -0,0 +1,60 @@
#include "./server/libaquery.h"
#include <unordered_map>
#include "./server/hasher.h"
#include "csv.h"
#include "./server/aggregations.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std;
using namespace types;
auto sale = new TableInfo<int,int>("sale", 2);
cxt->tables.insert({"sale", sale});
auto& sale_Month = *(ColRef<int> *)(&sale->colrefs[0]);
auto& sale_sales = *(ColRef<int> *)(&sale->colrefs[1]);
sale_Month.init();
sale_sales.init();
io::CSVReader<2> csv_reader_53ychC("moving_avg.csv");
csv_reader_53ychC.read_header(io::ignore_extra_column, "Month","sales");
int tmp_7ttMnHd3;
int tmp_5nHjeAtP;
while(csv_reader_53ychC.read_row(tmp_7ttMnHd3,tmp_5nHjeAtP)) {
sale_Month.emplace_back(tmp_7ttMnHd3);
sale_sales.emplace_back(tmp_5nHjeAtP);
}
auto out_3Xio = new TableInfo<decays<decltype(sale_Month[0])>,decays<decltype(avgw(3,sale_sales))>>("out_3Xio", 2);
cxt->tables.insert({"out_3Xio", out_3Xio});
auto& out_3Xio_Month = *(ColRef<decays<decltype(sale_Month[0])>> *)(&out_3Xio->colrefs[0]);
auto& out_3Xio_avgsw3salesales = *(ColRef<decays<decltype(avgw(3,sale_sales))>> *)(&out_3Xio->colrefs[1]);
out_3Xio_Month.init();
out_3Xio_Month = sale_Month;
out_3Xio_avgsw3salesales.init();
out_3Xio_avgsw3salesales = avgw(3,sale_sales);
// print(*out_3Xio);
FILE* fp_4nKGhD = fopen("moving_avg_output.csv", "w");
out_3Xio->printall(",", "\n", nullptr, fp_4nKGhD);
fclose(fp_4nKGhD);
typedef record<decltype(sale_sales[0])> record_type1H2vDGL;
unordered_map<record_type1H2vDGL, vector_type<uint32_t>, transTypes<record_type1H2vDGL, hasher>> g6Mjxfk5;
for (uint32_t i7u = 0; i7u < sale_sales.size; ++i7u){
g6Mjxfk5[forward_as_tuple(sale_sales[i7u])].emplace_back(i7u);
}
auto out_2IU2 = new TableInfo<decays<decltype(sale_sales[0])>,decays<decltype(minw(2,sale_Month))>>("out_2IU2", 2);
cxt->tables.insert({"out_2IU2", out_2IU2});
auto& out_2IU2_sales = *(ColRef<decays<decltype(sale_sales[0])>> *)(&out_2IU2->colrefs[0]);
auto& out_2IU2_minsw2saleMonth = *(ColRef<decays<decltype(minw(2,sale_Month))>> *)(&out_2IU2->colrefs[1]);
out_2IU2_sales.init();
out_2IU2_minsw2saleMonth.init();
for(auto& i5J : g6Mjxfk5) {
auto &key_4jl5toH = i5J.first;
auto &val_VJGwVwH = i5J.second;
out_2IU2_sales.emplace_back(get<0>(key_4jl5toH));
out_2IU2_minsw2saleMonth.emplace_back(minw(2,sale_Month[val_VJGwVwH]));
}
// print(*out_2IU2);
FILE* fp_18R4fY = fopen("flatten.csv", "w");
out_2IU2->printall(",","\n", nullptr, fp_18R4fY);
fclose(fp_18R4fY);
return 0;
}

@ -39,10 +39,10 @@ T min(const VT<T>& v) {
return min_v; return min_v;
} }
template<class T, template<typename ...> class VT> template<class T, template<typename ...> class VT>
VT<T> mins(const VT<T>& arr) { decayed_t<VT,T> mins(const VT<T>& arr) {
const int& len = arr.size; const uint32_t& len = arr.size;
std::deque<std::pair<T, uint32_t>> cache; std::deque<std::pair<T, uint32_t>> cache;
VT<T> ret(len); decayed_t<VT,T> ret(len);
T min = std::numeric_limits<T>::max(); T min = std::numeric_limits<T>::max();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
if (arr[i] < min) if (arr[i] < min)
@ -52,9 +52,9 @@ VT<T> mins(const VT<T>& arr) {
return ret; return ret;
} }
template<class T, template<typename ...> class VT> template<class T, template<typename ...> class VT>
VT<T> maxs(const VT<T>& arr) { decayed_t<VT,T> maxs(const VT<T>& arr) {
const int& len = arr.size; const uint32_t& len = arr.size;
VT<T> ret(len); decayed_t<VT,T> ret(len);
T max = std::numeric_limits<T>::min(); T max = std::numeric_limits<T>::min();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
if (arr[i] > max) if (arr[i] > max)
@ -65,9 +65,9 @@ VT<T> maxs(const VT<T>& arr) {
} }
template<class T, template<typename ...> class VT> template<class T, template<typename ...> class VT>
VT<T> minw(const VT<T>& arr, uint32_t w) { decayed_t<VT,T> minw(uint32_t w, const VT<T>& arr) {
const int& len = arr.size; const uint32_t& len = arr.size;
VT<T> ret(len); decayed_t<VT,T> ret{len};
std::deque<std::pair<T, uint32_t>> cache; std::deque<std::pair<T, uint32_t>> cache;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
if (!cache.empty() && cache.front().second == i - w) cache.pop_front(); if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
@ -79,9 +79,9 @@ VT<T> minw(const VT<T>& arr, uint32_t w) {
} }
template<class T, template<typename ...> class VT> template<class T, template<typename ...> class VT>
VT<T> maxw(const VT<T>& arr, uint32_t w) { decayed_t<VT,T> maxw(uint32_t w, const VT<T>& arr) {
const int& len = arr.size; const uint32_t& len = arr.size;
VT<T> ret(len); decayed_t<VT, T> ret(len);
std::deque<std::pair<T, uint32_t>> cache; std::deque<std::pair<T, uint32_t>> cache;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
if (!cache.empty() && cache.front().second == i - w) cache.pop_front(); if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
@ -91,15 +91,44 @@ VT<T> maxw(const VT<T>& arr, uint32_t w) {
} }
return ret; return ret;
} }
template<class T, template<typename ...> class VT>
decayed_t<VT, types::GetLongType<T>> sumw(uint32_t w, const VT<T>& arr) {
const uint32_t& len = arr.size;
decayed_t<VT, types::GetLongType<T>> ret(len);
uint32_t i = 0;
w = w > len ? len : w;
if(arr.size)
ret[i++] = arr[0];
for (; i < w; ++i)
ret[i] = ret[i-1] + arr[i];
for (; i < len; ++i)
ret[i] = ret[i-1] + arr[i] - arr[i-w];
return ret;
}
template<class T, template<typename ...> class VT>
decayed_t<VT, types::GetFPType<T>> avgw(uint32_t w, const VT<T>& arr) {
typedef types::GetFPType<T> FPType;
const uint32_t& len = arr.size;
decayed_t<VT, FPType> ret(len);
uint32_t i = 0;
types::GetLongType<T> s;
w = w > len ? len : w;
if(arr.size)
s = ret[i++] = arr[0];
for (; i < w; ++i)
ret[i] = (s += arr[i])/(FPType)(i+1);
for (; i < len; ++i)
ret[i] = ret[i-1] + (arr[i] - arr[i-w])/(FPType)w;
return ret;
}
template <class T> constexpr inline T max(const T& v) { return v; } template <class T> constexpr inline T max(const T& v) { return v; }
template <class T> constexpr inline T min(const T& v) { return v; } template <class T> constexpr inline T min(const T& v) { return v; }
template <class T> constexpr inline T avg(const T& v) { return v; } template <class T> constexpr inline T avg(const T& v) { return v; }
template <class T> constexpr inline T sum(const T& v) { return v; } template <class T> constexpr inline T sum(const T& v) { return v; }
template <class T> constexpr inline T maxw(const T& v, uint32_t) { return v; } template <class T> constexpr inline T maxw(uint32_t, const T& v) { return v; }
template <class T> constexpr inline T minw(const T& v, uint32_t) { return v; } template <class T> constexpr inline T minw(uint32_t, const T& v) { return v; }
template <class T> constexpr inline T avgw(const T& v, uint32_t) { return v; } template <class T> constexpr inline T avgw(uint32_t, const T& v) { return v; }
template <class T> constexpr inline T sumw(const T& v, uint32_t) { return v; } template <class T> constexpr inline T sumw(uint32_t, const T& v) { return v; }
template <class T> constexpr inline T maxs(const T& v) { return v; } template <class T> constexpr inline T maxs(const T& v) { return v; }
template <class T> constexpr inline T mins(const T& v) { return v; } template <class T> constexpr inline T mins(const T& v) { return v; }
template <class T> constexpr inline T avgs(const T& v) { return v; } template <class T> constexpr inline T avgs(const T& v) { return v; }

@ -2,14 +2,14 @@
#include "types.h" #include "types.h"
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <cstdio>
#include <string>
template <class ...Types> template <class ...Types>
std::string generate_printf_string(const char* sep = " ", const char* end = "\n") { std::string generate_printf_string(const char* sep = " ", const char* end = "\n") {
std::string str; std::string str;
(void)std::initializer_list<int>{ ((str += types::printf_str[types::Types<value_type_r<Types>>::getType()], str += sep), ...);
(str += types::printf_str[types::Types<Types>::getType()], str += sep, 0)... const auto trim = str.size() - strlen(sep);
}; if (trim > 0)
str.resize(trim);
str += end; str += end;
return str; return str;
} }

@ -98,7 +98,7 @@ int _main()
} }
dlclose(handle); dlclose(handle);
} }
static_assert(std::is_same_v<decltype(fill_integer_array<5, 1>()), std::integer_sequence<bool, 1,1,1,1,1>>, ""); //static_assert(std::is_same_v<decltype(fill_integer_array<5, 1>()), std::integer_sequence<bool, 1,1,1,1,1>>, "");
return 0; return 0;
} }

@ -10,30 +10,48 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server.vcxproj",
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msc-plugin", "..\msc-plugin\msc-plugin.vcxproj", "{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msc-plugin", "..\msc-plugin\msc-plugin.vcxproj", "{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}"
EndProject EndProject
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "msvs-py", "..\msvs-py\msvs-py.pyproj", "{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Debug|x86 = Debug|x86 Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64 Release|x64 = Release|x64
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|Any CPU.ActiveCfg = Debug|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|Any CPU.Build.0 = Debug|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.ActiveCfg = Debug|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.ActiveCfg = Debug|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.Build.0 = Debug|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.Build.0 = Debug|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.ActiveCfg = Debug|Win32 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.ActiveCfg = Debug|Win32
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.Build.0 = Debug|Win32 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.Build.0 = Debug|Win32
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|Any CPU.ActiveCfg = Release|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|Any CPU.Build.0 = Release|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.ActiveCfg = Release|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.ActiveCfg = Release|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.Build.0 = Release|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.Build.0 = Release|x64
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.ActiveCfg = Release|Win32 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.ActiveCfg = Release|Win32
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.Build.0 = Release|Win32 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.Build.0 = Release|Win32
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|Any CPU.ActiveCfg = Debug|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|Any CPU.Build.0 = Debug|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.ActiveCfg = Debug|x64 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.ActiveCfg = Debug|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.Build.0 = Debug|x64 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.Build.0 = Debug|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.ActiveCfg = Debug|Win32 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.ActiveCfg = Debug|Win32
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.Build.0 = Debug|Win32 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.Build.0 = Debug|Win32
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|Any CPU.ActiveCfg = Release|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|Any CPU.Build.0 = Release|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.ActiveCfg = Release|x64 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.ActiveCfg = Release|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.Build.0 = Release|x64 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.Build.0 = Release|x64
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.ActiveCfg = Release|Win32 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.ActiveCfg = Release|Win32
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.Build.0 = Release|Win32 {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.Build.0 = Release|Win32
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|x64.ActiveCfg = Debug|Any CPU
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|x86.ActiveCfg = Debug|Any CPU
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|x64.ActiveCfg = Release|Any CPU
{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -167,6 +167,7 @@
<ClInclude Include="aggregations.h" /> <ClInclude Include="aggregations.h" />
<ClInclude Include="gc.hpp" /> <ClInclude Include="gc.hpp" />
<ClInclude Include="hasher.h" /> <ClInclude Include="hasher.h" />
<ClInclude Include="io.h" />
<ClInclude Include="libaquery.h" /> <ClInclude Include="libaquery.h" />
<ClInclude Include="priority_vector.hpp" /> <ClInclude Include="priority_vector.hpp" />
<ClInclude Include="table.h" /> <ClInclude Include="table.h" />

@ -6,6 +6,8 @@
#include "types.h" #include "types.h"
#include "vector_type.hpp" #include "vector_type.hpp"
#include <iostream> #include <iostream>
#include <string>
#include "io.h"
template <typename T> template <typename T>
class vector_type; class vector_type;
template <> template <>
@ -26,8 +28,10 @@ template<typename _Ty>
class ColRef : public vector_type<_Ty> class ColRef : public vector_type<_Ty>
{ {
public: public:
typedef ColRef<_Ty> Decayed_t;
const char* name; const char* name;
types::Type_t ty = types::ERROR; types::Type_t ty = types::ERROR;
ColRef() : vector_type<_Ty>(0), name("") {}
ColRef(const uint32_t& size, const char* name = "") : vector_type<_Ty>(size), name(name) {} ColRef(const uint32_t& size, const char* name = "") : vector_type<_Ty>(size), name(name) {}
ColRef(const char* name) : name(name) {} ColRef(const char* name) : name(name) {}
void init() { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; } void init() { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; }
@ -37,6 +41,14 @@ public:
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const { ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
return ColView<_Ty>(*this, idxs); return ColView<_Ty>(*this, idxs);
} }
void out(uint32_t n = 4, const char* sep = " ") const {
n = n > this->size ? this->size : n;
std::cout << '(';
for (uint32_t i = 0; i < n; ++i)
std::cout << this->operator[](i) << sep;
std::cout << ')';
}
template<typename T> template<typename T>
ColRef<T> scast(); ColRef<T> scast();
}; };
@ -44,6 +56,7 @@ public:
template<typename _Ty> template<typename _Ty>
class ColView { class ColView {
public: public:
typedef ColRef<_Ty> Decayed_t;
const vector_type<uint32_t>& idxs; const vector_type<uint32_t>& idxs;
const ColRef<_Ty>& orig; const ColRef<_Ty>& orig;
const uint32_t& size; const uint32_t& size;
@ -77,8 +90,22 @@ public:
Iterator_t end() const { Iterator_t end() const {
return Iterator_t(idxs.end(), orig); return Iterator_t(idxs.end(), orig);
} }
void out(uint32_t n = 4, const char* sep = " ") const {
n = n > size ? size : n;
std::cout<<'(';
for (uint32_t i = 0; i < n; ++i)
std::cout << this->operator[](i)<< sep;
std::cout << ')';
}
}; };
template <template <class...> class VT, class T>
std::ostream& operator<<(std::ostream& os, const VT<T>& v)
{
v.out();
return os;
}
template <class Type>
struct decayed_impl<ColView, Type> { typedef ColRef<Type> type; };
template<typename _Ty> template<typename _Ty>
template<typename T> template<typename T>
inline ColRef<T> ColRef<_Ty>::scast() inline ColRef<T> ColRef<_Ty>::scast()
@ -103,6 +130,17 @@ template <long long _Index, class... _Types>
constexpr inline ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableView<_Types...>& table) noexcept { constexpr inline ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableView<_Types...>& table) noexcept {
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.info.colrefs[_Index]); return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.info.colrefs[_Index]);
} }
template <class T>
struct is_vector_impl : std::false_type {};
template <class V>
struct is_vector_impl<ColRef<V>> : std::true_type {};
template <class V>
struct is_vector_impl<ColView<V>> : std::true_type {};
template <class V>
struct is_vector_impl<vector_type<V>> : std::true_type {};
template <class T>
constexpr static bool is_vector_type = is_vector_impl<T>::value;
template<class ...Types> template<class ...Types>
struct TableView; struct TableView;
template<class ...Types> template<class ...Types>
@ -158,7 +196,49 @@ struct TableInfo {
auto order_by_view () { auto order_by_view () {
return TableView<Types...>(order_by<cols...>(), *this); return TableView<Types...>(order_by<cols...>(), *this);
} }
template <int col, int ...rem_cols, class Fn, class ...__Types>
inline void print2_impl(Fn func, const uint32_t& i, const __Types& ... args) const {
using this_type = typename std::tuple_element<col, tuple_type>::type;
const auto& this_value = get<col>(*this)[i];
const auto& next = [&](auto &v) {
if constexpr (sizeof...(rem_cols) == 0)
func(args..., v);
else
print2_impl<rem_cols...>(func, i, args ..., v);
};
if constexpr (is_vector_type<this_type>)
for (int j = 0; j < this_value.size; ++j)
next(this_value[j]);
else
next(this_value);
}
template <int ...cols>
void print2(const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type<uint32_t>* __restrict view = nullptr, FILE* __restrict fp = nullptr) const {
std::string printf_string =
generate_printf_string<typename std::tuple_element<cols, tuple_type>::type ...>(sep, end);
const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
if(view)
for (int i = 0; i < view->size; ++i)
print2_impl<cols...>(f, (*view)[i], printf_string.c_str());
else
for (int i = 0; i < colrefs[0].size; ++i)
print2_impl<cols...>(f, i, printf_string.c_str());
};
if (fp)
prt_loop([&fp](auto... args) { fprintf(fp, args...); });
else
prt_loop(printf);
}
template <int ...vals> struct applier {
inline constexpr static void apply(const TableInfo<Types...>& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type<uint32_t>* __restrict view = nullptr, FILE* __restrict fp = nullptr)
{ t.template print2<vals ...>(sep, end, view, fp); }};
inline void printall(const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type<uint32_t>* __restrict view = nullptr, FILE* __restrict fp = nullptr) {
applyIntegerSequence<sizeof...(Types), applier>::apply(*this, sep, end, view, fp);
}
}; };
@ -189,6 +269,9 @@ template <class T>
constexpr static inline bool is_vector(const T&) { constexpr static inline bool is_vector(const T&) {
return false; return false;
} }
template<class ...Types> template<class ...Types>
TableInfo<Types...>::TableInfo(const char* name, uint32_t n_cols) : name(name), n_cols(n_cols) { TableInfo<Types...>::TableInfo(const char* name, uint32_t n_cols) : name(name), n_cols(n_cols) {
this->colrefs = (ColRef<void>*)malloc(sizeof(ColRef<void>) * n_cols); this->colrefs = (ColRef<void>*)malloc(sizeof(ColRef<void>) * n_cols);

@ -1,11 +1,6 @@
#include "types.h" #include "types.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
//template<typename T>
//inline static constexpr void types::Types<T>::print(T& v)
//{
// std::cout << v;
//}
#include <chrono> #include <chrono>
#include <ctime> #include <ctime>
namespace types { namespace types {

@ -14,8 +14,8 @@ namespace types {
AINT, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, ALONG, ASHORT, ADATE, ATIME, ACHAR, AINT, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, ALONG, ASHORT, ADATE, ATIME, ACHAR,
AUINT, AULONG, AUSHORT, AUCHAR, NONE, ERROR AUINT, AULONG, AUSHORT, AUCHAR, NONE, ERROR
}; };
static constexpr const char* printf_str[] = { "%d ", "%f ", "%s ", "%lf ", "%llf ", "%ld ", "%hi ", "%s ", "%s ", "%c ", static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%llf", "%ld", "%hi", "%s", "%s", "%c",
"%u ", "%lu ", "%hu ", "%hhu ", "NULL " }; "%u", "%lu", "%hu", "%hhu", "NULL" };
// TODO: deal with data/time <=> str/uint conversion // TODO: deal with data/time <=> str/uint conversion
struct date_t { struct date_t {
uint32_t val; uint32_t val;
@ -77,13 +77,13 @@ namespace types {
using type = Cond(__Eq(float), float, Cond(__Eq(double), double, long double)); using type = Cond(__Eq(float), float, Cond(__Eq(double), double, long double));
}; };
template<class T> template<class T>
using GetFPType = typename GetFPTypeImpl<T>::type; using GetFPType = typename GetFPTypeImpl<typename std::decay<T>::type>::type;
template<class T> template<class T>
struct GetLongTypeImpl { struct GetLongTypeImpl {
using type = Cond(_U(T), unsigned long long, Cond(Fp(T), long double, long long)); using type = Cond(_U(T), unsigned long long, Cond(Fp(T), long double, long long));
}; };
template<class T> template<class T>
using GetLongType = typename GetLongTypeImpl<T>::type; using GetLongType = typename GetLongTypeImpl<typename std::decay<T>::type>::type;
} }
#define getT(i, t) std::tuple_element_t<i, std::tuple<t...>> #define getT(i, t) std::tuple_element_t<i, std::tuple<t...>>
@ -122,12 +122,61 @@ using decays = typename decayS<typename std::decay<T>::type>::type;
template <class T> template <class T>
using decay_inner = typename decayS<T>::type; using decay_inner = typename decayS<T>::type;
template <int n, bool v = 1, bool ...vals> template <class, template <class...> class T>
auto fill_integer_array() { struct instance_of_impl : std::false_type {};
if constexpr (n == 0) template <class ...T1, template <class ...> class T2>
return std::integer_sequence<bool, vals...>{}; struct instance_of_impl<T2<T1...>, T2> : std::true_type {};
else
return fill_integer_array<n - 1, v, v, vals...>(); template <class T1, class T2>
struct same_class_impl : std::false_type {};
template <class ...T1s, class ...T2s, template <class...> class T1>
struct same_class_impl<T1<T1s...>, T1<T2s...>> : std::true_type {};
template <class T1, class T2>
bool same_class = same_class_impl<T1, T2>::value;
template <class T1, template <class...> class T2>
bool instance_of = instance_of_impl<T1, T2>::value;
template <class lT, template <typename ...> class rT>
using transTypes = typename transTypes_s<lT, rT>::type;
template <class lT, class vT, template <vT ...> class rT>
struct transValues_s;
template <class vT, template<class, vT ...> class lT, vT ...T, template<vT ...> class rT>
struct transValues_s<lT<vT, T...>, vT, rT> {
using type = rT<T...>;
}; };
#include <utility>
template <class vT, int i, template <vT ...> class rT>
using transValues = typename transValues_s<std::make_integer_sequence<vT, i>, vT, rT>::type;
template <int i, template <int ...> class rT>
using applyIntegerSequence = typename transValues_s<std::make_integer_sequence<int, i>, int, rT>::type;
template <template <class ...> class T, class ...Types>
struct decayed_impl{ typedef T<Types...> type;};
template <template <typename ...> class VT, class ...Types>
using decayed_t = typename decayed_impl<VT, Types...>::type;
template <class First = void, class...Rest>
struct get_first_impl {
typedef First first;
constexpr static size_t rest_len = sizeof...(Rest);
typedef get_first_impl<Rest...> rest;
};
template <class ...T>
using get_first = typename get_first_impl<T...>::first;
template <class T>
struct value_type_impl { typedef T type; };
template <template <class...> class VT, class ...V>
struct value_type_impl<VT<V...>> { typedef get_first<V...> type; };
template <class T>
using value_type = typename value_type_impl<T>::type;
template <class ...T>
using get_first = typename get_first_impl<T...>::first;
template <class T>
struct value_type_rec_impl { typedef T type; };
template <template <class...> class VT, class ...V>
struct value_type_rec_impl<VT<V...>> { typedef typename value_type_rec_impl<get_first<int>>::type type; };
template <class T>
using value_type_r = typename value_type_rec_impl<T>::type;
#endif // !_TYPES_H #endif // !_TYPES_H

@ -1 +1,11 @@
#include "vector_type.hpp" #include "vector_type.hpp"
#include <iostream>
template<typename _Ty>
inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
{
n = n > size ? size : n;
std::cout << '(';
for (uint32_t i = 0; i < n; ++i)
std::cout << this->operator[](i) << sep;
std::cout << ')';
}

@ -22,7 +22,11 @@
template <typename _Ty> template <typename _Ty>
class vector_type { class vector_type {
public: public:
typedef vector_type<_Ty> Decayed_t;
void inline _copy(const vector_type<_Ty>& vt) { void inline _copy(const vector_type<_Ty>& vt) {
// quick init while using malloc
//if (capacity > 0) free(container);
this->size = vt.size; this->size = vt.size;
this->capacity = vt.capacity; this->capacity = vt.capacity;
this->container = (_Ty*)malloc(size * sizeof(_Ty)); this->container = (_Ty*)malloc(size * sizeof(_Ty));
@ -54,10 +58,10 @@ public:
} }
} }
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {}; constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
constexpr vector_type(const vector_type<_Ty>& vt) noexcept { constexpr vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) {
_copy(vt); _copy(vt);
} }
constexpr vector_type(vector_type<_Ty>&& vt) noexcept { constexpr vector_type(vector_type<_Ty>&& vt) noexcept : capacity(0) {
_move(std::move(vt)); _move(std::move(vt));
} }
vector_type<_Ty> operator =(const _Ty& vt) { vector_type<_Ty> operator =(const _Ty& vt) {
@ -179,6 +183,7 @@ public:
} }
size = this->size + dist; size = this->size + dist;
} }
void out(uint32_t n = 4, const char* sep = " ") const;
~vector_type() { ~vector_type() {
if (capacity > 0) free(container); if (capacity > 0) free(container);
container = 0; size = capacity = 0; container = 0; size = capacity = 0;
@ -250,7 +255,7 @@ public:
} }
} }
constexpr vector_type() : size(0), capacity(0), container(0) {}; constexpr vector_type() : size(0), capacity(0), container(0) {};
void *get(uint32_t i, types::Type_t atype){ void* get(uint32_t i, types::Type_t atype){
return static_cast<void*>(static_cast<char*>(container) + (i * types::AType_sizes[atype])); return static_cast<void*>(static_cast<char*>(container) + (i * types::AType_sizes[atype]));
} }
void operator[](const uint32_t& i) { void operator[](const uint32_t& i) {

Loading…
Cancel
Save