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

MCOL-4171 Some fixes

This commit is contained in:
David Hall
2020-08-13 09:54:01 -05:00
committed by Roman Nozdrin
parent 5b8aba0005
commit af80081c94
12 changed files with 65 additions and 54 deletions

View File

@ -82,7 +82,7 @@ constexpr uint8_t MAXLEGACYWIDTH = 8U;
constexpr uint8_t MAXSCALEINC4AVG = 4U;
constexpr int8_t IGNOREPRECISION = -1;
const uint64_t mcs_pow_10[20] =
const int64_t mcs_pow_10[19] =
{
1ULL,
10ULL,
@ -103,9 +103,8 @@ const uint64_t mcs_pow_10[20] =
10000000000000000ULL,
100000000000000000ULL,
1000000000000000000ULL,
10000000000000000000ULL
};
const uint128_t mcs_pow_10_128[20] =
const int128_t mcs_pow_10_128[20] =
{
10000000000000000000_xxl,
100000000000000000000_xxl,
@ -126,7 +125,7 @@ const uint128_t mcs_pow_10_128[20] =
100000000000000000000000000000000000_xxl,
1000000000000000000000000000000000000_xxl,
10000000000000000000000000000000000000_xxl,
100000000000000000000000000000000000000_xxl
100000000000000000000000000000000000000_xxl,
};
constexpr uint32_t maxPowOf10 = sizeof(mcs_pow_10)/sizeof(mcs_pow_10[0])-1;
@ -146,13 +145,13 @@ inline void getScaleDivisor(T& divisor, const int8_t scale)
std::string msg = "getScaleDivisor called with negative scale: " + std::to_string(scale);
throw std::invalid_argument(msg);
}
if (scale < 19)
else if (scale < 19)
{
divisor = mcs_pow_10[scale];
}
else
{
divisor = mcs_pow_10_128[scale-18];
divisor = mcs_pow_10_128[scale-19];
}
}

View File

@ -31,6 +31,7 @@
#include <string.h>
using int128_t = __int128;
using uint128_t = unsigned __int128;
namespace utils
{

View File

@ -419,8 +419,9 @@ public:
inline void setDoubleField(double val, uint32_t colIndex);
inline void setFloatField(float val, uint32_t colIndex);
inline void setDecimalField(double val, uint32_t colIndex) { }; // TODO: Do something here
inline void setLongDoubleField(long double val, uint32_t colIndex);
inline void setInt128Field(int128_t val, uint32_t colIndex);
inline void setLongDoubleField(const long double& val, uint32_t colIndex);
inline void setInt128Field(const int128_t& val, uint32_t colIndex);
inline void setUint128Field(const uint128_t& val, uint32_t colIndex);
inline void setRid(uint64_t rid);
@ -1167,7 +1168,7 @@ inline void Row::setFloatField(float val, uint32_t colIndex)
*((float*) &data[offsets[colIndex]]) = val;
}
inline void Row::setLongDoubleField(long double val, uint32_t colIndex)
inline void Row::setLongDoubleField(const long double& val, uint32_t colIndex)
{
uint8_t* p = &data[offsets[colIndex]];
*((long double*)p) = val;
@ -1178,11 +1179,16 @@ inline void Row::setLongDoubleField(long double val, uint32_t colIndex)
}
}
inline void Row::setInt128Field(int128_t val, uint32_t colIndex)
inline void Row::setInt128Field(const int128_t& val, uint32_t colIndex)
{
*((int128_t*)&data[offsets[colIndex]]) = val;
}
inline void Row::setUint128Field(const uint128_t& val, uint32_t colIndex)
{
*((uint128_t*)&data[offsets[colIndex]]) = val;
}
inline void Row::setVarBinaryField(const std::string& val, uint32_t colIndex)
{
if (inStringTable(colIndex))

View File

@ -191,12 +191,15 @@ void WF_lead_lag<T>::parseParms(const std::vector<execplan::SRCP>& parms)
// parms[3]: respect null | ignore null
cc = dynamic_cast<ConstantColumn*>(parms[3].get());
idbassert(cc != NULL);
bool isNull = false; // dummy, harded coded
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
if (cc != NULL)
{
bool isNull = false; // dummy. Return not used
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
}
}
template<typename T>
void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
{
@ -220,13 +223,7 @@ void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
if (!fOffsetNull)
{
implicit2T(idx, tmp, 0);
if (tmp > e) // prevent integer overflow
tmp = e + 1;
else if (tmp + e < 0)
tmp += e - 1;
fOffset = (int64_t) tmp;
fOffset = round(tmp);
fOffset *= fLead;
}
}

View File

