diff --git a/build_instructions.txt b/build_instructions.txt
deleted file mode 100644
index d5d8297..0000000
--- a/build_instructions.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-## Windows
-- clang-msvc:
- - "%CXX%" -D_CRT_SECURE_NO_WARNINGS -shared server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc -Lmonetdb/msvc -lmonetdbe.lib --std=c++2a -o server.so
- - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))
-- gcc-mingw (link w/ msvc monetdb):
- - "%CXX%" -shared -fPIC server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc msc-plugin/monetdbe.dll --std=c++2a -o server.so
- - os.add_dll_directory('c:/msys64/usr/bin')
- - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))
-- gcc-mingw (link w/ mingw monetdb, can only load under mingw python):
- - $(CXX) server/server.cpp server/monetdb_conn.cpp -fPIC -shared $(OS_SUPPORT) --std=c++1z -O3 -march=native -o server.so -I./monetdb/msys64 -L./lib -lmonetdbe
- - add_dll_dir(os.path.abspath('./lib'))
-- msvc:
- - D:\gg\vs22\MSBuild\Current\Bin\msbuild "d:\gg\AQuery++\server\server.vcxproj" /p:configuration=Release /p:platform=x64
- - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))
diff --git a/msc-plugin/libaquery.vcxproj b/msc-plugin/libaquery.vcxproj
index 7da895f..96b11f8 100644
--- a/msc-plugin/libaquery.vcxproj
+++ b/msc-plugin/libaquery.vcxproj
@@ -100,6 +100,8 @@
pch.hpp
$(ProjectDir)\..\monetdb\msvc
../libaquery.pch
+ true
+ true
Console
@@ -161,6 +163,8 @@
pch.hpp
$(ProjectDir)\..\monetdb\msvc
../libaquery.pch
+ true
+ true
Console
diff --git a/msc-plugin/msc-plugin.vcxproj b/msc-plugin/msc-plugin.vcxproj
index c187361..e0765b4 100644
--- a/msc-plugin/msc-plugin.vcxproj
+++ b/msc-plugin/msc-plugin.vcxproj
@@ -108,6 +108,7 @@
./server/pch.hpp
../libaquery.pch
true
+ true
Console
@@ -178,6 +179,7 @@
./server/pch.hpp
../libaquery.pch
true
+ true
Console
diff --git a/msc-plugin/sdk_example.vcxproj b/msc-plugin/sdk_example.vcxproj
index 09ddc80..f55e7a9 100644
--- a/msc-plugin/sdk_example.vcxproj
+++ b/msc-plugin/sdk_example.vcxproj
@@ -98,6 +98,8 @@
true
stdcpplatest
stdc17
+ true
+ true
Console
@@ -130,6 +132,8 @@
true
stdcpplatest
stdc17
+ true
+ true
Console
diff --git a/sdk/aquery.h b/sdk/aquery.h
index 3ef5bb6..fbe6517 100644
--- a/sdk/aquery.h
+++ b/sdk/aquery.h
@@ -75,7 +75,13 @@ extern void register_memory(void* ptr, deallocator_t deallocator);
__AQEXPORT__(void) init_session(Context* cxt);
#define __AQ_NO_SESSION__ __AQEXPORT__(void) init_session(Context*) {}
+
+#ifdef _MSC_VER
+void* _cdecl memcpy(void*, void*, size_t);
+#else
void* memcpy(void*, const void*, unsigned long long);
+#endif
+
struct ColRef_storage {
void* container;
unsigned int capacity, size;
diff --git a/server/aggregations.h b/server/aggregations.h
index 514e4a6..583f246 100644
--- a/server/aggregations.h
+++ b/server/aggregations.h
@@ -16,7 +16,7 @@ constexpr static inline size_t count(const T&) { return 1; }
// TODO: Specializations for dt/str/none
template class VT>
-types::GetLongType
+types::GetLongType
sum(const VT& v) {
types::GetLongType ret = 0;
for (const auto& _v : v)
@@ -31,8 +31,8 @@ double avg(const VT& v) {
template class VT>
VT sqrt(const VT& v) {
- VT ret {v.size};
- for (uint32_t i = 0; i < v.size; ++i){
+ VT ret{ v.size };
+ for (uint32_t i = 0; i < v.size; ++i) {
ret[i] = sqrt(v[i]);
}
return ret;
@@ -53,10 +53,10 @@ T min(const VT& v) {
return min_v;
}
template class VT>
-decayed_t mins(const VT& arr) {
+decayed_t mins(const VT& arr) {
const uint32_t& len = arr.size;
std::deque> cache;
- decayed_t ret(len);
+ decayed_t ret(len);
T min = std::numeric_limits::max();
for (int i = 0; i < len; ++i) {
if (arr[i] < min)
@@ -66,9 +66,9 @@ decayed_t mins(const VT& arr) {
return ret;
}
template class VT>
-decayed_t maxs(const VT& arr) {
+decayed_t maxs(const VT& arr) {
const uint32_t& len = arr.size;
- decayed_t ret(len);
+ decayed_t ret(len);
T max = std::numeric_limits::min();
for (int i = 0; i < len; ++i) {
if (arr[i] > max)
@@ -79,9 +79,9 @@ decayed_t maxs(const VT& arr) {
}
template class VT>
-decayed_t minw(uint32_t w, const VT& arr) {
+decayed_t minw(uint32_t w, const VT& arr) {
const uint32_t& len = arr.size;
- decayed_t ret{len};
+ decayed_t ret{ len };
std::deque> cache;
for (int i = 0; i < len; ++i) {
if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
@@ -93,7 +93,7 @@ decayed_t minw(uint32_t w, const VT& arr) {
}
template class VT>
-decayed_t maxw(uint32_t w, const VT& arr) {
+decayed_t maxw(uint32_t w, const VT& arr) {
const uint32_t& len = arr.size;
decayed_t ret(len);
std::deque> cache;
@@ -106,14 +106,27 @@ decayed_t maxw(uint32_t w, const VT& arr) {
return ret;
}
+template class VT>
+decayed_t> ratios(const VT& arr) {
+ uint32_t len = arr.size - 1;
+ if (!arr.size)
+ len = 1;
+ decayed_t> ret(len);
+ ret[0] = 0;
+
+ for (uint32_t i = 1; i < arr.size; ++i)
+ ret[i - 1] = arr[i] / arr[i - 1];
+ return ret;
+}
+
template class VT>
decayed_t> sums(const VT& arr) {
const uint32_t& len = arr.size;
decayed_t> ret(len);
uint32_t i = 0;
- if(len) ret[i++] = arr[0];
- for (; i < len; ++i)
- ret[i] = ret[i-1] + arr[i];
+ if (len) ret[i++] = arr[0];
+ for (; i < len; ++i)
+ ret[i] = ret[i - 1] + arr[i];
return ret;
}
template class VT>
@@ -123,9 +136,9 @@ decayed_t>> avgs(const VT& arr) {
decayed_t ret(len);
uint32_t i = 0;
types::GetLongType s;
- if(len) s = ret[i++] = arr[0];
- for (; i < len; ++i)
- ret[i] = (s+=arr[i])/(FPType)(i+1);
+ if (len) s = ret[i++] = arr[0];
+ for (; i < len; ++i)
+ ret[i] = (s += arr[i]) / (FPType)(i + 1);
return ret;
}
template class VT>
@@ -134,11 +147,11 @@ decayed_t> sumw(uint32_t w, const VT& arr) {
decayed_t> ret(len);
uint32_t i = 0;
w = w > len ? len : w;
- if(len) 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];
+ if (len) 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 VT>
@@ -149,11 +162,11 @@ decayed_t>> avgw(uint32_t w, const VT
uint32_t i = 0;
types::GetLongType s{};
w = w > len ? len : w;
- if(len) 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;
+ if (len) 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;
}
@@ -163,18 +176,29 @@ decayed_t deltas(const VT& arr) {
const uint32_t& len = arr.size;
decayed_t ret(len);
uint32_t i = 0;
- if(len) ret[i++] = 0;
- for (; i < len; ++i)
- ret[i] = arr[i] - arr[i-1];
+ if (len) ret[i++] = 0;
+ for (; i < len; ++i)
+ ret[i] = arr[i] - arr[i - 1];
return ret;
}
template class VT>
T last(const VT& arr) {
+ if (!arr.size) return 0;
const uint32_t& len = arr.size;
return arr[arr.size - 1];
}
+template class VT>
+T first(const VT& arr) {
+ if (!arr.size) return 0;
+ const uint32_t& len = arr.size;
+ return arr[0];
+}
+
+#define __DEFAULT_AGGREGATE_FUNCTION__(NAME, RET) \
+template constexpr inline T NAME(const T& v) { return RET; }
+
// wrong behavior with count(0)
template constexpr inline T count(const T& v) { return 1; }
template constexpr inline T max(const T& v) { return v; }
@@ -191,3 +215,4 @@ template constexpr inline T avgs(const T& v) { return v; }
template constexpr inline T sums(const T& v) { return v; }
template constexpr inline T last(const T& v) { return v; }
template constexpr inline T daltas(const T& v) { return 0; }
+template constexpr inline T ratios(const T& v) { return 1; }
diff --git a/server/server.cpp b/server/server.cpp
index c92d25a..b10ca80 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -320,35 +320,44 @@ int test_main()
Server* server = reinterpret_cast(cxt->alt_server);
const char* qs[]= {
- "CREATE TABLE test1(a INT, b INT, c INT, d INT);",
- "COPY OFFSET 2 INTO test1 FROM 'w:/gg/AQuery++/data/test.csv' ON SERVER USING DELIMITERS ',';",
- "SELECT sum(a), b, d, c FROM test1 GROUP BY c, b, d ORDER BY b ;",
+ "QCREATE TABLE trade(stocksymbol INT, time INT, quantity INT, price INT);",
+ "QCOPY OFFSET 2 INTO trade FROM 'w:/gg/AQuery++/data/trade_numerical.csv' ON SERVER USING DELIMITERS ',';",
+ "QSELECT stocksymbol, (SUM((quantity * price)) / SUM(quantity)) AS weighted_average FROM trade GROUP BY stocksymbol ;",
+ "Pdll_5lYrMY",
+ "QSELECT stocksymbol, price FROM trade ORDER BY time ;",
+ "Pdll_4Sg6Ri",
+ "QSELECT stocksymbol, quantity, price FROM trade ORDER BY time ;",
+ "Pdll_5h4kL2",
+ "QSELECT stocksymbol, price FROM trade ORDER BY time ;",
+ "Pdll_7tEWCO",
+ "QSELECT query_c.weighted_moving_averages, query_c.stocksymbol FROM query_c;",
+ "Pdll_7FCPnF"
};
n_recv = sizeof(qs)/(sizeof (char*));
n_recvd = const_cast(qs);
- if (n_recv > 0) {
- for (int i = 0; i < n_recv; ++i)
- {
- server->exec(n_recvd[i]);
- printf("Exec Q%d: %s\n", i, n_recvd[i]);
- }
- n_recv = 0;
- }
+ void* handle = 0;
+ handle = dlopen("./dll.so", RTLD_LAZY);
+ cxt->init_session();
+ for (int i = 0; i < n_recv; ++i)
+ {
+ //printf("%s, %d\n", n_recvd[i], n_recvd[i][0] == 'Q');
+ switch (n_recvd[i][0]) {
+ case 'Q': // SQL query for monetdbe
+ {
+ server->exec(n_recvd[i] + 1);
+ printf("Exec Q%d: %s\n", i, n_recvd[i]);
+ }
+ break;
+ case 'P': // Postprocessing procedure
+ if (handle && !server->haserror()) {
+ code_snippet c = reinterpret_cast(dlsym(handle, n_recvd[i] + 1));
+ c(cxt);
+ }
+ break;
+ }
+ }
+ n_recv = 0;
- cxt->log_level = LOG_INFO;
- puts(cpp_17 ?"true":"false");
- void* handle = dlopen("./dll.so", RTLD_LAZY);
- cxt->log("handle: %p\n", handle);
- if (handle) {
- cxt->log("inner\n");
- code_snippet c = reinterpret_cast(dlsym(handle, "dll_C4nJZu"));
- cxt->log("routine: %p\n", c);
- if (c) {
- cxt->log("inner\n");
- cxt->log("return: %d\n", c(cxt));
- }
- dlclose(handle);
- }
//static_assert(std::is_same_v()), std::integer_sequence>, "");
return 0;
diff --git a/server/table.h b/server/table.h
index 1e07968..76f5fb0 100644
--- a/server/table.h
+++ b/server/table.h
@@ -34,13 +34,13 @@ std::ostream& operator<<(std::ostream& os, const VT& v)
}
#ifdef __AQ__HAS__INT128__
-std::ostream& operator<<(std::ostream& os, __int128 & v);
-std::ostream& operator<<(std::ostream& os, __uint128_t & v);
+std::ostream& operator<<(std::ostream& os, __int128& v);
+std::ostream& operator<<(std::ostream& os, __uint128_t& v);
#endif
-std::ostream& operator<<(std::ostream& os, types::date_t & v);
-std::ostream& operator<<(std::ostream& os, types::time_t & v);
-std::ostream& operator<<(std::ostream& os, types::timestamp_t & v);
+std::ostream& operator<<(std::ostream& os, types::date_t& v);
+std::ostream& operator<<(std::ostream& os, types::time_t& v);
+std::ostream& operator<<(std::ostream& os, types::timestamp_t& v);
template
class ColView;
template
@@ -50,27 +50,27 @@ public:
typedef ColRef<_Ty> Decayed_t;
const char* name;
types::Type_t ty = types::Type_t::ERROR;
- ColRef(const ColRef<_Ty>& vt) : vector_type<_Ty>(vt) {}
+ ColRef(const ColRef<_Ty>& vt) : vector_type<_Ty>(vt) {}
ColRef(ColRef<_Ty>&& vt) : vector_type<_Ty>(std::move(vt)) {}
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) {}
ColRef(const uint32_t size, void* data, const char* name = "") : vector_type<_Ty>(size, data), name(name) {}
void init(const char* name = "") { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; this->name = name; }
- void initfrom(uint32_t sz, void*container, const char* name = "") {
- ty = types::Types<_Ty>::getType();
+ void initfrom(uint32_t sz, void* container, const char* name = "") {
+ ty = types::Types<_Ty>::getType();
this->size = sz;
this->capacity = 0;
- this->container = (_Ty*)container;
- this->name = name;
+ this->container = (_Ty*)container;
+ this->name = name;
}
template class VT, typename T>
- void initfrom(const VT& v, const char* name = ""){
- ty = types::Types<_Ty>::getType();
+ void initfrom(const VT& v, const char* name = "") {
+ ty = types::Types<_Ty>::getType();
this->size = v.size;
this->capacity = 0;
- this->container = (_Ty*)(v.container);
- this->name = name;
+ this->container = (_Ty*)(v.container);
+ this->name = name;
}
template
ColRef<_Ty>& operator =(ColRef&& vt) {
@@ -86,7 +86,7 @@ public:
using vector_type<_Ty>::subvec;
using vector_type<_Ty>::subvec_memcpy;
using vector_type<_Ty>::subvec_deep;
- ColRef<_Ty>& operator= (const _Ty& vt){
+ ColRef<_Ty>& operator= (const _Ty& vt) {
vector_type<_Ty>::operator=(vt);
return *this;
}
@@ -98,7 +98,7 @@ public:
vector_type<_Ty>::operator=(std::move(vt));
return *this;
}
- ColView<_Ty> operator [](const vector_type&idxs) const {
+ ColView<_Ty> operator [](const vector_type& idxs) const {
return ColView<_Ty>(*this, idxs);
}
@@ -117,12 +117,12 @@ public:
std::cout << this->operator[](i) << sep;
std::cout << this->operator[](i);
}
- std::cout<< more;
+ std::cout << more;
std::cout << ')';
}
template
ColRef scast();
-
+
ColRef<_Ty>* rename(const char* name) {
this->name = name;
return this;
@@ -130,14 +130,14 @@ public:
// defined in table_ext_monetdb.hpp
void* monetdb_get_col();
-
+
};
template<>
-class ColRef : public ColRef{};
+class ColRef : public ColRef {};
template
class ColView {
-public:
+public:
typedef ColRef<_Ty> Decayed_t;
const uint32_t size;
const ColRef<_Ty> orig;
@@ -145,7 +145,7 @@ public:
ColView(const ColRef<_Ty>& orig, vector_type&& idxs) : orig(orig), size(idxs.size), idxs(std::move(idxs)) {}
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)
+ for (uint32_t i = 0; i < size; ++i)
idxs[i] = orig.idxs[idxs[i]];
}
_Ty& operator [](const uint32_t& i) const {
@@ -177,9 +177,9 @@ public:
}
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 << '(';
+ for (uint32_t i = 0; i < n; ++i)
+ std::cout << this->operator[](i) << sep;
std::cout << ')';
}
operator ColRef<_Ty>() {
@@ -192,7 +192,7 @@ public:
uint32_t len = end - start;
return ColView<_Ty>(orig, idxs.subvec(start, end));
}
- ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) const{
+ ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) const {
uint32_t len = end - start;
ColRef<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
@@ -202,10 +202,10 @@ public:
std::unordered_set<_Ty> distinct_common() {
return std::unordered_set<_Ty> {begin(), end()};
}
- uint32_t distinct_size(){
+ uint32_t distinct_size() {
return distinct_common().size();
}
- ColRef<_Ty> distinct(){
+ ColRef<_Ty> distinct() {
auto set = distinct_common();
ColRef<_Ty> ret(set.size());
uint32_t i = 0;
@@ -235,8 +235,8 @@ template
constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept {
if constexpr (order)
return *(ColRef>> *) & (table.colrefs[_Index]);
- else
- return *(ColRef>> *) & (table.colrefs[-1-_Index]);
+ else
+ return *(ColRef>> *) & (table.colrefs[-1 - _Index]);
}
template
@@ -267,7 +267,7 @@ struct TableInfo {
TableInfo* this_table;
TableInfo* table;
vector_type rid;
- constexpr lineage_t(TableInfo*this_table, TableInfo *table)
+ constexpr lineage_t(TableInfo* this_table, TableInfo* table)
: this_table(this_table), table(table), rid(0) {}
constexpr lineage_t() : this_table(0), table(0), rid(0) {}
@@ -279,12 +279,12 @@ struct TableInfo {
rid.emplace_back(v);
}
};
-
+
template
auto bind(TableInfo* table2) {
return lineage_t(this, table2);
}
-
+
template
auto& get_col() {
return *reinterpret_cast>*>(colrefs + i);
@@ -293,30 +293,30 @@ struct TableInfo {
template
typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
template
- typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
+ typename std::enable_if < j < sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
template
struct GetTypes {
typedef typename std::tuple::type ...> type;
};
-
+
template
using getRecordType = typename GetTypes::type;
TableInfo(const char* name, uint32_t n_cols);
- TableInfo(const char* name = "", const char **col_names = nullptr);
+ TableInfo(const char* name = "", const char** col_names = nullptr);
template
inline void materialize(const vector_type& idxs, TableInfo* tbl = nullptr) { // inplace materialize
- if constexpr(prog == 0) tbl = (tbl == 0 ? this : tbl);
+ if constexpr (prog == 0) tbl = (tbl == 0 ? this : tbl);
if constexpr (prog == sizeof...(Types)) return;
else {
auto& col = get(*this);
- auto new_col = decays{idxs.size};
- for(uint32_t i = 0; i < idxs.size; ++i)
+ auto new_col = decays{ idxs.size };
+ for (uint32_t i = 0; i < idxs.size; ++i)
new_col[i] = col[idxs[i]];
get(*tbl) = new_col;
materialize(idxs, tbl);
}
}
- inline TableInfo* materialize_copy(const vector_type& idxs) {
+ inline TableInfo* materialize_copy(const vector_type& idxs) {
auto tbl = new TableInfo(this->name, sizeof...(Types));
materialize<0>(idxs, tbl);
return tbl;
@@ -337,16 +337,16 @@ struct TableInfo {
return ord;
}
template
- auto order_by_view () {
+ auto order_by_view() {
return TableView(order_by(), *this);
}
// Print 2 -- generate printf string first, supports flattening, supports sprintf/printf/fprintf
- template
+ template
inline void print2_impl(Fn func, const uint32_t& i, const __Types& ... args) const {
using this_type = typename std::tuple_element::type;
const auto& this_value = get(*this)[i];
- const auto& next = [&](auto &v) {
+ const auto& next = [&](auto& v) {
if constexpr (sizeof...(rem_cols) == 0)
func(args..., print_hook(v));
else
@@ -358,7 +358,7 @@ struct TableInfo {
else
next(this_value);
}
- std::string get_header_string(const char* __restrict sep, const char* __restrict end) const{
+ std::string get_header_string(const char* __restrict sep, const char* __restrict end) const {
std::string header_string = std::string();
for (uint32_t i = 0; i < sizeof...(Types); ++i)
header_string += std::string(this->colrefs[i].name) + sep + '|' + sep;
@@ -371,17 +371,17 @@ struct TableInfo {
template
void print2(const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr) const {
-
+
std::string printf_string =
generate_printf_string::type ...>(sep, end);
std::string header_string = std::string();
constexpr static int a_cols[] = { cols... };
- for(int i = 0; i < sizeof...(cols); ++i)
+ for (int i = 0; i < sizeof...(cols); ++i)
header_string += std::string(this->colrefs[a_cols[i]].name) + sep;
const size_t l_sep = strlen(sep);
- if(header_string.size() - l_sep >= 0)
+ if (header_string.size() - l_sep >= 0)
header_string.resize(header_string.size() - l_sep);
-
+
const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
#ifdef __AQ__HAS__INT128__
constexpr auto num_hge = count_type<__int128_t, __uint128_t>((tuple_type*)(0));
@@ -391,20 +391,21 @@ struct TableInfo {
constexpr auto num_date = count_type((tuple_type*)(0));
constexpr auto num_time = count_type((tuple_type*)(0));
constexpr auto num_timestamp = count_type((tuple_type*)(0));
- char cbuf[ num_hge * 41
- + num_time * types::time_t::string_length()
- + num_date * types::date_t::string_length()
- + num_timestamp * types::timestamp_t::string_length()
+ char cbuf[num_hge * 41
+ + num_time * types::time_t::string_length()
+ + num_date * types::date_t::string_length()
+ + num_timestamp * types::timestamp_t::string_length()
+ + 1
];
setgbuf(cbuf);
- if(view)
- for (uint32_t i = 0; i < view->size; ++i){
+ if (view)
+ for (uint32_t i = 0; i < view->size; ++i) {
print2_impl(f, (*view)[i], printf_string.c_str());
setgbuf();
}
else
- for (uint32_t i = 0; i < colrefs[0].size; ++i){
- print2_impl(f, i, printf_string.c_str());
+ for (uint32_t i = 0; i < colrefs[0].size; ++i) {
+ print2_impl(f, i, printf_string.c_str());
setgbuf();
}
};
@@ -420,10 +421,13 @@ struct TableInfo {
}
}
template struct applier {
- inline constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
- const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr)
- { t.template print2(sep, end, view, fp); }};
-
+ inline constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
+ const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr)
+ {
+ t.template print2(sep, end, view, fp);
+ }
+ };
+
inline void printall(const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr) {
applyIntegerSequence::apply(*this, sep, end, view, fp);
@@ -433,33 +437,33 @@ struct TableInfo {
this->name = name;
return this;
}
- template
+ template
void inline
- reserve(std::index_sequence, uint32_t size) {
- const auto& assign_sz = [&size](auto& col){
+ reserve(std::index_sequence, uint32_t size) {
+ const auto& assign_sz = [&size](auto& col) {
col.size = size;
col.grow();
};
(assign_sz(get_col()), ...);
}
- template
- decltype(auto) inline
- get_record(std::index_sequence, uint32_t i) {
+ template
+ decltype(auto) inline
+ get_record(std::index_sequence, uint32_t i) {
return std::forward_as_tuple(get_col()[i] ...);
}
- template
- void inline
- set_record(std::index_sequence, const tuple_type& t, uint32_t i) {
- const auto& assign_field =
- [](auto& l, const auto& r){
- l = r;
- };
+ template
+ void inline
+ set_record(std::index_sequence, const tuple_type& t, uint32_t i) {
+ const auto& assign_field =
+ [](auto& l, const auto& r) {
+ l = r;
+ };
(assign_field(get_col()[i], std::get(t)), ...);
}
TableInfo* distinct() {
std::unordered_set d_records;
std::make_index_sequence seq;
-
+
for (uint32_t j = 0; j < colrefs[0].size; ++j) {
d_records.insert(get_record(seq, j));
}
@@ -486,20 +490,20 @@ struct TableView {
typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
template
typename std::enable_if < j < sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
-
- template
- decltype(auto) inline
- get_record(std::index_sequence, uint32_t i) {
+
+ template
+ decltype(auto) inline
+ get_record(std::index_sequence, uint32_t i) {
return std::forward_as_tuple(info.template get_col()[idxs[i]] ...);
}
-
+
TableInfo* get_tableinfo(const char* name = nullptr, const char** names = nullptr) {
- if (name == nullptr)
+ if (name == nullptr)
name = info.name;
const char* info_names[sizeof...(Types)];
if (name == nullptr) {
- for(uint32_t i = 0; i < sizeof...(Types); ++i)
+ for (uint32_t i = 0; i < sizeof...(Types); ++i)
info_names[i] = info.colrefs[i].name;
names = info_names;
}
@@ -520,7 +524,7 @@ struct TableView {
TableInfo* distinct(const char* name = nullptr, const char** names = nullptr) {
std::unordered_set d_records;
std::make_index_sequence seq;
-
+
for (uint32_t j = 0; j < idxs->size; ++j) {
d_records.insert(get_record(seq, j));
}
@@ -559,7 +563,7 @@ template
TableInfo::TableInfo(const char* name, const char** col_names) : name(name), n_cols(sizeof...(Types)) {
this->colrefs = (ColRef*)malloc(sizeof(ColRef) * this->n_cols);
for (uint32_t i = 0; i < n_cols; ++i) {
- this->colrefs[i].init(col_names? col_names[i] : "");
+ this->colrefs[i].init(col_names ? col_names[i] : "");
}
}
template
@@ -582,7 +586,7 @@ template
inline void TableView::print(const char* __restrict sep, const char* __restrict end) const {
std::string header_string = info.get_header_string(sep, end);
std::cout << header_string.c_str();
-
+
uint32_t n_rows = 0;
if (info.colrefs[0].size > 0)
n_rows = info.colrefs[0].size;
@@ -594,25 +598,25 @@ inline void TableView::print(const char* __restrict sep, const char* _
template
template
inline typename std::enable_if::type
- TableInfo::print_impl(const uint32_t& i, const char* __restrict sep) const {
+TableInfo::print_impl(const uint32_t& i, const char* __restrict sep) const {
std::cout << (get(*this))[i];
}
template
template
-inline typename std::enable_if::type
+inline typename std::enable_if < j < sizeof...(Types) - 1, void>::type
TableInfo::print_impl(const uint32_t& i, const char* __restrict sep) const
{
std::cout << (get(*this))[i] << sep;
- print_impl(i, sep);
+ print_impl(i, sep);
}
template
inline void TableInfo::print(const char* __restrict sep, const char* __restrict end) const {
-
+
std::string header_string = get_header_string(sep, end);
std::cout << header_string.c_str();
-
+
uint32_t n_rows = 0;
if (n_cols > 0 && colrefs[0].size > 0)
n_rows = colrefs[0].size;
@@ -740,7 +744,7 @@ void print(const TableView& v, const char* delimiter = " ", const char
}
template
void print(const T& v, const char* delimiter = " ") {
- std::cout<< v<< delimiter;
+ std::cout << v << delimiter;
// printf(types::printf_str[types::Types::getType()], v);
}
@@ -748,10 +752,10 @@ void print(const T& v, const char* delimiter = " ") {
template <>
void print<__int128_t>(const __int128_t& v, const char* delimiter);
template <>
-void print<__uint128_t>(const __uint128_t&v, const char* delimiter);
+void print<__uint128_t>(const __uint128_t& v, const char* delimiter);
#endif
template <>
-void print(const bool&v, const char* delimiter);
+void print(const bool& v, const char* delimiter);
template
void inline print_impl(const T& v, const char* delimiter, const char* endline) {
@@ -765,10 +769,10 @@ void inline print_impl(const T& v, const char* delimiter, const char* endline) {
}
template class VT>
-typename std::enable_if, TableInfo>::value>::type
+typename std::enable_if, TableInfo>::value>::type
print(const VT& v, const char* delimiter = " ", const char* endline = "\n") {
print_impl(v, delimiter, endline);
}
-
+
#endif
diff --git a/server/types.h b/server/types.h
index d4a5656..8aa13ca 100644
--- a/server/types.h
+++ b/server/types.h
@@ -29,22 +29,22 @@ namespace types {
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%d", "%hi", "%s", "%s", "%c",
"%u", "%lu", "%s", "%hu", "%hhu", "%s", "%s", "Vector<%s>", "%s", "NULL", "ERROR" };
static constexpr const char* SQL_Type[] = { "INT", "REAL", "TEXT", "DOUBLE", "DOUBLE", "BIGINT", "HUGEINT", "SMALLINT", "DATE", "TIME", "TINYINT",
- "INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BIGINT", "BOOL", "BIGINT", "TIMESTAMP", "NULL", "ERROR"};
-
-
+ "INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BOOL", "BLOB", "TIMESTAMP", "NULL", "ERROR" };
+
+
// TODO: deal with data/time <=> str/uint conversion
- struct date_t{
+ struct date_t {
unsigned char day = 0;
unsigned char month = 0;
short year = 0;
date_t() = default;
- date_t(unsigned char day, unsigned char month, short year) :
- day (day), month (month), year(year) {}
+ date_t(unsigned char day, unsigned char month, short year) :
+ day(day), month(month), year(year) {}
date_t(const char*);
date_t& fromString(const char*);
bool validate() const;
- constexpr static unsigned string_length(){
+ constexpr static unsigned string_length() {
return 11;
};
char* toString(char* buf) const;
@@ -56,16 +56,16 @@ namespace types {
bool operator != (const date_t&) const;
};
- struct time_t{
+ struct time_t {
unsigned int ms = 0;
unsigned char seconds = 0;
unsigned char minutes = 0;
unsigned char hours = 0;
- time_t() = default;
- time_t(unsigned int ms, unsigned char seconds, unsigned char minutes, unsigned char hours) :
- ms (ms), seconds (seconds), minutes(minutes), hours(hours) {};
- time_t(const char*);
+ time_t() = default;
+ time_t(unsigned int ms, unsigned char seconds, unsigned char minutes, unsigned char hours) :
+ ms(ms), seconds(seconds), minutes(minutes), hours(hours) {};
+ time_t(const char*);
time_t& fromString(const char*);
bool validate() const;
constexpr static unsigned string_length() {
@@ -79,15 +79,15 @@ namespace types {
bool operator == (const time_t&) const;
bool operator != (const time_t&) const;
};
- struct timestamp_t{
+ struct timestamp_t {
date_t date;
time_t time;
timestamp_t() = default;
timestamp_t(const date_t& d, const time_t& t) : date(d), time(t) {}
- timestamp_t(const char*);
+ timestamp_t(const char*);
timestamp_t& fromString(const char*);
bool validate() const;
- constexpr static unsigned string_length(){
+ constexpr static unsigned string_length() {
return date_t::string_length() + time_t::string_length();
};
char* toString(char* buf) const;
@@ -135,10 +135,10 @@ namespace types {
inline constexpr static Type_t getType() {
#define TypeConnect(x, y) if constexpr(std::is_same::value) return y; else
ConnectTypes(TypeConnect)
- if constexpr (is_vector_type)
- return VECTOR;
- else
- return NONE;
+ if constexpr (is_vector_type)
+ return VECTOR;
+ else
+ return NONE;
}
};
#define ATypeSize(t, at) sizeof(t),
@@ -167,17 +167,51 @@ namespace types {
};
template
using GetLongType = typename GetLongTypeImpl::type>::type;
+
+
+ template
+ struct GetLongerTypeImpl {
+ using type = Cond(
+
+ __U(T), Cond(__Eq(char), unsigned short,
+ Cond(__Eq(short), unsigned int,
+ Cond(__Eq(int), unsigned long long,
+ ULL_Type
+ ))),
+
+ Cond(Fp(T), double,
+
+ Cond(__Eq(char), short,
+ Cond(__Eq(short), int,
+ Cond(__Eq(int), long,
+ LL_Type
+ ))))
+
+ );
+ };
+ template
+ using GetLongerType = typename GetLongerTypeImpl::type>::type;
}
+
struct astring_view {
const unsigned char* str = 0;
- constexpr astring_view(const char* str) :
+
+#if defined(__clang__) || !defined(__GNUC__)
+ constexpr
+#endif
+ astring_view(const char* str) noexcept :
str((const unsigned char*)(str)) {}
- constexpr astring_view(const signed char* str) :
+#if defined(__clang__) || !defined(__GNUC__)
+ constexpr
+#endif
+ astring_view(const signed char* str) noexcept :
str((const unsigned char*)(str)) {}
- constexpr astring_view(const unsigned char* str) :
+
+ constexpr
+ astring_view(const unsigned char* str) noexcept :
str(str) {}
- constexpr astring_view() = default;
+ constexpr astring_view() noexcept = default;
bool operator==(const astring_view& r) const {
auto this_str = str;
@@ -190,8 +224,8 @@ struct astring_view {
}
return !(*this_str || *other_str);
}
- bool operator >(const astring_view&r) const{
-
+ bool operator >(const astring_view& r) const {
+
}
operator const char* () const {
return reinterpret_cast(str);
@@ -200,7 +234,7 @@ struct astring_view {
return reinterpret_cast(str);
}
operator const signed char* () const {
- return reinterpret_cast(str);
+ return reinterpret_cast(str);
}
};
@@ -245,7 +279,7 @@ struct decayS {
using type = typename std::decay::type;
};
template class T, typename ...Types>
-struct decayS >{
+struct decayS > {
using type = T::type ...>;
};
template
@@ -284,7 +318,7 @@ using transValues = typename transValues_s