From 63dcaa387f3c5e9748414179393b5bdc533dc8e5 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Thu, 9 Jan 2020 13:22:56 +0000 Subject: [PATCH] MCOL-641 Simple INSERT with one record works with this commit. --- primitives/linux-port/column.cpp | 2 +- utils/dataconvert/dataconvert.cpp | 71 ++++++++++++++++++++++++++++- writeengine/shared/we_convertor.cpp | 5 +- writeengine/wrapper/we_colop.cpp | 10 +++- writeengine/wrapper/writeengine.cpp | 67 +++++++++++++++++++++++++-- 5 files changed, 144 insertions(+), 11 deletions(-) diff --git a/primitives/linux-port/column.cpp b/primitives/linux-port/column.cpp index b76b79655..f6d4e09d9 100644 --- a/primitives/linux-port/column.cpp +++ b/primitives/linux-port/column.cpp @@ -1627,9 +1627,9 @@ inline void p_Col_bin_ridArray(NewColRequestHeader* in, rfs[argIndex] = args->rf; memcpy(argVals[argIndex],args->val, W); + regex[argIndex].used = false; } - regex[argIndex].used = false; } diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index af0446616..df29d1d36 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -1161,11 +1161,73 @@ bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, const str } +// WIP +#include +using int128_t = __int128; +using uint128_t = unsigned __int128; + +struct uint128_pod +{ + uint64_t lo; + uint64_t hi; +}; + +inline void toString(uint128_t i, char *p) +{ + uint64_t div = 10000000000000000000ULL; + size_t div_log = 19; + uint128_t high = i; + uint128_t low; + low = high % div; + high /= div; + uint128_t mid; + mid = high % div; + high /= div; + + uint128_pod *high_pod = reinterpret_cast(&high); + uint128_pod *mid_pod = reinterpret_cast(&mid); + uint128_pod *low_pod = reinterpret_cast(&low); + int printed_chars = 0; + + // WIP replace snprintf with streams + if (high_pod->lo != 0) { + printed_chars = snprintf(p, div_log+1, "%ld", high_pod->lo); + p += printed_chars; + printed_chars = snprintf(p, div_log+1, "%019lu", mid_pod->lo); + p += printed_chars; + } else if (mid_pod->lo != 0) { + printed_chars = snprintf(p, div_log+1, "%lu", mid_pod->lo); + p += printed_chars; + } + snprintf(p, div_log+1, "%019ld", low_pod->lo); +} + + +// Template this +// result must be calloc-ed +void atoi_(const string &arg, int128_t &res, size_t &size) +{ + // WIP + //char buf[40]; + //int128_t *res_ptr = reinterpret_cast(result); + res = 0; + for (int j = 0; j < arg.size(); j++) + { + // WIP + res = res*10 + arg[j] - '0'; + } + //toString(res, buf); + //std::cerr << "atoi_ " << buf <(&high); + uint128_pod *mid_pod = reinterpret_cast(&mid); + uint128_pod *low_pod = reinterpret_cast(&low); + int printed_chars = 0; + + // WIP replace snprintf with streams + if (high_pod->lo != 0) { + printed_chars = snprintf(p, div_log+1, "%ld", high_pod->lo); + p += printed_chars; + printed_chars = snprintf(p, div_log+1, "%019lu", mid_pod->lo); + p += printed_chars; + } else if (mid_pod->lo != 0) { + printed_chars = snprintf(p, div_log+1, "%lu", mid_pod->lo); + p += printed_chars; + } + snprintf(p, div_log+1, "%019ld", low_pod->lo); +} + + + /*@convertValArray - Convert interface values to internal values */ /*********************************************************** @@ -389,8 +433,14 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* value, boost: } break; - case WriteEngine::WR_BINARY: case WriteEngine::WR_INT128: + { + int128_t val = boost::any_cast(data); + size = 16; + // WIP Why do we use memcpy here? + memcpy(value, &val, size); + } + case WriteEngine::WR_BINARY: { char val = boost::any_cast(data); //TODO:FIXME how to determine size ? 16, 32,48 ? @@ -416,7 +466,6 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* value, boost: void WriteEngineWrapper::convertValue(const ColType colType, void* valArray, const size_t pos, boost::any& data, bool fromList) { string curStr; -// ColTuple curTuple; if (fromList) { @@ -505,11 +554,15 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* valArray, con break; case WriteEngine::WR_BINARY: - case WriteEngine::WR_INT128: curStr = boost::any_cast(data); memcpy((char*)valArray + pos * curStr.length(), curStr.c_str(), curStr.length()); break; - + case WriteEngine::WR_INT128: + int128_t val = boost::any_cast(data); + size_t size = 16; + // WIP Why do we use memcpy here? + memcpy((uint8_t*)valArray+pos*size, &val, size); + break; } // end of switch (colType) } else @@ -576,8 +629,12 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* valArray, con data = ((Token*)valArray)[pos]; break; - case WriteEngine::WR_BINARY : case WriteEngine::WR_INT128: + { + data = ((int128_t*)valArray)[pos]; + break; + } + case WriteEngine::WR_BINARY : { char tmp[16]; //TODO:FIXME how to determine size ? 16, 32,48 ?