Bill 2 years ago
commit 48beab441d

@ -230,6 +230,9 @@
<ItemGroup>
<ClCompile Include="..\out.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\udf.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

@ -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 <class ...Types>
struct hasher {
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
size_t>::type hashi(const std::tuple<Types...>&) const {
return 534235245539ULL;
}
template <size_t i = 0> typename std::enable_if < i < sizeof ...(Types),
size_t>::type hashi(const std::tuple<Types...>& record) const {
using current_type = typename std::decay<typename std::tuple_element<i, std::tuple<Types...>>::type>::type;
return std::hash<current_type>()(std::get<i>(record)) ^ hashi<i + 1>(record);
}
size_t operator()(const std::tuple<Types...>& record) const {
return hashi(record);
}
};
namespace std{
template<>
struct hash<astring_view> {
size_t operator()(const astring_view& _Keyval) const noexcept {
return append_bytes(_Keyval.str);
}
};
template<>
struct hash<types::date_t> {
size_t operator() (const types::date_t& _Keyval) const noexcept {
return std::hash<unsigned int>()(*(unsigned int*)(&_Keyval));
}
};
template<>
struct hash<types::time_t> {
size_t operator() (const types::time_t& _Keyval) const noexcept {
@ -40,6 +67,7 @@ namespace std{
;
}
};
template<>
struct hash<types::timestamp_t>{
size_t operator() (const types::timestamp_t& _Keyval) const noexcept {
@ -48,27 +76,8 @@ namespace std{
}
};
}
inline size_t append_bytes(const astring_view& view) noexcept {
return append_bytes(view.str);
}
template <class ...Types>
struct hasher {
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
size_t>::type hashi(const std::tuple<Types...>&) const {
return 534235245539ULL;
}
template <size_t i = 0> typename std::enable_if< i < sizeof ...(Types),
size_t>::type hashi(const std::tuple<Types...>& record) const {
using current_type = typename std::decay<typename std::tuple_element<i, std::tuple<Types...>>::type>::type;
struct hash<std::tuple<Types...>> : public hasher<Types...>{ };
return std::hash<current_type>()(std::get<i>(record)) ^ hashi<i+1>(record);
}
size_t operator()(const std::tuple<Types...>& record) const {
return hashi(record);
}
};

@ -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<char**>(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<code_snippet>(dlsym(handle, "dll_54aqwy"));
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dll_C4nJZu"));
cxt->log("routine: %p\n", c);
if (c) {
cxt->log("inner\n");

@ -9,6 +9,8 @@
#include <string>
#include <algorithm>
#include "io.h"
#include "hasher.h"
#undef ERROR
template <typename T>
class vector_type;
@ -432,21 +434,21 @@ struct TableInfo {
void inline
reserve(std::index_sequence<Is...>, uint32_t size) {
const auto& assign_sz = [&size](auto& col){ col.size = size;};
(assign_sz(get_col<Is>(*this)), ...);
(assign_sz(get_col<Is>()), ...);
}
template <size_t ...Is>
decltype(auto) inline
get_record(std::index_sequence<Is...>, uint32_t i) {
return std::forward_as_tuple((get_col<Is>(*this)[i], ...));
return std::forward_as_tuple(get_col<Is>()[i] ...);
}
template <size_t ...Is>
void inline
set_record(std::index_sequence<Is...>, tuple_type t) {
set_record(std::index_sequence<Is...>, const tuple_type& t, uint32_t i) {
const auto& assign_field =
[](auto& l, const auto& r){
l = r;
};
(assign_field(get_col<Is>(*this)[Is], std::get<Is>(t)), ...);
(assign_field(get_col<Is>()[i], std::get<Is>(t)), ...);
}
TableInfo<Types ...>* distinct() {
std::unordered_set<tuple_type> 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;
}

Loading…
Cancel
Save