1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-641 This commit introduces templates for DataConvert and RowGroup methods.

This commit is contained in:
drrtuy
2020-01-21 12:57:31 +03:00
committed by Roman Nozdrin
parent 0c67b6ab50
commit 54c152d6c8
9 changed files with 111 additions and 37 deletions

View File

@ -1174,21 +1174,28 @@ struct uint128_pod
};
// WIP MCOL-641
void DataConvert::toString(unsigned __int128 i, char *p)
// Check for overflows with buflen
template<typename T>
void DataConvert::toString(T* dec, char *p, size_t buflen)
{
uint64_t div = 10000000000000000000ULL;
size_t div_log = 19;
uint128_t high = i;
// template this
uint128_t high = *dec;
uint128_t low;
low = high % div;
high /= div;
uint128_t mid;
mid = high % div;
high /= div;
// WIP How to treat PODs here ?
// use typeof
// Or a templated structure
uint128_pod *high_pod = reinterpret_cast<uint128_pod*>(&high);
uint128_pod *mid_pod = reinterpret_cast<uint128_pod*>(&mid);
uint128_pod *low_pod = reinterpret_cast<uint128_pod*>(&low);
char* original_p = p;
int printed_chars = 0;
// WIP replace snprintf with streams
@ -1202,9 +1209,9 @@ void DataConvert::toString(unsigned __int128 i, char *p)
p += printed_chars;
}
snprintf(p, div_log+1, "%019lu", low_pod->lo);
if (buflen <= p-original_p)
std::cout << "DataConvert::toString char buffer overflow" << std::endl;
}
// WIP MCOL-641
// Template this
// result must be calloc-ed
@ -1213,7 +1220,7 @@ void DataConvert::toString(unsigned __int128 i, char *p)
void atoi128(const string& arg, int128_t& res)
{
// WIP
//char buf[40];
//char buf[41];
//int128_t *res_ptr = reinterpret_cast<int128_t*>(result);
res = 0;
for (size_t j = 0; j < arg.size(); j++)
@ -1228,10 +1235,14 @@ void atoi128(const string& arg, int128_t& res)
}
// WIP MCOL-641
void DataConvert::decimalToString(unsigned __int128 int_val, uint8_t scale, char* buf, unsigned int buflen,
execplan::CalpontSystemCatalog::ColDataType colDataType)
template <typename T>
void DataConvert::decimalToString(T* valuePtr,
uint8_t scale,
char* buf,
unsigned int buflen,
execplan::CalpontSystemCatalog::ColDataType colDataType)
{
toString(int_val, buf);
toString<T>(valuePtr, buf, buflen);
// Biggest ColumnStore supports is DECIMAL(38,x), or 38 total digits+dp+sign for column
@ -1243,7 +1254,7 @@ void DataConvert::decimalToString(unsigned __int128 int_val, uint8_t scale, char
size_t l1 = strlen(buf);
char* ptr = &buf[0];
if (int_val < 0)
if (*valuePtr < 0)
{
ptr++;
idbassert(l1 >= 2);
@ -1259,7 +1270,7 @@ void DataConvert::decimalToString(unsigned __int128 int_val, uint8_t scale, char
const char* zeros = "00000000000000000000000000000000000000"; //38 0's
size_t diff = 0;
if (int_val != 0)
if (*valuePtr != 0)
diff = scale - l1; //this will always be > 0
else
diff = scale;
@ -1267,7 +1278,7 @@ void DataConvert::decimalToString(unsigned __int128 int_val, uint8_t scale, char
memmove((ptr + diff), ptr, l1 + 1); //also move null
memcpy(ptr, zeros, diff);
if (int_val != 0)
if (*valuePtr != 0)
l1 = 0;
else
l1 = 1;
@ -1289,6 +1300,11 @@ void DataConvert::decimalToString(unsigned __int128 int_val, uint8_t scale, char
*(ptr + l1) = '.';
}
// Explicit instantiation
template
void DataConvert::decimalToString<int128_t>(int128_t* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType);
template
void DataConvert::decimalToString<uint128_t>(uint128_t* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType);
boost::any
DataConvert::convertColumnData(const CalpontSystemCatalog::ColType& colType,

View File

@ -1011,8 +1011,11 @@ public:
EXPORT static bool isNullData(execplan::ColumnResult* cr, int rownum, execplan::CalpontSystemCatalog::ColType colType);
static inline std::string decimalToString(int64_t value, uint8_t scale, execplan::CalpontSystemCatalog::ColDataType colDataType);
static inline void decimalToString(int64_t value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType);
EXPORT static void decimalToString(unsigned __int128 value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType);
EXPORT static void toString(unsigned __int128 i, char *p);
template <typename T>
EXPORT static void decimalToString(T* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType);
template <typename T>
EXPORT static void toString(T* dec, char *p, size_t buflen);
static inline std::string constructRegexp(const std::string& str);
static inline void trimWhitespace(int64_t& charData);
static inline bool isEscapedChar(char c)

View File

@ -953,6 +953,11 @@ bool Row::isNullValue(uint32_t colIndex) const
switch (len)
{
// MCOL-641 WIP
case 16:
return (*((int64_t*) &data[offsets[colIndex]]) == static_cast<int64_t>(joblist::BIGINTNULL));
break;
case 1 :
return (data[offsets[colIndex]] == joblist::TINYINTNULL);

View File

@ -435,7 +435,10 @@ public:
inline void setVarBinaryField(const uint8_t* val, uint32_t len, uint32_t colIndex);
inline std::string getBinaryField(uint32_t colIndex) const;
inline const uint8_t* getBinaryField2(uint32_t colIndex) const;
template <typename T>
inline T* getBinaryField(uint32_t colIndex) const;
template <typename T>
inline T* getBinaryField_offset(uint32_t offset) const;
inline boost::shared_ptr<mcsv1sdk::UserData> getUserData(uint32_t colIndex) const;
inline void setUserData(mcsv1sdk::mcsv1Context& context,
@ -792,7 +795,7 @@ inline uint32_t Row::getStringLength(uint32_t colIndex) const
return strnlen((char*) &data[offsets[colIndex]], getColumnWidth(colIndex));
}
// Check whether memcpy affects perf here
inline void Row::setBinaryField(const uint8_t* strdata, uint32_t length, uint32_t offset)
{
memcpy(&data[offset], strdata, length);
@ -837,11 +840,19 @@ inline std::string Row::getBinaryField(uint32_t colIndex) const
}
// WIP MCOL-641
inline const uint8_t* Row::getBinaryField2(uint32_t colIndex) const
template <typename T>
inline T* Row::getBinaryField(uint32_t colIndex) const
{
return &data[offsets[colIndex]];
return reinterpret_cast<T*>(&data[offsets[colIndex]]);
}
template <typename T>
inline T* Row::getBinaryField_offset(uint32_t offset) const
{
return reinterpret_cast<T*>(&data[offset]);
}
inline std::string Row::getVarBinaryStringField(uint32_t colIndex) const
{
if (inStringTable(colIndex))
@ -961,10 +972,12 @@ inline void Row::setUintField_offset(uint64_t val, uint32_t offset)
case 8:
*((uint64_t*) &data[offset]) = val;
break;
/* This doesn't look like appropriate place
case 16:
std::cout << __FILE__<< ":" <<__LINE__ << " Fix for 16 Bytes ?" << std::endl;
*((uint64_t*) &data[offset]) = val;
break;
*/
default:
idbassert(0);
throw std::logic_error("Row::setUintField called on a non-uint32_t field");