diff --git a/msc-plugin/msc-plugin.vcxproj b/msc-plugin/msc-plugin.vcxproj index ac70b3a..c187361 100644 --- a/msc-plugin/msc-plugin.vcxproj +++ b/msc-plugin/msc-plugin.vcxproj @@ -230,6 +230,9 @@ + + + diff --git a/server/hasher.h b/server/hasher.h index 2bfe3d1..526c168 100644 --- a/server/hasher.h +++ b/server/hasher.h @@ -17,19 +17,46 @@ inline size_t append_bytes(const unsigned char* _First) noexcept { return _Val; } +inline size_t append_bytes(const astring_view& view) noexcept { + return append_bytes(view.str); +} + + +template +struct hasher { + template typename std::enable_if< i == sizeof...(Types), + size_t>::type hashi(const std::tuple&) const { + return 534235245539ULL; + } + + template typename std::enable_if < i < sizeof ...(Types), + size_t>::type hashi(const std::tuple& record) const { + using current_type = typename std::decay>::type>::type; + + return std::hash()(std::get(record)) ^ hashi(record); + } + size_t operator()(const std::tuple& record) const { + return hashi(record); + } +}; + + namespace std{ + template<> struct hash { size_t operator()(const astring_view& _Keyval) const noexcept { return append_bytes(_Keyval.str); } }; + template<> struct hash { size_t operator() (const types::date_t& _Keyval) const noexcept { return std::hash()(*(unsigned int*)(&_Keyval)); } }; + template<> struct hash { size_t operator() (const types::time_t& _Keyval) const noexcept { @@ -40,6 +67,7 @@ namespace std{ ; } }; + template<> struct hash{ size_t operator() (const types::timestamp_t& _Keyval) const noexcept { @@ -48,27 +76,8 @@ namespace std{ } }; -} + template + struct hash> : public hasher{ }; -inline size_t append_bytes(const astring_view& view) noexcept { - return append_bytes(view.str); } - -template -struct hasher { - template typename std::enable_if< i == sizeof...(Types), - size_t>::type hashi(const std::tuple&) const { - return 534235245539ULL; - } - - template typename std::enable_if< i < sizeof ...(Types), - size_t>::type hashi(const std::tuple& record) const { - using current_type = typename std::decay>::type>::type; - - return std::hash()(std::get(record)) ^ hashi(record); - } - size_t operator()(const std::tuple& record) const { - return hashi(record); - } -}; diff --git a/server/server.cpp b/server/server.cpp index 5fec1d8..dd63e3e 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -333,9 +333,9 @@ int test_main() //printf("sibal: %p %p\n", aa, bb); const char* qs[]= { - "CREATE TABLE network(src VARCHAR(3), dst VARCHAR(3), len INT, _time INT);", - "COPY OFFSET 2 INTO network FROM 'c:/Users/sunyi/Desktop/AQuery2/data/network.csv' ON SERVER USING DELIMITERS ',';", - "SELECT src, dst, len, _time FROM network ORDER BY src, dst, _time", + "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 ;", }; n_recv = sizeof(qs)/(sizeof (char*)); n_recvd = const_cast(qs); @@ -354,7 +354,7 @@ int test_main() cxt->log("handle: %p\n", handle); if (handle) { cxt->log("inner\n"); - code_snippet c = reinterpret_cast(dlsym(handle, "dll_54aqwy")); + code_snippet c = reinterpret_cast(dlsym(handle, "dll_C4nJZu")); cxt->log("routine: %p\n", c); if (c) { cxt->log("inner\n"); diff --git a/server/table.h b/server/table.h index f96c0e6..eab5f9d 100644 --- a/server/table.h +++ b/server/table.h @@ -9,6 +9,8 @@ #include #include #include "io.h" +#include "hasher.h" + #undef ERROR template class vector_type; @@ -432,21 +434,21 @@ struct TableInfo { void inline reserve(std::index_sequence, uint32_t size) { const auto& assign_sz = [&size](auto& col){ col.size = size;}; - (assign_sz(get_col(*this)), ...); + (assign_sz(get_col()), ...); } template decltype(auto) inline get_record(std::index_sequence, uint32_t i) { - return std::forward_as_tuple((get_col(*this)[i], ...)); + return std::forward_as_tuple(get_col()[i] ...); } template void inline - set_record(std::index_sequence, tuple_type t) { + 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(*this)[Is], std::get(t)), ...); + (assign_field(get_col()[i], std::get(t)), ...); } TableInfo* distinct() { std::unordered_set d_records; @@ -456,8 +458,9 @@ struct TableInfo { d_records.insert(get_record(seq, j)); } reserve(seq, d_records.size()); + uint32_t i = 0; for (const auto& dr : d_records) { - set_record(seq, dr); + set_record(seq, dr, i++); } return this; }