You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
MCOL-4171 Some fixes
This commit is contained in:
committed by
Roman Nozdrin
parent
5b8aba0005
commit
af80081c94
@ -82,7 +82,7 @@ constexpr uint8_t MAXLEGACYWIDTH = 8U;
|
|||||||
constexpr uint8_t MAXSCALEINC4AVG = 4U;
|
constexpr uint8_t MAXSCALEINC4AVG = 4U;
|
||||||
constexpr int8_t IGNOREPRECISION = -1;
|
constexpr int8_t IGNOREPRECISION = -1;
|
||||||
|
|
||||||
const uint64_t mcs_pow_10[20] =
|
const int64_t mcs_pow_10[19] =
|
||||||
{
|
{
|
||||||
1ULL,
|
1ULL,
|
||||||
10ULL,
|
10ULL,
|
||||||
@ -103,9 +103,8 @@ const uint64_t mcs_pow_10[20] =
|
|||||||
10000000000000000ULL,
|
10000000000000000ULL,
|
||||||
100000000000000000ULL,
|
100000000000000000ULL,
|
||||||
1000000000000000000ULL,
|
1000000000000000000ULL,
|
||||||
10000000000000000000ULL
|
|
||||||
};
|
};
|
||||||
const uint128_t mcs_pow_10_128[20] =
|
const int128_t mcs_pow_10_128[20] =
|
||||||
{
|
{
|
||||||
10000000000000000000_xxl,
|
10000000000000000000_xxl,
|
||||||
100000000000000000000_xxl,
|
100000000000000000000_xxl,
|
||||||
@ -126,7 +125,7 @@ const uint128_t mcs_pow_10_128[20] =
|
|||||||
100000000000000000000000000000000000_xxl,
|
100000000000000000000000000000000000_xxl,
|
||||||
1000000000000000000000000000000000000_xxl,
|
1000000000000000000000000000000000000_xxl,
|
||||||
10000000000000000000000000000000000000_xxl,
|
10000000000000000000000000000000000000_xxl,
|
||||||
100000000000000000000000000000000000000_xxl
|
100000000000000000000000000000000000000_xxl,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr uint32_t maxPowOf10 = sizeof(mcs_pow_10)/sizeof(mcs_pow_10[0])-1;
|
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);
|
std::string msg = "getScaleDivisor called with negative scale: " + std::to_string(scale);
|
||||||
throw std::invalid_argument(msg);
|
throw std::invalid_argument(msg);
|
||||||
}
|
}
|
||||||
if (scale < 19)
|
else if (scale < 19)
|
||||||
{
|
{
|
||||||
divisor = mcs_pow_10[scale];
|
divisor = mcs_pow_10[scale];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
divisor = mcs_pow_10_128[scale-18];
|
divisor = mcs_pow_10_128[scale-19];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using int128_t = __int128;
|
using int128_t = __int128;
|
||||||
|
using uint128_t = unsigned __int128;
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
|
@ -419,8 +419,9 @@ public:
|
|||||||
inline void setDoubleField(double val, uint32_t colIndex);
|
inline void setDoubleField(double val, uint32_t colIndex);
|
||||||
inline void setFloatField(float 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 setDecimalField(double val, uint32_t colIndex) { }; // TODO: Do something here
|
||||||
inline void setLongDoubleField(long double val, uint32_t colIndex);
|
inline void setLongDoubleField(const long double& val, uint32_t colIndex);
|
||||||
inline void setInt128Field(int128_t 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);
|
inline void setRid(uint64_t rid);
|
||||||
|
|
||||||
@ -1167,7 +1168,7 @@ inline void Row::setFloatField(float val, uint32_t colIndex)
|
|||||||
*((float*) &data[offsets[colIndex]]) = val;
|
*((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]];
|
uint8_t* p = &data[offsets[colIndex]];
|
||||||
*((long double*)p) = val;
|
*((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;
|
*((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)
|
inline void Row::setVarBinaryField(const std::string& val, uint32_t colIndex)
|
||||||
{
|
{
|
||||||
if (inStringTable(colIndex))
|
if (inStringTable(colIndex))
|
||||||
|
@ -191,12 +191,15 @@ void WF_lead_lag<T>::parseParms(const std::vector<execplan::SRCP>& parms)
|
|||||||
|
|
||||||
// parms[3]: respect null | ignore null
|
// parms[3]: respect null | ignore null
|
||||||
cc = dynamic_cast<ConstantColumn*>(parms[3].get());
|
cc = dynamic_cast<ConstantColumn*>(parms[3].get());
|
||||||
idbassert(cc != NULL);
|
if (cc != NULL)
|
||||||
bool isNull = false; // dummy, harded coded
|
{
|
||||||
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
|
bool isNull = false; // dummy. Return not used
|
||||||
|
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
|
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)
|
if (!fOffsetNull)
|
||||||
{
|
{
|
||||||
implicit2T(idx, tmp, 0);
|
implicit2T(idx, tmp, 0);
|
||||||
|
fOffset = round(tmp);
|
||||||
if (tmp > e) // prevent integer overflow
|
|
||||||
tmp = e + 1;
|
|
||||||
else if (tmp + e < 0)
|
|
||||||
tmp += e - 1;
|
|
||||||
|
|
||||||
fOffset = (int64_t) tmp;
|
|
||||||
fOffset *= fLead;
|
fOffset *= fLead;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,23 +215,10 @@ void WF_nth_value<T>::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
if (!fNthNull)
|
if (!fNthNull)
|
||||||
{
|
{
|
||||||
implicit2T(idx, tmp, 0);
|
implicit2T(idx, tmp, 0);
|
||||||
|
fNth = round(tmp);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isNull = true;
|
bool isNull = true;
|
||||||
|
|
||||||
if ((!fNthNull) && ((b + fNth - 1) <= e))
|
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;
|
int64_t n = k + fNth - 1;
|
||||||
|
|
||||||
if (n <= e)
|
if (n <= e && n >= 0)
|
||||||
{
|
{
|
||||||
fRow.setData(getPointer(fRowData->at(n)));
|
fRow.setData(getPointer(fRowData->at(n)));
|
||||||
getValue(colIn, fValue);
|
getValue(colIn, fValue);
|
||||||
|
@ -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);
|
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp > e) // prevent integer overflow
|
fNtile = round(tmp);
|
||||||
tmp = e + 1;
|
|
||||||
|
|
||||||
fNtile = (int64_t) tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
|
|||||||
{
|
{
|
||||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
|
|||||||
{
|
{
|
||||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -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>
|
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 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 = 0;
|
||||||
int128_t avg;
|
int128_t factor;
|
||||||
|
datatypes::getScaleDivisor(factor, scale);
|
||||||
if (scale > 0)
|
if (scale > 0)
|
||||||
{
|
{
|
||||||
if ((sum * factor) / factor == sum)
|
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>
|
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 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 = 0;
|
||||||
uint128_t avg = sum;
|
uint128_t factor;
|
||||||
|
datatypes::getScaleDivisor(factor, scale);
|
||||||
if (scale > 0)
|
if (scale > 0)
|
||||||
{
|
{
|
||||||
if ((sum * factor) / factor == sum)
|
if ((sum * factor) / factor == sum)
|
||||||
|
@ -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& uintTypeId = (unsigned int)1;
|
||||||
static const static_any::any& ulongTypeId = (unsigned long)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& 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& floatTypeId = (float)1;
|
||||||
static const static_any::any& doubleTypeId = (double)1;
|
static const static_any::any& doubleTypeId = (double)1;
|
||||||
static const std::string typeStr("");
|
static const std::string typeStr("");
|
||||||
|
@ -362,6 +362,11 @@ template<> void WindowFunctionType::setValue<int128_t>(uint64_t i, int128_t& t)
|
|||||||
fRow.setInt128Field(t, i);
|
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)
|
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
|
||||||
{
|
{
|
||||||
fRow.setStringField(t, i);
|
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:
|
case CalpontSystemCatalog::DECIMAL:
|
||||||
{
|
{
|
||||||
int128_t iv = *v;
|
if (sizeof(T) == 8)
|
||||||
setValue(i, iv);
|
{
|
||||||
|
int64_t iv = *v;
|
||||||
|
setValue(i, iv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int128_t iv = *v;
|
||||||
|
setValue(i, iv);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CalpontSystemCatalog::UDECIMAL:
|
case CalpontSystemCatalog::UDECIMAL:
|
||||||
{
|
{
|
||||||
uint128_t uv = *v;
|
if (sizeof(T) == 8)
|
||||||
setValue(i, uv);
|
{
|
||||||
|
uint64_t iv = *v;
|
||||||
|
setValue(i, iv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint128_t iv = *v;
|
||||||
|
setValue(i, iv);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,7 +501,6 @@ template<typename T>
|
|||||||
void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||||
{
|
{
|
||||||
int ct = fRow.getColType(i);
|
int ct = fRow.getColType(i);
|
||||||
int64_t divisor = 1;
|
|
||||||
|
|
||||||
switch (ct)
|
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
|
s -= fRow.getScale(i); // we scale only the difference of scales
|
||||||
datatypes::getScaleDivisor(divisor, abs(s));
|
datatypes::getScaleDivisor(divisor, abs(s));
|
||||||
if (s > 0)
|
if (s > 0)
|
||||||
t *= divisor;
|
t *= divisor;
|
||||||
else if (s < 0)
|
else if (s < 0)
|
||||||
t /= divisor;
|
t /= divisor;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -250,7 +250,7 @@ protected:
|
|||||||
{
|
{
|
||||||
fRow.setDoubleField(v, i);
|
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);
|
fRow.setLongDoubleField(v, i);
|
||||||
}
|
}
|
||||||
|
@ -845,6 +845,9 @@ inline void allocateValArray(void*& valArray, ColTupleList::size_type totalRow,
|
|||||||
case WriteEngine::WR_TEXT:
|
case WriteEngine::WR_TEXT:
|
||||||
valArray = (char*) calloc(sizeof(char), totalRow * MAX_COLUMN_BOUNDARY);
|
valArray = (char*) calloc(sizeof(char), totalRow * MAX_COLUMN_BOUNDARY);
|
||||||
break;
|
break;
|
||||||
|
case WriteEngine::WR_TOKEN:
|
||||||
|
valArray = (Token*) calloc(sizeof(Token), totalRow);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
valArray = calloc(totalRow, colWidth);
|
valArray = calloc(totalRow, colWidth);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user