fixed int128 problem, groupby agg
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#include "io.h"
|
||||
|
||||
char* gbuf = 0;
|
||||
|
||||
void setgbuf(char* buf){
|
||||
static char* b = 0;
|
||||
if (buf == 0)
|
||||
gbuf = b;
|
||||
else
|
||||
gbuf = buf;
|
||||
}
|
||||
+49
@@ -2,6 +2,7 @@
|
||||
#include "types.h"
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
template <class ...Types>
|
||||
std::string generate_printf_string(const char* sep = " ", const char* end = "\n") {
|
||||
std::string str;
|
||||
@@ -13,3 +14,51 @@ std::string generate_printf_string(const char* sep = " ", const char* end = "\n"
|
||||
return str;
|
||||
}
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
inline const char* get_int128str(__int128_t v, char* buf){
|
||||
bool neg = false;
|
||||
if (v < 0) {
|
||||
if(v == std::numeric_limits<__int128_t>::min())
|
||||
return "-170141183460469231731687303715884105728";
|
||||
v = -v;
|
||||
neg = true;
|
||||
}
|
||||
do {
|
||||
*--buf = v%10 + '0';
|
||||
v /= 10;
|
||||
} while(v);
|
||||
if (neg) *--buf = '-';
|
||||
return buf;
|
||||
}
|
||||
|
||||
inline const char* get_uint128str(__uint128_t v, char* buf){
|
||||
do {
|
||||
*--buf = v%10 + '0';
|
||||
v /= 10;
|
||||
} while(v);
|
||||
return buf;
|
||||
}
|
||||
extern char* gbuf;
|
||||
|
||||
void setgbuf(char* buf = 0);
|
||||
|
||||
template<class T>
|
||||
inline decltype(auto) printi128(const T& v){
|
||||
return v;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline decltype(auto) printi128<__int128_t>(const __int128_t& v) {
|
||||
*(gbuf+=40) = 0;
|
||||
return get_int128str(v, gbuf++);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline decltype(auto) printi128<__uint128_t>(const __uint128_t& v) {
|
||||
*(gbuf+=40) = 0;
|
||||
return get_uint128str(v, gbuf++);
|
||||
}
|
||||
|
||||
#else
|
||||
#define printi128(x) x
|
||||
#endif
|
||||
|
||||
+2
-1
@@ -48,9 +48,10 @@ struct Context{
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#define __DLLEXPORT__ __declspec(dllexport) __stdcall
|
||||
#define __DLLEXPORT__ __declspec(dllexport) __stdcall
|
||||
#else
|
||||
#define __DLLEXPORT__
|
||||
#endif
|
||||
|
||||
#define __AQEXPORT__(_Ty) extern "C" _Ty __DLLEXPORT__
|
||||
#endif
|
||||
@@ -24,4 +24,4 @@ struct Server{
|
||||
void *getCol(int col_idx);
|
||||
void close();
|
||||
~Server();
|
||||
};
|
||||
};
|
||||
|
||||
+55
-44
@@ -28,6 +28,7 @@ struct SharedMemory
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
struct thread_context{
|
||||
|
||||
}v;
|
||||
@@ -59,6 +60,15 @@ extern "C" int __DLLEXPORT__ binary_info() {
|
||||
return AppleClang;
|
||||
#endif
|
||||
}
|
||||
|
||||
__AQEXPORT__(bool) have_hge(){
|
||||
#if defined(_MONETDBE_LIB_) and defined(HAVE_HGE)
|
||||
return HAVE_HGE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
int dll_main(int argc, char** argv, Context* cxt){
|
||||
Config *cfg = reinterpret_cast<Config *>(argv[0]);
|
||||
|
||||
@@ -111,50 +121,50 @@ int dll_main(int argc, char** argv, Context* cxt){
|
||||
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
//extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
|
||||
//
|
||||
// puts("running");
|
||||
// Context* cxt = new Context();
|
||||
// cxt->log("%d %s\n", argc, argv[1]);
|
||||
//
|
||||
// const char* shmname;
|
||||
// if (argc < 0)
|
||||
// return dll_main(argc, argv, cxt);
|
||||
// else if (argc <= 1)
|
||||
// return test_main();
|
||||
// else
|
||||
// shmname = argv[1];
|
||||
// SharedMemory shm = SharedMemory(shmname);
|
||||
// if (!shm.pData)
|
||||
// return 1;
|
||||
// bool &running = static_cast<bool*>(shm.pData)[0],
|
||||
// &ready = static_cast<bool*>(shm.pData)[1];
|
||||
// using namespace std::chrono_literals;
|
||||
// cxt->log("running: %s\n", running? "true":"false");
|
||||
// cxt->log("ready: %s\n", ready? "true":"false");
|
||||
// while (running) {
|
||||
// std::this_thread::sleep_for(1ms);
|
||||
// if(ready){
|
||||
// cxt->log("running: %s\n", running? "true":"false");
|
||||
// cxt->log("ready: %s\n", ready? "true":"false");
|
||||
// void* handle = dlopen("./dll.so", RTLD_LAZY);
|
||||
// cxt->log("handle: %lx\n", handle);
|
||||
// if (handle) {
|
||||
// cxt->log("inner\n");
|
||||
// code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain"));
|
||||
// cxt->log("routine: %lx\n", c);
|
||||
// if (c) {
|
||||
// cxt->log("inner\n");
|
||||
// cxt->err("return: %d\n", c(cxt));
|
||||
// }
|
||||
// }
|
||||
// ready = false;
|
||||
// }
|
||||
// }
|
||||
// shm.FreeMemoryMap();
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
|
||||
|
||||
puts("running");
|
||||
Context* cxt = new Context();
|
||||
cxt->log("%d %s\n", argc, argv[1]);
|
||||
|
||||
const char* shmname;
|
||||
if (argc < 0)
|
||||
return dll_main(argc, argv, cxt);
|
||||
else if (argc <= 1)
|
||||
return test_main();
|
||||
else
|
||||
shmname = argv[1];
|
||||
SharedMemory shm = SharedMemory(shmname);
|
||||
if (!shm.pData)
|
||||
return 1;
|
||||
bool &running = static_cast<bool*>(shm.pData)[0],
|
||||
&ready = static_cast<bool*>(shm.pData)[1];
|
||||
using namespace std::chrono_literals;
|
||||
cxt->log("running: %s\n", running? "true":"false");
|
||||
cxt->log("ready: %s\n", ready? "true":"false");
|
||||
while (running) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
if(ready){
|
||||
cxt->log("running: %s\n", running? "true":"false");
|
||||
cxt->log("ready: %s\n", ready? "true":"false");
|
||||
void* handle = dlopen("./dll.so", RTLD_LAZY);
|
||||
cxt->log("handle: %lx\n", handle);
|
||||
if (handle) {
|
||||
cxt->log("inner\n");
|
||||
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain"));
|
||||
cxt->log("routine: %lx\n", c);
|
||||
if (c) {
|
||||
cxt->log("inner\n");
|
||||
cxt->err("return: %d\n", c(cxt));
|
||||
}
|
||||
}
|
||||
ready = false;
|
||||
}
|
||||
}
|
||||
shm.FreeMemoryMap();
|
||||
return 0;
|
||||
}
|
||||
#include "utils.h"
|
||||
int test_main()
|
||||
{
|
||||
@@ -200,6 +210,7 @@ int test_main()
|
||||
dlclose(handle);
|
||||
}
|
||||
//static_assert(std::is_same_v<decltype(fill_integer_array<5, 1>()), std::integer_sequence<bool, 1,1,1,1,1>>, "");
|
||||
|
||||
return 0;
|
||||
std::unordered_map<int, int> a;
|
||||
}
|
||||
|
||||
@@ -1 +1,28 @@
|
||||
#include "table.h"
|
||||
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_int128str(v, s+40);
|
||||
}
|
||||
template <>
|
||||
void print<__uint128_t>(const __uint128_t&v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_uint128str(v, s+40);
|
||||
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
+41
-8
@@ -63,14 +63,19 @@ public:
|
||||
using vector_type<_Ty>::operator[];
|
||||
using vector_type<_Ty>::operator=;
|
||||
using vector_type<_Ty>::subvec;
|
||||
using vector_type<_Ty>::subvec_view;
|
||||
using vector_type<_Ty>::subvec_memcpy;
|
||||
using vector_type<_Ty>::subvec_deep;
|
||||
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
|
||||
return ColView<_Ty>(*this, idxs);
|
||||
}
|
||||
|
||||
void out(uint32_t n = 4, const char* sep = " ") const {
|
||||
n = n > this->size ? this->size : n;
|
||||
const char* more = "";
|
||||
if (n < this->size)
|
||||
more = " ... ";
|
||||
else
|
||||
n = this->size;
|
||||
|
||||
std::cout << '(';
|
||||
if (n > 0)
|
||||
{
|
||||
@@ -79,6 +84,7 @@ public:
|
||||
std::cout << this->operator[](i) << sep;
|
||||
std::cout << this->operator[](i);
|
||||
}
|
||||
std::cout<< more;
|
||||
std::cout << ')';
|
||||
}
|
||||
template<typename T>
|
||||
@@ -90,7 +96,7 @@ class ColView {
|
||||
public:
|
||||
typedef ColRef<_Ty> Decayed_t;
|
||||
const vector_type<uint32_t>& idxs;
|
||||
const ColRef<_Ty>& orig;
|
||||
const ColRef<_Ty> orig;
|
||||
const uint32_t& size;
|
||||
ColView(const ColRef<_Ty>& orig, const vector_type<uint32_t>& idxs) : orig(orig), idxs(idxs), size(idxs.size) {}
|
||||
ColView(const ColView<_Ty>& orig, const vector_type<uint32_t>& idxs) : orig(orig.orig), idxs(idxs), size(idxs.size) {
|
||||
@@ -135,6 +141,10 @@ public:
|
||||
ret[i] = orig[idxs[i]];
|
||||
return ret;
|
||||
}
|
||||
ColView<_Ty> subvec(uint32_t start, uint32_t end) {
|
||||
uint32_t len = end - start;
|
||||
return ColView<_Ty>(orig, idxs.subvec(start, end));
|
||||
}
|
||||
ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) {
|
||||
uint32_t len = end - start;
|
||||
ColRef<_Ty> subvec(len);
|
||||
@@ -142,7 +152,7 @@ public:
|
||||
subvec[i] = operator[](i);
|
||||
return subvec;
|
||||
}
|
||||
inline ColRef<_Ty> subvec_deep(uint32_t start = 0) { return subvec_deep(start, size); }
|
||||
inline ColRef<_Ty> subvec(uint32_t start = 0) { return subvec_deep(start, size); }
|
||||
};
|
||||
template <template <class...> class VT, class T>
|
||||
std::ostream& operator<<(std::ostream& os, const VT<T>& v)
|
||||
@@ -150,8 +160,11 @@ std::ostream& operator<<(std::ostream& os, const VT<T>& v)
|
||||
v.out();
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v);
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v);
|
||||
template <class Type>
|
||||
struct decayed_impl<ColView, Type> { typedef ColRef<Type> type; };
|
||||
|
||||
template<typename _Ty>
|
||||
template<typename T>
|
||||
inline ColRef<T> ColRef<_Ty>::scast()
|
||||
@@ -186,6 +199,7 @@ struct is_vector_impl<vector_type<V>> : std::true_type {};
|
||||
|
||||
template<class ...Types>
|
||||
struct TableView;
|
||||
|
||||
template<class ...Types>
|
||||
struct TableInfo {
|
||||
const char* name;
|
||||
@@ -211,14 +225,17 @@ struct TableInfo {
|
||||
rid.emplace_back(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<class ...Types2>
|
||||
auto bind(TableInfo<Types2...>* table2) {
|
||||
return lineage_t(this, table2);
|
||||
}
|
||||
|
||||
template <size_t i = 0>
|
||||
auto& get_col() {
|
||||
return *reinterpret_cast<ColRef<std::tuple_element_t <i, tuple_type>>*>(colrefs + i);
|
||||
}
|
||||
|
||||
template <size_t j = 0>
|
||||
typename std::enable_if<j == sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
|
||||
template <size_t j = 0>
|
||||
@@ -227,6 +244,7 @@ struct TableInfo {
|
||||
struct GetTypes {
|
||||
typedef typename std::tuple<typename std::tuple_element<Idxs, tuple_type>::type ...> type;
|
||||
};
|
||||
|
||||
template <size_t ...Idxs>
|
||||
using getRecordType = typename GetTypes<Idxs...>::type;
|
||||
TableInfo(const char* name, uint32_t n_cols);
|
||||
@@ -276,9 +294,9 @@ struct TableInfo {
|
||||
const auto& this_value = get<col>(*this)[i];
|
||||
const auto& next = [&](auto &v) {
|
||||
if constexpr (sizeof...(rem_cols) == 0)
|
||||
func(args..., v);
|
||||
func(args..., printi128(v));
|
||||
else
|
||||
print2_impl<rem_cols...>(func, i, args ..., v);
|
||||
print2_impl<rem_cols...>(func, i, args ..., printi128(v));
|
||||
};
|
||||
if constexpr (is_vector_type<this_type>)
|
||||
for (int j = 0; j < this_value.size; ++j)
|
||||
@@ -312,12 +330,20 @@ struct TableInfo {
|
||||
header_string.resize(header_string.size() - l_sep);
|
||||
|
||||
const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
|
||||
constexpr auto num_hge = count_type<__int128_t, __uint128_t>((tuple_type*)(0));
|
||||
char cbuf[num_hge * 41];
|
||||
setgbuf(cbuf);
|
||||
|
||||
if(view)
|
||||
for (int i = 0; i < view->size; ++i)
|
||||
for (int i = 0; i < view->size; ++i){
|
||||
print2_impl<cols...>(f, (*view)[i], printf_string.c_str());
|
||||
setgbuf();
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < colrefs[0].size; ++i)
|
||||
for (int i = 0; i < colrefs[0].size; ++i){
|
||||
print2_impl<cols...>(f, i, printf_string.c_str());
|
||||
setgbuf();
|
||||
}
|
||||
};
|
||||
|
||||
if (fp)
|
||||
@@ -538,6 +564,13 @@ void print(const T& v, const char* delimiter = " ") {
|
||||
std::cout<< v;
|
||||
// printf(types::printf_str[types::Types<T>::getType()], v);
|
||||
}
|
||||
#ifdef __SIZEOF_INT128__
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter);
|
||||
template <>
|
||||
void print<__uint128_t>(const __uint128_t&v, const char* delimiter);
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
void inline print_impl(const T& v, const char* delimiter, const char* endline) {
|
||||
for (const auto& vi : v) {
|
||||
|
||||
+33
-6
@@ -21,11 +21,11 @@ constexpr static bool is_vector_type = is_vector_impl<T>::value;
|
||||
|
||||
namespace types {
|
||||
enum Type_t {
|
||||
AINT32, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, AINT64, AINT16, ADATE, ATIME, AINT8,
|
||||
AUINT32, AUINT64, AUINT16, AUINT8, VECTOR, NONE, ERROR
|
||||
AINT32, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, AINT64, AINT128, AINT16, ADATE, ATIME, AINT8,
|
||||
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, VECTOR, NONE, ERROR
|
||||
};
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%llf", "%ld", "%hi", "%s", "%s", "%c",
|
||||
"%u", "%lu", "%hu", "%hhu", "Vector<%s>", "NULL", "ERROR" };
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%llf", "%ld", "%s", "%hi", "%s", "%s", "%c",
|
||||
"%u", "%lu", "%s", "%hu", "%hhu", "Vector<%s>", "NULL", "ERROR" };
|
||||
// TODO: deal with data/time <=> str/uint conversion
|
||||
struct date_t {
|
||||
uint32_t val;
|
||||
@@ -43,6 +43,17 @@ namespace types {
|
||||
struct Types {
|
||||
typedef T type;
|
||||
constexpr Types() noexcept = default;
|
||||
#ifdef __SIZEOF_INT128__
|
||||
#define F_INT128(__F_) __F_(__int128_t, AINT128) \
|
||||
__F_(__uint128_t, AUINT128)
|
||||
#define ULL_Type __uint128_t
|
||||
#define LL_Type __int128_t
|
||||
#else
|
||||
#define F_INT128
|
||||
#define ULL_Type unsigned long long
|
||||
#define LL_Type long long
|
||||
#endif
|
||||
|
||||
#define ConnectTypes(f) \
|
||||
f(int, AINT32) \
|
||||
f(float, AFLOAT) \
|
||||
@@ -57,7 +68,8 @@ namespace types {
|
||||
f(unsigned int, AUINT32) \
|
||||
f(unsigned long, AUINT64) \
|
||||
f(unsigned short, AUINT16) \
|
||||
f(unsigned char, AUINT8)
|
||||
f(unsigned char, AUINT8) \
|
||||
F_INT128(f)
|
||||
|
||||
inline constexpr static Type_t getType() {
|
||||
#define TypeConnect(x, y) if constexpr(std::is_same<x, T>::value) return y; else
|
||||
@@ -90,7 +102,7 @@ namespace types {
|
||||
using GetFPType = typename GetFPTypeImpl<typename std::decay<T>::type>::type;
|
||||
template<class T>
|
||||
struct GetLongTypeImpl {
|
||||
using type = Cond(__U(T), unsigned long long, Cond(Fp(T), long double, long long));
|
||||
using type = Cond(__U(T), ULL_Type, Cond(Fp(T), long double, LL_Type));
|
||||
};
|
||||
template<class T>
|
||||
using GetLongType = typename GetLongTypeImpl<typename std::decay<T>::type>::type;
|
||||
@@ -202,4 +214,19 @@ struct nullval_impl<float> { constexpr static float value = -std::numeric_limits
|
||||
template<>
|
||||
struct nullval_impl<double> { constexpr static double value = -std::numeric_limits<double>::quiet_NaN(); };
|
||||
|
||||
constexpr size_t sum_type(size_t a[], size_t sz) {
|
||||
size_t ret = 0;
|
||||
for (int i = 0; i < sz; ++i)
|
||||
ret += a[i];
|
||||
return ret;
|
||||
}
|
||||
template<class Types, class ...T1> constexpr size_t sum_type() {
|
||||
size_t t[] = {std::is_same_v<Types, T1> ...};
|
||||
return sum_type(t, sizeof...(T1));
|
||||
}
|
||||
template<class ...T1, class ...Types> constexpr
|
||||
size_t count_type(std::tuple<Types...>* ts) {
|
||||
size_t t[] = {sum_type<Types, T1...>() ...};
|
||||
return sum_type(t, sizeof...(Types));
|
||||
}
|
||||
#endif // !_TYPES_H
|
||||
|
||||
+9
-11
@@ -145,7 +145,7 @@ public:
|
||||
return curr;
|
||||
}
|
||||
|
||||
_Ty& operator[](const uint32_t _i) const {
|
||||
inline _Ty& operator[](const uint32_t _i) const {
|
||||
return container[_i];
|
||||
}
|
||||
|
||||
@@ -212,15 +212,15 @@ public:
|
||||
size = this->size + dist;
|
||||
}
|
||||
void out(uint32_t n = 4, const char* sep = " ") const;
|
||||
vector_type<_Ty> subvec(uint32_t start, uint32_t end) {
|
||||
vector_type<_Ty> subvec_memcpy(uint32_t start, uint32_t end) const {
|
||||
vector_type<_Ty> subvec(end - start);
|
||||
memcpy(subvec.container, container + start, sizeof(_Ty) * (end - start));
|
||||
return subvec;
|
||||
}
|
||||
inline vector_type<_Ty> subvec_view(uint32_t start, uint32_t end) {
|
||||
return subvec(container + start, end - start);
|
||||
inline vector_type<_Ty> subvec(uint32_t start, uint32_t end) const {
|
||||
return vector_type<_Ty>(container + start, end - start);
|
||||
}
|
||||
vector_type<_Ty> subvec_deep(uint32_t start, uint32_t end) {
|
||||
vector_type<_Ty> subvec_deep(uint32_t start, uint32_t end) const {
|
||||
uint32_t len = end - start;
|
||||
vector_type<_Ty> subvec(len);
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
@@ -228,7 +228,7 @@ public:
|
||||
return subvec;
|
||||
}
|
||||
inline vector_type<_Ty> subvec(uint32_t start = 0) { return subvec(start, size); }
|
||||
inline vector_type<_Ty> subvec_view(uint32_t start = 0) { return subvec_view(start, size); }
|
||||
inline vector_type<_Ty> subvec_memcpy(uint32_t start = 0) { return subvec_memcpy(start, size); }
|
||||
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) { return subvec_deep(start, size); }
|
||||
|
||||
~vector_type() {
|
||||
@@ -305,14 +305,12 @@ public:
|
||||
void* get(uint32_t i, types::Type_t atype){
|
||||
return static_cast<void*>(static_cast<char*>(container) + (i * types::AType_sizes[atype]));
|
||||
}
|
||||
void operator[](const uint32_t& i) {
|
||||
|
||||
}
|
||||
void operator[](const uint32_t& i);
|
||||
vector_type<void> subvec(uint32_t, uint32_t);
|
||||
vector_type<void> subvec_view(uint32_t, uint32_t);
|
||||
vector_type<void> subvec_memcpy(uint32_t, uint32_t);
|
||||
vector_type<void> subvec_deep(uint32_t, uint32_t);
|
||||
vector_type<void> subvec(uint32_t);
|
||||
vector_type<void> subvec_view(uint32_t);
|
||||
vector_type<void> subvec_memcpy(uint32_t);
|
||||
vector_type<void> subvec_deep(uint32_t);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
Reference in New Issue
Block a user