diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9268e1b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "paper"] + path = paper + url = https://github.com/sunyinqi0508/AQueryPaper diff --git a/paper b/paper new file mode 160000 index 0000000..fa4e3f5 --- /dev/null +++ b/paper @@ -0,0 +1 @@ +Subproject commit fa4e3f5a0606b2dda75faaacfb66cdaf42153260 diff --git a/rfdata_preproc.py b/rfdata_preproc.py index e6720a2..6a7b760 100644 --- a/rfdata_preproc.py +++ b/rfdata_preproc.py @@ -26,6 +26,7 @@ def process(f : str): with open(filename, 'rb') as ifile: icontents = ifile.read() with open(ofilename, 'wb') as ofile: + ofile.write(b'\n') for l in icontents.splitlines(): fields = l.strip().split(b' ') subfields = fields[:-1] diff --git a/sdk/irf.cpp b/sdk/irf.cpp index f1820d2..745f6d2 100644 --- a/sdk/irf.cpp +++ b/sdk/irf.cpp @@ -1,22 +1,26 @@ #include "DecisionTree.h" +#include "RF.h" + // __AQ_NO_SESSION__ #include "../server/table.h" #include "aquery.h" DecisionTree *dt = nullptr; +RandomForest *rf = nullptr; __AQEXPORT__(bool) -newtree(int height, long f, ColRef sparse, double forget, long maxf, long noclasses, Evaluation e, long r, long rb) +newtree(int height, long f, ColRef X, double forget, long maxf, long noclasses, Evaluation e, long r, long rb) { - if (sparse.size != f) + if (X.size != f) return false; - int *issparse = (int *)malloc(f * sizeof(int)); - for (long i = 0; i < f; i++) - issparse[i] = sparse.container[i]; + int *X_cpy = (int *)malloc(f * sizeof(int)); + + memcpy(X_cpy, X.container, f); if (maxf < 0) maxf = f; - dt = new DecisionTree(f, issparse, forget, maxf, noclasses, e); + dt = new DecisionTree(f, X_cpy, forget, maxf, noclasses, e); + rf = new RandomForest(height, f, X_cpy, forget, noclasses, e) return true; } @@ -44,7 +48,8 @@ fit(vector_type> v, vector_type res) double **data = (double **)malloc(v.size * sizeof(double *)); for (int i = 0; i < v.size; ++i) data[i] = v.container[i].container; - dt->fit(data, res.container, v.size); + // dt->fit(data, res.container, v.size); + rf->fit(data, res.container, v.size); return true; } @@ -54,8 +59,8 @@ predict(vector_type> v) int *result = (int *)malloc(v.size * sizeof(int)); for (long i = 0; i < v.size; i++) - result[i] = dt->Test(v.container[i].container, dt->DTree); - + //result[i] = dt->Test(v.container[i].container, dt->DTree); + result[i] = rf->Test(v.container, rf->DTrees); auto container = (vector_type *)malloc(sizeof(vector_type)); container->size = v.size; container->capacity = 0; diff --git a/server/libaquery.cpp b/server/libaquery.cpp index 7217dc7..7df1870 100644 --- a/server/libaquery.cpp +++ b/server/libaquery.cpp @@ -281,15 +281,15 @@ inline const char* str(const bool& v) { return v ? "true" : "false"; } -class A{ +class A { public: std::chrono::high_resolution_clock::time_point tp; A(){ tp = std::chrono::high_resolution_clock::now(); - printf("A %llx created.\n", tp.time_since_epoch().count()); + printf("A %llu created.\n", tp.time_since_epoch().count()); } ~A() { - printf("A %llx died after %lldns.\n", tp.time_since_epoch().count(), + printf("A %llu died after %lldns.\n", tp.time_since_epoch().count(), (std::chrono::high_resolution_clock::now() - tp).count()); } }; diff --git a/server/mariadb_conn.h b/server/mariadb_conn.h index 170a7d8..a17e92b 100644 --- a/server/mariadb_conn.h +++ b/server/mariadb_conn.h @@ -6,17 +6,17 @@ struct Context; struct Server{ - MYSQL *server = 0; - Context *cxt = 0; - bool status = 0; + MYSQL *server = nullptr; + Context *cxt = nullptr; + bool status = false; bool has_error = false; - char* query = 0; + char* query = nullptr; int type = 0; void connect(Context* cxt, const char* host = "bill.local", const char* user = "root", const char* passwd = "0508", const char* db_name = "db", const unsigned int port = 3306, - const char* unix_socket = 0, const unsigned long client_flag = 0 + const char* unix_socket = nullptr, const unsigned long client_flag = 0 ); void exec(const char* q); void close(); diff --git a/server/monetdb_conn.cpp b/server/monetdb_conn.cpp index 21380ea..0ef14c2 100644 --- a/server/monetdb_conn.cpp +++ b/server/monetdb_conn.cpp @@ -18,8 +18,12 @@ #include #endif // _WIN32 -#undef ERROR -#undef static_assert +#ifdef ERROR + #undef ERROR +#endif +#ifdef static_assert + #undef static_assert +#endif constexpr const char* monetdbe_type_str[] = { "monetdbe_bool", "monetdbe_int8_t", "monetdbe_int16_t", "monetdbe_int32_t", "monetdbe_int64_t", @@ -86,7 +90,7 @@ void Server::connect(Context *cxt){ char c[50]; std::cin.getline(c, 49); for(int i = 0; i < 50; ++i) { - if (!c[i] || c[i] == 'y' || c[i] == 'Y'){ + if (!c[i] || c[i] == 'y' || c[i] == 'Y') { monetdbe_close(*server); free(*server); this->server = nullptr; @@ -120,7 +124,7 @@ void Server::exec(const char* q){ auto _res = static_cast(this->res); monetdbe_cnt _cnt = 0; auto qresult = monetdbe_query(*server, const_cast(q), &_res, &_cnt); - if (_res != 0){ + if (_res != nullptr){ this->cnt = _res->nrows; this->res = _res; } @@ -162,6 +166,8 @@ void Server::print_results(const char* sep, const char* end){ col_data[i] = static_cast(cols[i]->data); szs [i] = monetdbe_type_szs[cols[i]->type]; header_string = header_string + cols[i]->name + sep + '|' + sep; + if (err_msg) [[unlikely]] + puts(err_msg); } if (const size_t l_sep = strlen(sep) + 1; header_string.size() >= l_sep) header_string.resize(header_string.size() - l_sep); @@ -183,7 +189,7 @@ void Server::print_results(const char* sep, const char* end){ void Server::close(){ if(this->server){ auto server = static_cast(this->server); - monetdbe_close(*(server)); + monetdbe_close(*server); free(server); this->server = nullptr; } diff --git a/server/monetdb_conn.h b/server/monetdb_conn.h index 891c9a6..bd5f2d0 100644 --- a/server/monetdb_conn.h +++ b/server/monetdb_conn.h @@ -4,18 +4,18 @@ struct Context; struct Server{ - void *server = 0; - Context *cxt = 0; - bool status = 0; - char* query = 0; + void *server = nullptr; + Context *cxt = nullptr; + bool status = false; + char* query = nullptr; int type = 1; - void* res = 0; - void* ret_col = 0; + void* res = nullptr; + void* ret_col = nullptr; long long cnt = 0; - char* last_error = 0; + char* last_error = nullptr; - Server(Context* cxt = nullptr); + explicit Server(Context* cxt = nullptr); void connect(Context* cxt); void exec(const char* q); void *getCol(int col_idx); diff --git a/server/monetdb_ext.c b/server/monetdb_ext.c index 8111108..fe0e144 100644 --- a/server/monetdb_ext.c +++ b/server/monetdb_ext.c @@ -77,7 +77,7 @@ monetdbe_get_size(monetdbe_database dbhdl, const char *table_name) } void* -monetdbe_get_col(monetdbe_database dbhdl, const char *table_name, uint32_t col_id) { +monetdbe_get_col(monetdbe_database dbhdl, const char *table_name, uint32_t col_id) { monetdbe_database_internal* hdl = (monetdbe_database_internal*)dbhdl; backend* be = ((backend *)(((monetdbe_database_internal*)dbhdl)->c->sqlcontext)); mvc *m = be->mvc; diff --git a/server/priority_vector.hpp b/server/priority_vector.hpp index f1c7d6f..389b06a 100644 --- a/server/priority_vector.hpp +++ b/server/priority_vector.hpp @@ -6,7 +6,7 @@ template class priority_vector : public vector_type { const Comparator comp; public: - priority_vector(Comparator comp = std::less{}) : + explicit priority_vector(Comparator comp = std::less{}) : comp(comp), vector_type(0) {} void emplace_back(T val) { vector_type::emplace_back(val); diff --git a/tests/dt2.a b/tests/dt2.a index 5f7fd2a..bf59543 100644 --- a/tests/dt2.a +++ b/tests/dt2.a @@ -6,6 +6,8 @@ LOAD MODULE FROM "./libirf.so" ); create table source(x1 double, x2 double, x3 double, x4 double, x5 int64); +-- Create trigger 1 ~~ to predict whenever sz(source > ?) +-- Create trigger 2 ~~ to auto feed ~ load data infile "data/benchmark" into table source fields terminated by ","; create table sparse(x int);