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

@ -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);
}