@ -215,23 +215,10 @@ void WF_nth_value<T>::operator()(int64_t b, int64_t e, int64_t c)
if (!fNthNull)
{
implicit2T(idx, tmp, 0);
if (tmp <= 0)
{
ostringstream oss;
oss << tmp;
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
}
if (tmp > e) // prevent integer overflow
tmp = e + 1;
fNth = (int64_t) tmp;
fNth = round(tmp);
}
}
bool isNull = true;
if ((!fNthNull) && ((b + fNth - 1) <= e))
@ -256,7 +243,7 @@ void WF_nth_value<T>::operator()(int64_t b, int64_t e, int64_t c)
int64_t n = k + fNth - 1;
if (n <= e)
if (n <= e && n >= 0)
{
fRow.setData(getPointer(fRowData->at(n)));
getValue(colIn, fValue);

View File

@ -118,10 +118,7 @@ void WF_ntile::operator()(int64_t b, int64_t e, int64_t c)
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
}
if (tmp > e) // prevent integer overflow
tmp = e + 1;
fNtile = (int64_t) tmp;
fNtile = round(tmp);
}
}

View File

@ -92,7 +92,7 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_percentile<int128_t>(id, name));
func.reset(new WF_percentile<int64_t>(id, name));
}
else
{
@ -105,7 +105,7 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_percentile<uint128_t>(id, name));
func.reset(new WF_percentile<uint64_t>(id, name));
}
else
{

View File

@ -85,8 +85,9 @@ inline void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(uint128_t val, uint128_t sum)
template<typename T_IN, typename T_OUT>
int128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(int128_t sum, uint64_t count, int scale)
{
int128_t factor = pow(10.0, scale);
int128_t avg;
int128_t avg = 0;
int128_t factor;
datatypes::getScaleDivisor(factor, scale);
if (scale > 0)
{
if ((sum * factor) / factor == sum)
@ -120,8 +121,9 @@ int128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(int128_t sum, uint64_t count, int
template<typename T_IN, typename T_OUT>
uint128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(uint128_t sum, uint64_t count, int scale)
{
uint128_t factor = pow(10.0, scale);
uint128_t avg = sum;
uint128_t avg = 0;
uint128_t factor;
datatypes::getScaleDivisor(factor, scale);
if (scale > 0)
{
if ((sum * factor) / factor == sum)

View File

@ -550,7 +550,7 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
static const static_any::any& uintTypeId = (unsigned int)1;
static const static_any::any& ulongTypeId = (unsigned long)1;
static const static_any::any& ullTypeId = (unsigned long long)1;
static const static_any::any& uint128TypeId = (int128_t)1;
static const static_any::any& uint128TypeId = (uint128_t)1;
static const static_any::any& floatTypeId = (float)1;
static const static_any::any& doubleTypeId = (double)1;
static const std::string typeStr("");

View File

@ -362,6 +362,11 @@ template<> void WindowFunctionType::setValue<int128_t>(uint64_t i, int128_t& t)
fRow.setInt128Field(t, i);
}
template<> void WindowFunctionType::setValue<uint128_t>(uint64_t i, uint128_t& t)
{
fRow.setUint128Field(t, i);
}
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
{
fRow.setStringField(t, i);
@ -433,15 +438,31 @@ void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
case CalpontSystemCatalog::DECIMAL:
{
int128_t iv = *v;
setValue(i, iv);
if (sizeof(T) == 8)
{
int64_t iv = *v;
setValue(i, iv);
}
else
{
int128_t iv = *v;
setValue(i, iv);
}
break;
}
case CalpontSystemCatalog::UDECIMAL:
{
uint128_t uv = *v;
setValue(i, uv);
if (sizeof(T) == 8)
{
uint64_t iv = *v;
setValue(i, iv);
}
else
{
uint128_t iv = *v;
setValue(i, iv);
}
break;
}
@ -480,7 +501,6 @@ template<typename T>
void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
{
int ct = fRow.getColType(i);
int64_t divisor = 1;
switch (ct)
{
@ -557,14 +577,13 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
}
}
T divisor = 1;
s -= fRow.getScale(i); // we scale only the difference of scales
datatypes::getScaleDivisor(divisor, abs(s));
if (s > 0)
t *= divisor;
else if (s < 0)
t /= divisor;
}
template<>

View File

@ -250,7 +250,7 @@ protected:
{
fRow.setDoubleField(v, i);
}
void setLongDoubleValue(int64_t i, long double v)
void setLongDoubleValue(int64_t i, const long double& v)
{
fRow.setLongDoubleField(v, i);
}

View File

@ -845,6 +845,9 @@ inline void allocateValArray(void*& valArray, ColTupleList::size_type totalRow,
case WriteEngine::WR_TEXT:
valArray = (char*) calloc(sizeof(char), totalRow * MAX_COLUMN_BOUNDARY);
break;
case WriteEngine::WR_TOKEN:
valArray = (Token*) calloc(sizeof(Token), totalRow);
break;
default:
valArray = calloc(totalRow, colWidth);
break;