simple udf code generation

This commit is contained in:
2022-07-29 22:45:51 +08:00
parent ece2a6cc9f
commit 5b1bbf0f99
58 changed files with 2642 additions and 1588 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@

@@ -1 +0,0 @@

@@ -1 +0,0 @@

@@ -1,2 +0,0 @@
#TargetFrameworkVersion=:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.19041.0
Release|Win32|d:\gg\AQuery++\server\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16 -1
View File
@@ -14,11 +14,26 @@ const char* monetdbe_type_str[] = {
// should be last:
"monetdbe_type_unknown"
} ;
const unsigned char monetdbe_type_szs[] = {
sizeof(monetdbe_column_bool::null_value), sizeof(monetdbe_column_int8_t::null_value),
sizeof(monetdbe_column_int16_t::null_value), sizeof(monetdbe_column_int32_t::null_value),
sizeof(monetdbe_column_int64_t::null_value),
#ifdef HAVE_HGE
sizeof(monetdbe_column_int128_t::null_value),
#endif
sizeof(monetdbe_column_size_t::null_value), sizeof(monetdbe_column_float::null_value),
sizeof(monetdbe_column_double::null_value),
sizeof(monetdbe_column_str::null_value), sizeof(monetdbe_column_blob::null_value),
sizeof(monetdbe_data_date), sizeof(monetdbe_data_time), sizeof(monetdbe_data_timestamp),
// should be last:
1
};
Server::Server(Context* cxt){
if (cxt){
connect(cxt);
}
}
}
void Server::connect(Context *cxt){
+5 -1
View File
@@ -1,4 +1,8 @@
#include "monetdbe.h"
#ifdef _WIN32
#include "monetdbe.h"
#else
#include "monetdb/monetdbe.h"
#endif
struct Context;
+44 -43
View File
@@ -111,49 +111,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()
{
+23 -12
View File
@@ -62,6 +62,9 @@ public:
ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {}
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_deep;
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
return ColView<_Ty>(*this, idxs);
}
@@ -132,6 +135,14 @@ public:
ret[i] = orig[idxs[i]];
return ret;
}
ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) {
uint32_t len = end - start;
ColRef<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
subvec[i] = operator[](i);
return subvec;
}
inline ColRef<_Ty> subvec_deep(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)
@@ -431,84 +442,84 @@ inline void TableInfo<Types...>::print(const char* __restrict sep, const char* _
}
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] - rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] - rhs;
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs - rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] + rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] + rhs;
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs + rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] * rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] * rhs;
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, "");
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs * rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size, "");
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] / rhs[i];
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size, "");
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] / rhs;
return ret;
}
template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(rhs.size, "");
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(rhs.size);
for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs / rhs[i];
return ret;
+32 -3
View File
@@ -47,6 +47,7 @@ public:
_Ty* container;
uint32_t size, capacity;
typedef _Ty* iterator_t;
typedef _Ty value_t;
vector_type(const uint32_t& size) : size(size), capacity(size) {
container = (_Ty*)malloc(size * sizeof(_Ty));
}
@@ -58,6 +59,7 @@ public:
}
}
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
constexpr vector_type(_Ty* container, uint32_t len) noexcept : size(len), capacity(0), container(container) {};
constexpr vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) {
_copy(vt);
}
@@ -107,11 +109,13 @@ public:
}
void emplace_back(_Ty _val) {
if (size >= capacity) { // geometric growth
capacity += 1 + (capacity >> 1);
_Ty* n_container = (_Ty*)malloc(capacity * sizeof(_Ty));
uint32_t new_capacity = size + 1 + (size >> 1);
_Ty* n_container = (_Ty*)malloc(new_capacity * sizeof(_Ty));
memcpy(n_container, container, sizeof(_Ty) * size);
free(container);
if (capacity)
free(container);
container = n_container;
capacity = new_capacity;
}
container[size++] = _val;
}
@@ -208,6 +212,25 @@ 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(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);
}
vector_type<_Ty> subvec_deep(uint32_t start, uint32_t end) {
uint32_t len = end - start;
vector_type<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
subvec[i] = container[i];
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_deep(uint32_t start = 0) { return subvec_deep(start, size); }
~vector_type() {
if (capacity > 0) free(container);
container = 0; size = capacity = 0;
@@ -285,6 +308,12 @@ public:
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_deep(uint32_t, uint32_t);
vector_type<void> subvec(uint32_t);
vector_type<void> subvec_view(uint32_t);
vector_type<void> subvec_deep(uint32_t);
};
#pragma pack(pop)
#endif