From 3051eb5fe77be27eca371de9566742465bf8f668 Mon Sep 17 00:00:00 2001 From: bill sun Date: Mon, 2 May 2022 08:35:50 +0800 Subject: [PATCH] bug fixes --- engine/ddl.py | 6 +- engine/expr.py | 1 + engine/groupby.py | 2 +- moving_avg.a | 2 +- msc-plugin/msc-plugin.vcxproj | 22 +- out.cpp | 124 ++--- prompt.py | 54 ++- .../3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H | 15 + .../d544cc15c643dbd4f18da52d811c040/table.h | 443 ++++++++++++++++++ server/server.vcxproj | 16 +- server/table.h | 8 +- server/vector_type.hpp | 2 +- 12 files changed, 602 insertions(+), 93 deletions(-) create mode 100644 server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H create mode 100644 server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h diff --git a/engine/ddl.py b/engine/ddl.py index 60be2be..f1511db 100644 --- a/engine/ddl.py +++ b/engine/ddl.py @@ -28,7 +28,7 @@ class create_table(ast_node): # create an empty new table if self.cexprs is None: for c in tbl.columns: - self.emit(f"{c.cxt_name}.init();") + self.emit(f"{c.cxt_name}.init({c.name});") # create an output table else: # 1 to 1 lineage. @@ -40,7 +40,7 @@ class create_table(ast_node): else: self.lineage = None for i, c in enumerate(tbl.columns): - self.emit(f"{c.cxt_name}.init();") + self.emit(f"{c.cxt_name}.init({c.name});") self.emit(f"{c.cxt_name} = {self.cexprs[i](self.lineage)};") self.lineage = None self.parent.assumptions = None @@ -54,7 +54,7 @@ class create_table(ast_node): scanner.add(f"{lineage_var}.emplace_back({counter_var}++);", "front") self.lineage = f"{lineage_var}.rid" for i, c in enumerate(tbl.columns): - scanner.add(f"{c.cxt_name}.init();", "init") + scanner.add(f"{c.cxt_name}.init({c.name});", "init") scanner.add(f"{c.cxt_name} = {self.cexprs[i](scanner.it_ver)};") class insert(ast_node): diff --git a/engine/expr.py b/engine/expr.py index b387d79..71d14f4 100644 --- a/engine/expr.py +++ b/engine/expr.py @@ -50,6 +50,7 @@ class expr(ast_node): self.inside_agg = False if(type(parent) is expr): self.inside_agg = parent.inside_agg + self.__abs = parent.__abs ast_node.__init__(self, parent, node, None) def init(self, _): diff --git a/engine/groupby.py b/engine/groupby.py index 3a23c34..4299e10 100644 --- a/engine/groupby.py +++ b/engine/groupby.py @@ -55,7 +55,7 @@ class groupby(ast_node): gscanner = scan(self, self.group) val_var = 'val_'+base62uuid(7) gscanner.add(f'auto &{val_var} = {gscanner.it_ver}.second;') - gscanner.add(f'{out.cxt_name}->order_by<{assumption.result()}>(&{val_var});') + gscanner.add(f'{self.datasource.cxt_name}->order_by<{assumption.result()}>(&{val_var});') gscanner.finalize() def finalize(self, cexprs, out:TableInfo): diff --git a/moving_avg.a b/moving_avg.a index f9b21e5..c0fb9a3 100644 --- a/moving_avg.a +++ b/moving_avg.a @@ -10,5 +10,5 @@ FROM sale INTO OUTFILE "moving_avg_output.csv" FIELDS TERMINATED BY ";" -select sales, mins(2,Month) from sale group by sales +select Month, mins(2,sales) from sale assuming desc Month group by sales into outfile "flatten.csv" \ No newline at end of file diff --git a/msc-plugin/msc-plugin.vcxproj b/msc-plugin/msc-plugin.vcxproj index 682cfb8..7194878 100644 --- a/msc-plugin/msc-plugin.vcxproj +++ b/msc-plugin/msc-plugin.vcxproj @@ -32,6 +32,7 @@ true v143 Unicode + false DynamicLibrary @@ -39,12 +40,15 @@ v143 true Unicode + true DynamicLibrary true v143 Unicode + true + false DynamicLibrary @@ -52,6 +56,7 @@ v143 true Unicode + true @@ -94,11 +99,14 @@ _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest + Guard + true Console - true + DebugFull $(ProjectDir)\..\dll.so + true @@ -123,14 +131,22 @@ Level3 true - _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _ALLOW_RTCc_IN_STL;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest + Guard + true + ProgramDatabase + Disabled + false + true + false Console - true + DebugFull $(ProjectDir)\..\dll.so + true diff --git a/out.cpp b/out.cpp index 03d68f4..f282ad1 100644 --- a/out.cpp +++ b/out.cpp @@ -1,61 +1,79 @@ -#include "./server/hasher.h" -#include "./server/aggregations.h" -#include "csv.h" #include "./server/libaquery.h" -#include +#include "./server/aggregations.h" extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { using namespace std; using namespace types; - auto sale = new TableInfo("sale", 2); -cxt->tables.insert({"sale", sale}); -auto& sale_Month = *(ColRef *)(&sale->colrefs[0]); -auto& sale_sales = *(ColRef *)(&sale->colrefs[1]); -sale_Month.init(); -sale_sales.init(); -io::CSVReader<2> csv_reader_6T89Ll("moving_avg.csv"); -csv_reader_6T89Ll.read_header(io::ignore_extra_column, "Month","sales"); -int tmp_5vttJ2yV; -int tmp_2ckq15YU; -while(csv_reader_6T89Ll.read_row(tmp_5vttJ2yV,tmp_2ckq15YU)) { - -sale_Month.emplace_back(tmp_5vttJ2yV); -sale_sales.emplace_back(tmp_2ckq15YU); -} -auto out_2UiD = new TableInfo>,value_type>>("out_2UiD", 2); -cxt->tables.insert({"out_2UiD", out_2UiD}); -auto& out_2UiD_Month = *(ColRef>> *)(&out_2UiD->colrefs[0]); -auto& out_2UiD_avgw3salesales = *(ColRef>> *)(&out_2UiD->colrefs[1]); -auto order_1NNZ9F = sale->order_by<0>(); -out_2UiD_Month.init(); -out_2UiD_Month = sale_Month[*order_1NNZ9F]; -out_2UiD_avgw3salesales.init(); -out_2UiD_avgw3salesales = avgw(3,sale_sales[*order_1NNZ9F]); -print(*out_2UiD); -FILE* fp_6xIJn4 = fopen("moving_avg_output.csv", "w"); -out_2UiD->printall(";", "\n", nullptr, fp_6xIJn4); -fclose(fp_6xIJn4); -typedef record record_type6Lepq5T; -unordered_map, transTypes> g4loWjmn; -for (uint32_t i5g = 0; i5g < sale_sales.size; ++i5g){ -g4loWjmn[forward_as_tuple(sale_sales[i5g])].emplace_back(i5g); -} -auto out_2YlO = new TableInfo>,decays>("out_2YlO", 2); -cxt->tables.insert({"out_2YlO", out_2YlO}); -auto& out_2YlO_sales = *(ColRef>> *)(&out_2YlO->colrefs[0]); -auto& out_2YlO_minw2saleMonth = *(ColRef> *)(&out_2YlO->colrefs[1]); -out_2YlO_sales.init(); -out_2YlO_minw2saleMonth.init(); -for(auto& iFU : g4loWjmn) { -auto &key_3AwvKMR = iFU.first; -auto &val_7jtE12E = iFU.second; -out_2YlO_sales.emplace_back(get<0>(key_3AwvKMR)); -out_2YlO_minw2saleMonth.emplace_back(minw(2,sale_Month[val_7jtE12E])); -} -print(*out_2YlO); -FILE* fp_45ld6S = fopen("flatten.csv", "w"); -out_2YlO->printall(",", "\n", nullptr, fp_45ld6S); -fclose(fp_45ld6S); + auto stocks = new TableInfo("stocks", 2); +cxt->tables.insert({"stocks", stocks}); +auto& stocks_timestamp = *(ColRef *)(&stocks->colrefs[0]); +auto& stocks_price = *(ColRef *)(&stocks->colrefs[1]); +stocks_timestamp.init(); +stocks_price.init(); +stocks_timestamp.emplace_back(1); +stocks_price.emplace_back(15); +stocks_timestamp.emplace_back(2); +stocks_price.emplace_back(19); +stocks_timestamp.emplace_back(3); +stocks_price.emplace_back(16); +stocks_timestamp.emplace_back(4); +stocks_price.emplace_back(17); +stocks_timestamp.emplace_back(5); +stocks_price.emplace_back(15); +stocks_timestamp.emplace_back(6); +stocks_price.emplace_back(13); +stocks_timestamp.emplace_back(7); +stocks_price.emplace_back(5); +stocks_timestamp.emplace_back(8); +stocks_price.emplace_back(8); +stocks_timestamp.emplace_back(9); +stocks_price.emplace_back(7); +stocks_timestamp.emplace_back(10); +stocks_price.emplace_back(13); +stocks_timestamp.emplace_back(11); +stocks_price.emplace_back(11); +stocks_timestamp.emplace_back(12); +stocks_price.emplace_back(14); +stocks_timestamp.emplace_back(13); +stocks_price.emplace_back(10); +stocks_timestamp.emplace_back(14); +stocks_price.emplace_back(5); +stocks_timestamp.emplace_back(15); +stocks_price.emplace_back(2); +stocks_timestamp.emplace_back(16); +stocks_price.emplace_back(5); +auto out_oMxe = new TableInfo>>("out_oMxe", 1); +cxt->tables.insert({"out_oMxe", out_oMxe}); +auto& out_oMxe_maxstockspriceminstockstimestamp = *(ColRef>> *)(&out_oMxe->colrefs[0]); +out_oMxe_maxstockspriceminstockstimestamp.init(); +out_oMxe_maxstockspriceminstockstimestamp = max((stocks_price-min(stocks_timestamp))); +print(*out_oMxe); +auto out_2ZWg = new TableInfo>>("out_2ZWg", 1); +cxt->tables.insert({"out_2ZWg", out_2ZWg}); +auto& out_2ZWg_maxstockspriceminsstocksprice = *(ColRef>> *)(&out_2ZWg->colrefs[0]); +out_2ZWg_maxstockspriceminsstocksprice.init(); +out_2ZWg_maxstockspriceminsstocksprice = max((stocks_price-mins(stocks_price))); +print(*out_2ZWg); +const auto& tmp_sz_B19sAY = stocks_timestamp.size; +auto out_JZsz = new TableInfo>,value_type>>("out_JZsz", 2); +cxt->tables.insert({"out_JZsz", out_JZsz}); +auto& out_JZsz_price = *(ColRef>> *)(&out_JZsz->colrefs[0]); +auto& out_JZsz_timestamp = *(ColRef>> *)(&out_JZsz->colrefs[1]); +out_JZsz_price.init(); +out_JZsz_timestamp.init(); +for (uint32_t i3D = 0; i3D < tmp_sz_B19sAY; ++i3D){ +if ((((stocks_price[i3D]-stocks_timestamp[i3D])>=1)&&!(((stocks_price[i3D]*stocks_timestamp[i3D])<100)))) { +out_JZsz_price = stocks_price[i3D]; +out_JZsz_timestamp = stocks_timestamp[i3D]; +}} +print(*out_JZsz); +auto out_2Fm0 = new TableInfo>>("out_2Fm0", 1); +cxt->tables.insert({"out_2Fm0", out_2Fm0}); +auto& out_2Fm0_maxstockspriceminsstocksprice = *(ColRef>> *)(&out_2Fm0->colrefs[0]); +auto order_5qqTLa = stocks->order_by<-1>(); +out_2Fm0_maxstockspriceminsstocksprice.init(); +out_2Fm0_maxstockspriceminsstocksprice = max((stocks_price[*order_5qqTLa]-mins(stocks_price[*order_5qqTLa]))); +print(*out_2Fm0); return 0; } \ No newline at end of file diff --git a/prompt.py b/prompt.py index e956c3a..67741d1 100644 --- a/prompt.py +++ b/prompt.py @@ -42,27 +42,31 @@ def rm(): cleanup = False atexit.register(rm) - -shm = base62uuid() -if sys.platform != 'win32': - import readline - shm += '.shm' - basecmd = ['bash', '-c', 'rlwrap k'] - mm = None - if not os.path.isfile(shm): - # create initial file - with open(shm, "w+b") as handle: - handle.write(b'\x01\x00') # [running, new job] - handle.flush() - mm = mmap.mmap(handle.fileno(), 2, access=mmap.ACCESS_WRITE, offset=0) - if mm is None: - exit(1) -else: - basecmd = ['bash.exe', '-c', 'rlwrap ./k'] - mm = mmap.mmap(0, 2, shm) - mm.write(b'\x01\x00') - mm.flush() -server = subprocess.Popen(["./server.bin", shm]) + +def init(): + global shm, server, basecmd, mm + shm = base62uuid() + if sys.platform != 'win32': + import readline + shm += '.shm' + basecmd = ['bash', '-c', 'rlwrap k'] + mm = None + if not os.path.isfile(shm): + # create initial file + with open(shm, "w+b") as handle: + handle.write(b'\x01\x00') # [running, new job] + handle.flush() + mm = mmap.mmap(handle.fileno(), 2, access=mmap.ACCESS_WRITE, offset=0) + if mm is None: + exit(1) + else: + basecmd = ['bash.exe', '-c', 'rlwrap ./k'] + mm = mmap.mmap(0, 2, shm) + mm.write(b'\x01\x00') + mm.flush() + server = subprocess.Popen(["./server.bin", shm]) + +init() test_parser = True @@ -92,10 +96,8 @@ cxt = None while test_parser: try: if server.poll() is not None: - mm.seek(0,os.SEEK_SET) - mm.write(b'\x01\x00') - server = subprocess.Popen(["./server.bin", shm]) - q = input() + init() + q = input().lower() if q == 'exec': if not keep or cxt is None: cxt = engine.initialize() @@ -145,7 +147,7 @@ while test_parser: else trimed[1] with open(fn, 'r') as file: - contents = file.read() + contents = file.read()#.lower() stmts = parser.parse(contents) continue stmts = parser.parse(q) diff --git a/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H b/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H new file mode 100644 index 0000000..757cb76 --- /dev/null +++ b/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H @@ -0,0 +1,15 @@ +#pragma once +#include "types.h" +#include +#include +template +std::string generate_printf_string(const char* sep = " ", const char* end = "\n") { + std::string str; + ((str += types::printf_str[types::Types>::getType()], str += sep), ...); + const auto trim = str.size() - strlen(sep); + if (trim > 0) + str.resize(trim); + str += end; + return str; +} + diff --git a/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h b/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h new file mode 100644 index 0000000..059c3e6 --- /dev/null +++ b/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h @@ -0,0 +1,443 @@ +// TODO: Replace `cout, printf` with sprintf&fputs and custom buffers + +#ifndef _TABLE_H +#define _TABLE_H + +#include "types.h" +#include "vector_type.hpp" +#include +#include +#include "io.h" +template +class vector_type; +template <> +class vector_type; + +#ifdef _MSC_VER +namespace types { + enum Type_t; + template + struct Types; + template + struct Coercion; +} +#endif +template +class ColView; +template +class ColRef : public vector_type<_Ty> +{ +public: + typedef ColRef<_Ty> Decayed_t; + const char* name; + 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 char* name) : name(name) {} + void init(const char* name = "") { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; this->name = name; } + ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {} + using vector_type<_Ty>::operator[]; + using vector_type<_Ty>::operator=; + ColView<_Ty> operator [](const vector_type&idxs) const { + 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 + ColRef scast(); +}; + +template +class ColView { +public: + typedef ColRef<_Ty> Decayed_t; + const vector_type& idxs; + const ColRef<_Ty>& orig; + const uint32_t& size; + ColView(const ColRef<_Ty>& orig, const vector_type& idxs) : orig(orig), idxs(idxs), size(idxs.size) {} + ColView(const ColView<_Ty>& orig, const vector_type& idxs) : orig(orig.orig), idxs(idxs), size(idxs.size) { + for (uint32_t i = 0; i < size; ++i) + idxs[i] = orig.idxs[idxs[i]]; + } + _Ty& operator [](const uint32_t& i) const { + return orig[idxs[i]]; + } + struct Iterator_t { + const uint32_t* val; + const ColRef<_Ty>& orig; + constexpr Iterator_t(const uint32_t* val, const ColRef<_Ty>& orig) noexcept : val(val), orig(orig) {} + _Ty& operator*() { return orig[*val]; } + bool operator != (const Iterator_t& rhs) { return rhs.val != val; } + Iterator_t& operator++ () { + ++val; + return *this; + } + Iterator_t operator++ (int) { + Iterator_t tmp = *this; + ++val; + return tmp; + } + }; + Iterator_t begin() const { + return Iterator_t(idxs.begin(), orig); + } + Iterator_t end() const { + 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 << ')'; + } + operator ColRef<_Ty>() { + auto ret = ColRef<_Ty>(size); + for (uint32_t i = 0; i < size; ++i) + ret[i] = orig[idxs[i]]; + return ret; + } +}; +template