diff --git a/reconstruct/ast.py b/reconstruct/ast.py index a260ccb..e1430f3 100644 --- a/reconstruct/ast.py +++ b/reconstruct/ast.py @@ -596,11 +596,14 @@ class groupby_c(ast_node): col_names : List[str], col_types : List[Types], col_tovec : List[bool]): tovec_columns = set() for i, c in enumerate(col_names): - self.context.emitc(f'{c}.reserve({self.group}.size());') if col_tovec[i]: # and type(col_types[i]) is VectorT: + self.context.emitc(f'{c}.resize({self.group}.size());') typename : Types = col_types[i] # .inner_type self.context.emitc(f'auto buf_{c} = static_cast<{typename.cname} *>(calloc({self.total_sz}, sizeof({typename.cname})));') tovec_columns.add(c) + else: + self.context.emitc(f'{c}.reserve({self.group}.size());') + self.arr_len = 'arrlen_' + base62uuid(3) self.arr_values = 'arrvals_' + base62uuid(3) diff --git a/server/libaquery.cpp b/server/libaquery.cpp index 60e4b81..500640d 100644 --- a/server/libaquery.cpp +++ b/server/libaquery.cpp @@ -615,3 +615,26 @@ aq_to_chars(void* value, char* buffer){ return buffer + src.size(); } +// Defined in vector_type.h +template <> +vector_type::vector_type(const char** container, uint32_t len, + typename std::enable_if_t*) noexcept +{ + size = capacity = len; + this->container = static_cast( + malloc(sizeof(std::string_view) * len)); + for(uint32_t i = 0; i < len; ++i){ + this->container[i] = container[i]; + } +} + +template<> +vector_type::vector_type(const uint32_t size, void* data) : + size(size), capacity(0) { + this->container = static_cast( + malloc(sizeof(std::string_view) * size)); + for(uint32_t i = 0; i < size; ++i){ + this->container[i] = ((const char**)data)[i]; + } + //std::cout< operator >(const T2& lhs, const VT& rhs) { #define _AQ_OP_(x) __AQ_OP__##x #define __AQ_OP__add + #define __AQ_OP__minus - -#define __AQ_OP__div * -#define __AQ_OP__mul / +#define __AQ_OP__mul * +#define __AQ_OP__div / #define __AQ_OP__and & #define __AQ_OP__or | #define __AQ_OP__xor ^ @@ -934,8 +934,8 @@ void aqop_##x (const VT& lhs, const VT& rhs, Ret& ret){\ __D_AQOP(add) __D_AQOP(minus) -__D_AQOP(div) __D_AQOP(mul) +__D_AQOP(div) __D_AQOP(and) __D_AQOP(or) __D_AQOP(xor) diff --git a/server/table_ext_monetdb.hpp b/server/table_ext_monetdb.hpp index 3c93c3f..65d34e5 100644 --- a/server/table_ext_monetdb.hpp +++ b/server/table_ext_monetdb.hpp @@ -28,7 +28,7 @@ inline constexpr monetdbe_types AQType_2_monetdbe[] = { #else monetdbe_int64_t, #endif - monetdbe_timestamp, monetdbe_int64_t, monetdbe_int64_t + monetdbe_timestamp, monetdbe_int8_t, monetdbe_str, monetdbe_int64_t, monetdbe_int64_t }; template @@ -75,12 +75,14 @@ void TableInfo::monetdb_append_table(void* srv, const char* alt_name) { auto err = monetdbe_append(*((monetdbe_database*)server->server), "sys", alt_name, monetdbe_cols, sizeof...(Ts)); if (err) puts(err); - return; + goto finialize; } } - // for(uint32_t i = 0; i < n_vecs; ++i) - // free(gc_vecs[i]); puts("Error! Empty table."); + +finialize: + for(uint32_t i = 0; i < cnt; ++i) + GC::gc_handle->reg(gc_vecs[i]); } @@ -92,6 +94,16 @@ void* ColRef::monetdb_get_col(void** gc_vecs, uint32_t& cnt) { col->type = aq_type; col->count = this->size; col->data = this->container; + + if constexpr(std::is_same_v) { + auto _data = static_cast( + malloc(sizeof(const char *) * this->size)); + for(uint32_t i = 0; i < this->size; ++i){ + _data[i] = this->container[i].data(); + } + col->data = _data; + gc_vecs[cnt++] = _data; + } col->name = const_cast(this->name); // auto arr = (types::timestamp_t*) malloc (sizeof(types::timestamp_t)* this->size); // if constexpr (is_vector_type){ @@ -102,5 +114,4 @@ void* ColRef::monetdb_get_col(void** gc_vecs, uint32_t& cnt) { // } return col; } - #endif diff --git a/server/types.h b/server/types.h index f9ad100..921eabd 100644 --- a/server/types.h +++ b/server/types.h @@ -393,9 +393,9 @@ template class T1> struct same_class_impl, T1> : std::true_type {}; template -bool same_class = same_class_impl::value; +constexpr bool same_class = same_class_impl::value; template class T2> -bool instance_of = instance_of_impl::value; +constexpr bool instance_of = instance_of_impl::value; template class rT> using transTypes = typename transTypes_s::type; diff --git a/server/vector_type.hpp b/server/vector_type.hpp index caa0f33..6b21ff9 100644 --- a/server/vector_type.hpp +++ b/server/vector_type.hpp @@ -61,7 +61,9 @@ public: [[likely]] container = (_Ty*)GC::scratch_space->alloc(size * sizeof(_Ty)); } - container = (_Ty*)malloc(size * sizeof(_Ty)); + else{ + container = (_Ty*)malloc(size * sizeof(_Ty)); + } // TODO: calloc for objects. } explicit constexpr vector_type(std::initializer_list<_Ty> _l) { @@ -74,7 +76,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 char** container, uint32_t len, + vector_type(const char** container, uint32_t len, typename std::enable_if_t>* = nullptr) noexcept = delete; constexpr explicit vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) { _copy(vt); @@ -90,7 +92,7 @@ public: // out(10); }; // size >= capacity ==> readonly vector - constexpr vector_type(const uint32_t size, void* data) : + vector_type(const uint32_t size, void* data) : size(size), capacity(0), container(static_cast<_Ty*>(data)) {} void init_from(const uint32_t size, void* data) { @@ -341,7 +343,8 @@ public: vector_type<_Ty> getRef() { return vector_type<_Ty>(container, size); } ~vector_type() { if (capacity > 0) GC::gc_handle->reg(container, sizeof(_Ty) * capacity);//free(container); - container = 0; size = capacity = 0; + container = nullptr; + size = capacity = 0; } #define Compare(_op) \ template \ @@ -404,28 +407,6 @@ public: _Make_Ops(Opseq) }; -template <> -constexpr vector_type::vector_type(const char** container, uint32_t len, - typename std::enable_if_t*) noexcept -{ - size = capacity = len; - this->container = static_cast( - malloc(sizeof(std::string_view) * len)); - for(uint32_t i = 0; i < len; ++i){ - this->container[i] = container[i]; - } -} - -template<> -constexpr vector_type::vector_type(const uint32_t size, void* data) : - size(size), capacity(0) { - this->container = static_cast( - malloc(sizeof(std::string_view) * size)); - for(uint32_t i = 0; i < size; ++i){ - this->container[i] = ((const char**)data)[i]; - } - //std::cout< // void vector_type::init_from(const uint32_t size, void* data) { @@ -527,4 +508,10 @@ public: } }; +template<> +vector_type::vector_type(const uint32_t size, void* data); +template <> +vector_type::vector_type(const char** container, uint32_t len, + typename std::enable_if_t*) noexcept; + #endif