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

MCOL-641 Switched to DataConvert static methods in joblist code.

Replaced BINARYEMPTYROW and BINARYNULL values. We need to have
separate magic values for numeric and non-numeric binary types
b/c numeric cant tolerate losing 0 used for magics previously.

atoi128() now parses minus sign and produces negative values.

RowAggregation::isNull() now uses Row::isNull() for DECIMAL.
This commit is contained in:
drrtuy
2020-02-04 23:02:39 +03:00
committed by Roman Nozdrin
parent 0ff0472842
commit 84f9821720
6 changed files with 59 additions and 48 deletions

View File

@ -1601,18 +1601,6 @@ bool optimizeIdbPatitionSimpleFilter(SimpleFilter* sf, JobStepVector& jsv, JobIn
return true; return true;
} }
// WIP MCOL-641 put this in dataconvert
void atoi128(const string& arg, unsigned __int128& res)
{
res = 0;
for (size_t j = 0; j < arg.size(); j++)
{
if (LIKELY(arg[j]-'0' >= 0))
res = res*10 + arg[j] - '0';
}
}
const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo) const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo)
{ {
JobStepVector jsv; JobStepVector jsv;
@ -1899,11 +1887,13 @@ const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo)
} }
#else #else
// WIP MCOL-641 // WIP MCOL-641 width check must be a f() not a literal
// make a template from convertValueNum to avoid extra if
// this condition doesn't support UDECIMAL
if (ct.colDataType == CalpontSystemCatalog::DECIMAL && if (ct.colDataType == CalpontSystemCatalog::DECIMAL &&
ct.colWidth == 16) ct.colWidth == 16)
{ {
atoi128(constval, val128); dataconvert::atoi128(constval, val128);
} }
else else
{ {

View File

@ -83,8 +83,8 @@ const uint16_t NULL_UINT16 = USMALLINTNULL;
const uint32_t NULL_UINT32 = UINTNULL; const uint32_t NULL_UINT32 = UINTNULL;
const uint64_t NULL_UINT64 = UBIGINTNULL; const uint64_t NULL_UINT64 = UBIGINTNULL;
const uint64_t BINARYEMPTYROW = 0; const uint64_t BINARYEMPTYROW = UBIGINTEMPTYROW;
const uint64_t BINARYNULL = 0; const uint64_t BINARYNULL = UBIGINTNULL;
const std::string CPNULLSTRMARK("_CpNuLl_"); const std::string CPNULLSTRMARK("_CpNuLl_");
const std::string CPSTRNOTFOUND("_CpNoTf_"); const std::string CPSTRNOTFOUND("_CpNoTf_");

View File

@ -51,6 +51,7 @@ typedef uint32_t ulong;
using namespace logging; using namespace logging;
namespace namespace
{ {
@ -1162,10 +1163,8 @@ bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, const str
} }
// WIP // WIP MCOL-641
#include <stdio.h> #include <stdio.h>
using int128_t = __int128;
using uint128_t = unsigned __int128;
struct uint128_pod struct uint128_pod
{ {
@ -1192,6 +1191,7 @@ void DataConvert::toString(T* dec, char *p, size_t buflen)
// WIP How to treat PODs here ? // WIP How to treat PODs here ?
// use typeof // use typeof
// Or a templated structure // Or a templated structure
// Use uint64* to access parts of uint128 and remove pods
uint128_pod *high_pod = reinterpret_cast<uint128_pod*>(&high); uint128_pod *high_pod = reinterpret_cast<uint128_pod*>(&high);
uint128_pod *mid_pod = reinterpret_cast<uint128_pod*>(&mid); uint128_pod *mid_pod = reinterpret_cast<uint128_pod*>(&mid);
uint128_pod *low_pod = reinterpret_cast<uint128_pod*>(&low); uint128_pod *low_pod = reinterpret_cast<uint128_pod*>(&low);
@ -1201,7 +1201,7 @@ void DataConvert::toString(T* dec, char *p, size_t buflen)
// WIP replace snprintf with streams // WIP replace snprintf with streams
if (high_pod->lo != 0) { if (high_pod->lo != 0) {
printed_chars = snprintf(p, div_log+1, "%lu", high_pod->lo); printed_chars = snprintf(p, div_log+1, "%lu", high_pod->lo);
p += printed_chars; p += printed_chars;
printed_chars = snprintf(p, div_log+1, "%019lu", mid_pod->lo); printed_chars = snprintf(p, div_log+1, "%019lu", mid_pod->lo);
p += printed_chars; p += printed_chars;
} else if (mid_pod->lo != 0) { } else if (mid_pod->lo != 0) {
@ -1215,32 +1215,42 @@ void DataConvert::toString(T* dec, char *p, size_t buflen)
// WIP MCOL-641 // WIP MCOL-641
// Template this // Template this
// result must be calloc-ed // result must be calloc-ed
//template <typename T> void atoi128(const std::string& arg, int128_t& res)
//void atoi_(const string &arg, T &res)
void atoi128(const string& arg, int128_t& res)
{ {
// WIP
//char buf[41];
//int128_t *res_ptr = reinterpret_cast<int128_t*>(result);
res = 0; res = 0;
for (size_t j = 0; j < arg.size(); j++) size_t idx = (arg[0] == '-') ? 1 : 0;
for (size_t j = idx; j < arg.size(); j++)
{ {
// WIP Optimize this // WIP Optimize this
if (LIKELY(arg[j]-'0' >= 0)) if (LIKELY(arg[j]-'0' >= 0))
res = res*10 + arg[j] - '0'; res = res*10 + arg[j] - '0';
} }
// Use bit shift if possible
if (idx)
res *= -1;
//toString(res, buf); //toString(res, buf);
//std::cerr << "atoi_ " << buf <<endl; //std::cerr << "atoi_ " << buf <<endl;
//*res_ptr = res; //*res_ptr = res;
} }
void atoi128(const std::string& arg, uint128_t& res)
{
res = 0;
for (size_t j = 0; j < arg.size(); j++)
{
// WIP Optimize this
if (LIKELY(arg[j]-'0' >= 0))
res = res*10 + arg[j] - '0';
}
}
// WIP MCOL-641 // WIP MCOL-641
template <typename T> template <typename T>
void DataConvert::decimalToString(T* valuePtr, void DataConvert::decimalToString(T* valuePtr,
uint8_t scale, uint8_t scale,
char* buf, char* buf,
unsigned int buflen, unsigned int buflen,
execplan::CalpontSystemCatalog::ColDataType colDataType) cscDataType colDataType)
{ {
toString<T>(valuePtr, buf, buflen); toString<T>(valuePtr, buf, buflen);
@ -1302,19 +1312,23 @@ void DataConvert::decimalToString(T* valuePtr,
} }
// Explicit instantiation // Explicit instantiation
template template
void DataConvert::decimalToString<int128_t>(int128_t* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType); void DataConvert::decimalToString<int128_t>(int128_t* value, uint8_t scale,
char* buf, unsigned int buflen, cscDataType colDataType);
template template
void DataConvert::decimalToString<uint128_t>(uint128_t* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType); void DataConvert::decimalToString<uint128_t>(uint128_t* value, uint8_t scale,
char* buf, unsigned int buflen, cscDataType colDataType);
boost::any boost::any
DataConvert::convertColumnData(const CalpontSystemCatalog::ColType& colType, DataConvert::convertColumnData(const CalpontSystemCatalog::ColType& colType,
const std::string& dataOrig, bool& pushWarning, const std::string& timeZone, bool nulFlag, bool noRoundup, bool isUpdate) const std::string& dataOrig, bool& pushWarning,
const std::string& timeZone, bool nulFlag,
bool noRoundup, bool isUpdate)
{ {
boost::any value; boost::any value;
// WIP // WIP
std::string data( dataOrig ); std::string data( dataOrig );
pushWarning = false; pushWarning = false;
CalpontSystemCatalog::ColDataType type = colType.colDataType; cscDataType type = colType.colDataType;
//if ( !data.empty() ) //if ( !data.empty() )
if (!nulFlag) if (!nulFlag)

View File

@ -84,6 +84,7 @@ inline uint64_t uint64ToStr(uint64_t n)
return htonll(n); return htonll(n);
} }
using cscDataType = execplan::CalpontSystemCatalog::ColDataType;
#if defined(_MSC_VER) && defined(xxxDATACONVERT_DLLEXPORT) #if defined(_MSC_VER) && defined(xxxDATACONVERT_DLLEXPORT)
#define EXPORT __declspec(dllexport) #define EXPORT __declspec(dllexport)
@ -114,7 +115,6 @@ const int64_t IDB_pow[19] =
1000000000000000000LL 1000000000000000000LL
}; };
const int32_t SECS_PER_MIN = 60; const int32_t SECS_PER_MIN = 60;
const int32_t MINS_PER_HOUR = 60; const int32_t MINS_PER_HOUR = 60;
const int32_t HOURS_PER_DAY = 24; const int32_t HOURS_PER_DAY = 24;
@ -134,6 +134,9 @@ const int32_t MIN_TIMESTAMP_VALUE = 0;
namespace dataconvert namespace dataconvert
{ {
using int128_t = __int128;
using uint128_t = unsigned __int128;
enum CalpontDateTimeFormat enum CalpontDateTimeFormat
{ {
CALPONTDATE_ENUM = 1, // date format is: "YYYY-MM-DD" CALPONTDATE_ENUM = 1, // date format is: "YYYY-MM-DD"
@ -157,6 +160,9 @@ struct MySQLTime
} }
}; };
void atoi128(const std::string& arg, int128_t& res);
void atoi128(const std::string& arg, uint128_t& res);
/** /**
* This function converts the timezone represented as a string * This function converts the timezone represented as a string
* in the format "+HH:MM" or "-HH:MM" to a signed offset in seconds * in the format "+HH:MM" or "-HH:MM" to a signed offset in seconds
@ -1009,10 +1015,10 @@ public:
EXPORT static bool isColumnTimeStampValid( int64_t timeStamp ); EXPORT static bool isColumnTimeStampValid( int64_t timeStamp );
EXPORT static bool isNullData(execplan::ColumnResult* cr, int rownum, execplan::CalpontSystemCatalog::ColType colType); 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 std::string decimalToString(int64_t value, uint8_t scale, cscDataType colDataType);
static inline void decimalToString(int64_t value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType); static inline void decimalToString(int64_t value, uint8_t scale, char* buf, unsigned int buflen, cscDataType colDataType);
template <typename T> template <typename T>
EXPORT static void decimalToString(T* value, uint8_t scale, char* buf, unsigned int buflen, execplan::CalpontSystemCatalog::ColDataType colDataType); EXPORT static void decimalToString(T* value, uint8_t scale, char* buf, unsigned int buflen, cscDataType colDataType);
template <typename T> template <typename T>
EXPORT static void toString(T* dec, char *p, size_t buflen); EXPORT static void toString(T* dec, char *p, size_t buflen);
@ -1226,15 +1232,16 @@ inline void DataConvert::timeToString1( long long timevalue, char* buf, unsigned
#endif #endif
} }
inline std::string DataConvert::decimalToString(int64_t value, uint8_t scale, execplan::CalpontSystemCatalog::ColDataType colDataType) inline std::string DataConvert::decimalToString(int64_t value, uint8_t scale, cscDataType colDataType)
{ {
// This is too much
char buf[80]; char buf[80];
DataConvert::decimalToString(value, scale, buf, 80, colDataType); DataConvert::decimalToString(value, scale, buf, 80, colDataType);
return std::string(buf); return std::string(buf);
} }
inline void DataConvert::decimalToString(int64_t int_val, uint8_t scale, char* buf, unsigned int buflen, inline void DataConvert::decimalToString(int64_t int_val, uint8_t scale,
execplan::CalpontSystemCatalog::ColDataType colDataType) char* buf, unsigned int buflen, cscDataType colDataType)
{ {
// Need to convert a string with a binary unsigned number in it to a 64-bit signed int // Need to convert a string with a binary unsigned number in it to a 64-bit signed int

View File

@ -542,7 +542,7 @@ inline bool RowAggregation::isNull(const RowGroup* pRowGroup, const Row& row, in
case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
{ {
row.isNullValue(col); ret = row.isNullValue(col);
break; break;
} }

View File

@ -846,12 +846,12 @@ void Row::initToNull()
break; break;
case 16 : case 16 :
// WIP MCOL-641 {
uint64_t *dec = reinterpret_cast<uint64_t*>(&data[offsets[i]]); uint64_t *dec = reinterpret_cast<uint64_t*>(&data[offsets[i]]);
+ dec[0] = joblist::BINARYNULL; dec[0] = joblist::BINARYNULL;
+ dec[1] = joblist::BINARYNULL; dec[1] = joblist::BINARYNULL;
break; break;
}
default: default:
*((int64_t*) &data[offsets[i]]) = static_cast<int64_t>(joblist::BIGINTNULL); *((int64_t*) &data[offsets[i]]) = static_cast<int64_t>(joblist::BIGINTNULL);
break; break;
@ -1045,15 +1045,15 @@ bool Row::isNullValue(uint32_t colIndex) const
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
{ {
uint32_t len = getColumnWidth(colIndex); uint32_t len = getColumnWidth(colIndex);
const uint64_t *dec; const int64_t *dec;
switch (len) switch (len)
{ {
// MCOL-641 // MCOL-641
case 16: case 16:
dec = reinterpret_cast<const uint64_t*>(&data[offsets[colIndex]]); dec = reinterpret_cast<const int64_t*>(&data[offsets[colIndex]]);
return ((dec[0] == joblist::BINARYNULL) return ((dec[0] == static_cast<int64_t>(joblist::BINARYNULL))
&& (dec[1] == joblist::BINARYNULL)); && (dec[1] == static_cast<int64_t>(joblist::BINARYNULL)));
case 1 : case 1 :
return (data[offsets[colIndex]] == joblist::TINYINTNULL); return (data[offsets[colIndex]] == joblist::TINYINTNULL);