You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
clang format apply
This commit is contained in:
@ -18,7 +18,6 @@
|
||||
|
||||
// $Id: wf_stats.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
@ -49,206 +48,195 @@ using namespace joblist;
|
||||
|
||||
#include "wf_stats.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
template <typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const string& name, int ct,
|
||||
WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
switch (ct)
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
{
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
decltype(datatypes::MAXDECIMALWIDTH) width =
|
||||
wc->functionParms()[0]->resultType().colWidth;
|
||||
if (width < datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (ct == CalpontSystemCatalog::UDECIMAL)
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
else
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
}
|
||||
else if (width == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
func.reset(new WF_stats<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_stats<double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_stats<float>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
func.reset(new WF_stats<long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
return func;
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
decltype(datatypes::MAXDECIMALWIDTH) width = wc->functionParms()[0]->resultType().colWidth;
|
||||
if (width < datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (ct == CalpontSystemCatalog::UDECIMAL)
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
else
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
}
|
||||
else if (width == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
func.reset(new WF_stats<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_stats<double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_stats<float>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
func.reset(new WF_stats<long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
WindowFunctionType* WF_stats<T>::clone() const
|
||||
{
|
||||
return new WF_stats<T>(*this);
|
||||
return new WF_stats<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void WF_stats<T>::resetData()
|
||||
{
|
||||
fSum1 = 0;
|
||||
fSum2 = 0;
|
||||
fCount = 0;
|
||||
fStats = 0.0;
|
||||
fSum1 = 0;
|
||||
fSum2 = 0;
|
||||
fCount = 0;
|
||||
fStats = 0.0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void WF_stats<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
CDT cdt;
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) ||
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
CDT cdt;
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) || (fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
T valIn;
|
||||
getValue(colIn, valIn, &cdt);
|
||||
long double val = (long double)valIn;
|
||||
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn, &cdt);
|
||||
long double val = (long double) valIn;
|
||||
|
||||
fSum1 += val;
|
||||
fSum2 += val * val;
|
||||
fCount++;
|
||||
}
|
||||
|
||||
if (fCount > 1)
|
||||
{
|
||||
uint32_t scale = fRow.getScale(colIn);
|
||||
auto factor = datatypes::scaleDivisor<long double>(scale);
|
||||
long double ldSum1 = fSum1;
|
||||
long double ldSum2 = fSum2;
|
||||
|
||||
// adjust the scale if necessary
|
||||
if (scale != 0 &&
|
||||
cdt != CalpontSystemCatalog::LONGDOUBLE)
|
||||
{
|
||||
ldSum1 /= factor;
|
||||
ldSum2 /= factor * factor;
|
||||
}
|
||||
|
||||
long double stat = ldSum1 * ldSum1 / fCount;
|
||||
stat = ldSum2 - stat;
|
||||
|
||||
if (fFunctionId == WF__STDDEV_POP)
|
||||
stat = sqrt(stat / fCount);
|
||||
else if (fFunctionId == WF__STDDEV_SAMP)
|
||||
stat = sqrt(stat / (fCount - 1));
|
||||
else if (fFunctionId == WF__VAR_POP)
|
||||
stat = stat / fCount;
|
||||
else if (fFunctionId == WF__VAR_SAMP)
|
||||
stat = stat / (fCount - 1);
|
||||
|
||||
fStats = (double) stat;
|
||||
}
|
||||
fSum1 += val;
|
||||
fSum2 += val * val;
|
||||
fCount++;
|
||||
}
|
||||
|
||||
if (fCount == 0)
|
||||
if (fCount > 1)
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*) NULL);
|
||||
}
|
||||
else if (fCount == 1)
|
||||
{
|
||||
if (fFunctionId == WF__STDDEV_SAMP || fFunctionId == WF__VAR_SAMP)
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*) NULL);
|
||||
}
|
||||
else // fFunctionId == WF__STDDEV_POP || fFunctionId == WF__VAR_POP
|
||||
{
|
||||
double temp = 0.0;
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*) &temp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, &fStats);
|
||||
}
|
||||
uint32_t scale = fRow.getScale(colIn);
|
||||
auto factor = datatypes::scaleDivisor<long double>(scale);
|
||||
long double ldSum1 = fSum1;
|
||||
long double ldSum2 = fSum2;
|
||||
|
||||
fPrev = c;
|
||||
// adjust the scale if necessary
|
||||
if (scale != 0 && cdt != CalpontSystemCatalog::LONGDOUBLE)
|
||||
{
|
||||
ldSum1 /= factor;
|
||||
ldSum2 /= factor * factor;
|
||||
}
|
||||
|
||||
long double stat = ldSum1 * ldSum1 / fCount;
|
||||
stat = ldSum2 - stat;
|
||||
|
||||
if (fFunctionId == WF__STDDEV_POP)
|
||||
stat = sqrt(stat / fCount);
|
||||
else if (fFunctionId == WF__STDDEV_SAMP)
|
||||
stat = sqrt(stat / (fCount - 1));
|
||||
else if (fFunctionId == WF__VAR_POP)
|
||||
stat = stat / fCount;
|
||||
else if (fFunctionId == WF__VAR_SAMP)
|
||||
stat = stat / (fCount - 1);
|
||||
|
||||
fStats = (double)stat;
|
||||
}
|
||||
}
|
||||
|
||||
if (fCount == 0)
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*)NULL);
|
||||
}
|
||||
else if (fCount == 1)
|
||||
{
|
||||
if (fFunctionId == WF__STDDEV_SAMP || fFunctionId == WF__VAR_SAMP)
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*)NULL);
|
||||
}
|
||||
else // fFunctionId == WF__STDDEV_POP || fFunctionId == WF__VAR_POP
|
||||
{
|
||||
double temp = 0.0;
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*)&temp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, &fStats);
|
||||
}
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
template boost::shared_ptr<WindowFunctionType> WF_stats<int64_t>::makeFunction(int, const string&, int,
|
||||
WindowFunctionColumn*);
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
} // namespace windowfunction
|
||||
// vim:ts=4 sw=4:
|
||||
|
||||
|
Reference in New Issue
Block a user