bug fix on select into
This commit is contained in:
@@ -117,9 +117,9 @@ decayed_t<VT, types::GetLongType<T>> sums(const VT<T>& arr) {
|
||||
return ret;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<T>> avgs(const VT<T>& arr) {
|
||||
decayed_t<VT, types::GetFPType<types::GetLongType<T>>> avgs(const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
typedef types::GetFPType<T> FPType;
|
||||
typedef types::GetFPType<types::GetLongType<T>> FPType;
|
||||
decayed_t<VT, FPType> ret(len);
|
||||
uint32_t i = 0;
|
||||
types::GetLongType<T> s;
|
||||
|
||||
+67
-14
@@ -26,6 +26,21 @@ namespace types {
|
||||
struct Coercion;
|
||||
}
|
||||
#endif
|
||||
template <template <class...> class VT, class T>
|
||||
std::ostream& operator<<(std::ostream& os, const VT<T>& v)
|
||||
{
|
||||
v.out();
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v);
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v);
|
||||
#endif
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, types::date_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::time_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::timestamp_t & v);
|
||||
template<typename _Ty>
|
||||
class ColView;
|
||||
template<typename _Ty>
|
||||
@@ -200,19 +215,7 @@ public:
|
||||
}
|
||||
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)
|
||||
{
|
||||
v.out();
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, types::date_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::time_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::timestamp_t & v);
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v);
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v);
|
||||
#endif
|
||||
|
||||
template <class Type>
|
||||
struct decayed_impl<ColView, Type> { typedef ColRef<Type> type; };
|
||||
|
||||
@@ -433,7 +436,10 @@ struct TableInfo {
|
||||
template <size_t ...Is>
|
||||
void inline
|
||||
reserve(std::index_sequence<Is...>, uint32_t size) {
|
||||
const auto& assign_sz = [&size](auto& col){ col.size = size;};
|
||||
const auto& assign_sz = [&size](auto& col){
|
||||
col.size = size;
|
||||
col.grow();
|
||||
};
|
||||
(assign_sz(get_col<Is>()), ...);
|
||||
}
|
||||
template <size_t ...Is>
|
||||
@@ -481,6 +487,53 @@ struct TableView {
|
||||
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 ...Is>
|
||||
decltype(auto) inline
|
||||
get_record(std::index_sequence<Is...>, uint32_t i) {
|
||||
return std::forward_as_tuple(info.template get_col<Is>()[idxs[i]] ...);
|
||||
}
|
||||
|
||||
TableInfo<Types ...>* get_tableinfo(const char* name = nullptr, const char** names = nullptr) {
|
||||
if (name == nullptr)
|
||||
name = info.name;
|
||||
|
||||
const char* info_names[sizeof...(Types)];
|
||||
if (name == nullptr) {
|
||||
for(uint32_t i = 0; i < sizeof...(Types); ++i)
|
||||
info_names[i] = info.colrefs[i].name;
|
||||
names = info_names;
|
||||
}
|
||||
|
||||
return new TableInfo<Types ...>(name, names);
|
||||
}
|
||||
|
||||
TableInfo<Types ...>* materialize(const char* name = nullptr, const char** names = nullptr) {
|
||||
std::make_index_sequence<sizeof...(Types)> seq;
|
||||
auto table = get_tableinfo(name, names);
|
||||
table->reserve(seq, idxs->size);
|
||||
for (uint32_t i = 0; i < idxs->size; ++i) {
|
||||
table->set_record(get_record(i));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
TableInfo<Types ...>* distinct(const char* name = nullptr, const char** names = nullptr) {
|
||||
std::unordered_set<tuple_type> d_records;
|
||||
std::make_index_sequence<sizeof...(Types)> seq;
|
||||
|
||||
for (uint32_t j = 0; j < idxs->size; ++j) {
|
||||
d_records.insert(get_record(seq, j));
|
||||
}
|
||||
|
||||
TableInfo<Types ...>* ret = get_tableinfo(name, names);
|
||||
ret->reserve(seq, d_records.size());
|
||||
uint32_t i = 0;
|
||||
for (const auto& dr : d_records) {
|
||||
ret->set_record(seq, dr, i++);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
~TableView() {
|
||||
delete idxs;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "monetdbe.h"
|
||||
|
||||
inline constexpr monetdbe_types AQType_2_monetdbe[] = {
|
||||
monetdbe_int32_t, monetdbe_float, monetdbe_str, monetdbe_double, monetdbe_int64_t,
|
||||
monetdbe_int32_t, monetdbe_float, monetdbe_str, monetdbe_double, monetdbe_double, monetdbe_int64_t,
|
||||
#ifdef HAVE_HGE
|
||||
monetdbe_int128_t,
|
||||
#else
|
||||
@@ -22,7 +22,8 @@ inline constexpr monetdbe_types AQType_2_monetdbe[] = {
|
||||
#else
|
||||
monetdbe_int64_t,
|
||||
#endif
|
||||
monetdbe_int16_t, monetdbe_int8_t, monetdbe_bool, monetdbe_int64_t, monetdbe_int64_t, monetdbe_int64_t
|
||||
monetdbe_int16_t, monetdbe_int8_t, monetdbe_bool, monetdbe_int64_t,
|
||||
monetdbe_timestamp, monetdbe_int64_t, monetdbe_int64_t
|
||||
};
|
||||
|
||||
template<class ...Ts>
|
||||
@@ -34,23 +35,33 @@ void TableInfo<Ts ...>::monetdb_append_table(void* srv, const char* alt_name) {
|
||||
monetdbe_column** monetdbe_cols = new monetdbe_column * [sizeof...(Ts)];
|
||||
|
||||
uint32_t i = 0;
|
||||
const auto get_col = [&monetdbe_cols, &i](auto v) {
|
||||
puts("getcols...");
|
||||
const auto get_col = [&monetdbe_cols, &i, *this](auto v) {
|
||||
printf("%d %d\n", i, (ColRef<void>*)v - colrefs);
|
||||
monetdbe_cols[i++] = (monetdbe_column*)v->monetdb_get_col();
|
||||
};
|
||||
(get_col((ColRef<Ts>*)(colrefs + i)), ...);
|
||||
|
||||
puts("getcols done");
|
||||
for(int i = 0; i < sizeof...(Ts); ++i)
|
||||
{
|
||||
printf("no:%d name: %s count:%d data: %p \n",
|
||||
i, monetdbe_cols[i]->name, monetdbe_cols[i]->count, monetdbe_cols[i]->data);
|
||||
}
|
||||
std::string create_table_str = "CREATE TABLE ";
|
||||
create_table_str += alt_name;
|
||||
create_table_str += " (";
|
||||
i = 0;
|
||||
const auto get_name_type = [&i, *this]() {
|
||||
return std::string(colrefs[i++].name) + ' ';
|
||||
const auto get_name_type = [&i, *this, &create_table_str](auto v) {
|
||||
create_table_str+= std::string(colrefs[i++].name) + ' ' +
|
||||
std::string(types::SQL_Type[types::Types<std::remove_pointer_t<decltype(v)>>::getType()]) + ", ";
|
||||
};
|
||||
create_table_str += ((get_name_type() + types::SQL_Type[types::Types<Ts>::getType()] + ", ") + ... + std::string(""));
|
||||
(get_name_type((Ts*)(0)), ...);
|
||||
auto last_comma = create_table_str.find_last_of(',');
|
||||
if (last_comma != static_cast<decltype(last_comma)>(-1)) {
|
||||
create_table_str[last_comma] = ')';
|
||||
Server* server = (Server*)srv;
|
||||
puts("create table...");
|
||||
puts(create_table_str.c_str());
|
||||
server->exec(create_table_str.c_str());
|
||||
if (!server->last_error) {
|
||||
auto err = monetdbe_append(*((monetdbe_database*)server->server), "sys", alt_name, monetdbe_cols, sizeof...(Ts));
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ namespace types {
|
||||
};
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%d", "%hi", "%s", "%s", "%c",
|
||||
"%u", "%lu", "%s", "%hu", "%hhu", "%s", "%s", "Vector<%s>", "%s", "NULL", "ERROR" };
|
||||
static constexpr const char* SQL_Type[] = { "INT", "REAL", "TEXT", "DOUBLE", "DOUBLE", "BIGINT", "HUGEINT", "SMALLINT", "DATE", "TIME", "TINYINT",
|
||||
static constexpr const char* SQL_Type[] = { "INT", "REAL", "VARCHAR(15)", "DOUBLE", "DOUBLE", "BIGINT", "HUGEINT", "SMALLINT", "DATE", "TIME", "TINYINT",
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BIGINT", "BOOL", "BIGINT", "TIMESTAMP", "NULL", "ERROR"};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user