You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
clang format apply
This commit is contained in:
@ -17,7 +17,6 @@
|
||||
|
||||
// $Id: wf_ranking.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
@ -48,110 +47,102 @@ using namespace joblist;
|
||||
|
||||
#include "wf_ranking.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_ranking::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
boost::shared_ptr<WindowFunctionType> WF_ranking::makeFunction(int id, const string& name, int ct,
|
||||
WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ranking(id, name));
|
||||
return func;
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ranking(id, name));
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
WindowFunctionType* WF_ranking::clone() const
|
||||
{
|
||||
return new WF_ranking(*this);
|
||||
return new WF_ranking(*this);
|
||||
}
|
||||
|
||||
|
||||
void WF_ranking::resetData()
|
||||
{
|
||||
fRank = 0;
|
||||
fDups = 0;
|
||||
fRank = 0;
|
||||
fDups = 0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
void WF_ranking::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
// one row handling
|
||||
if (fPartition.first == fPartition.second)
|
||||
// one row handling
|
||||
if (fPartition.first == fPartition.second)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(fPartition.first)));
|
||||
int64_t r = (fFunctionId == WF__PERCENT_RANK) ? 0 : 1;
|
||||
|
||||
if (fFunctionId == WF__RANK || fFunctionId == WF__DENSE_RANK)
|
||||
setIntValue(fFieldIndex[0], r);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], r);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// more than one row, e > b
|
||||
b = fPartition.first;
|
||||
e = fPartition.second;
|
||||
double n1 = e - b; // count(*) - 1, n will not be 0.
|
||||
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
if (c != b && fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c - 1))))
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(fPartition.first)));
|
||||
int64_t r = (fFunctionId == WF__PERCENT_RANK) ? 0 : 1;
|
||||
fDups++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fRank++;
|
||||
|
||||
if (fFunctionId == WF__RANK || fFunctionId == WF__DENSE_RANK)
|
||||
setIntValue(fFieldIndex[0], r);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], r);
|
||||
if (fFunctionId != WF__DENSE_RANK)
|
||||
fRank += fDups;
|
||||
|
||||
return;
|
||||
fDups = 0;
|
||||
}
|
||||
|
||||
// more than one row, e > b
|
||||
b = fPartition.first;
|
||||
e = fPartition.second;
|
||||
double n1 = e - b; // count(*) - 1, n will not be 0.
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
|
||||
for (c = b; c <= e; c++)
|
||||
if (fFunctionId != WF__PERCENT_RANK)
|
||||
setIntValue(fFieldIndex[0], fRank);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], (fRank - 1) / n1);
|
||||
}
|
||||
|
||||
// Two-pass, need to find peers.
|
||||
if (fFunctionId == WF__CUME_DIST)
|
||||
{
|
||||
int prevRank = ++fRank + fDups; // hypothetical row at (e+1)
|
||||
double n0 = (e - b + 1); // count(*)
|
||||
double cumeDist = 1;
|
||||
fRow.setData(getPointer(fRowData->at(e)));
|
||||
|
||||
for (c = e; c >= b; c--)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
if (c != b &&
|
||||
fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c - 1))))
|
||||
{
|
||||
fDups++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fRank++;
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
int currRank = getIntValue(fFieldIndex[0]);
|
||||
|
||||
if (fFunctionId != WF__DENSE_RANK)
|
||||
fRank += fDups;
|
||||
if (currRank != prevRank)
|
||||
{
|
||||
cumeDist = ((double)(prevRank - 1)) / n0;
|
||||
prevRank = currRank;
|
||||
}
|
||||
|
||||
fDups = 0;
|
||||
}
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
|
||||
if (fFunctionId != WF__PERCENT_RANK)
|
||||
setIntValue(fFieldIndex[0], fRank);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], (fRank - 1) / n1);
|
||||
}
|
||||
|
||||
// Two-pass, need to find peers.
|
||||
if (fFunctionId == WF__CUME_DIST)
|
||||
{
|
||||
int prevRank = ++fRank + fDups; // hypothetical row at (e+1)
|
||||
double n0 = (e - b + 1); // count(*)
|
||||
double cumeDist = 1;
|
||||
fRow.setData(getPointer(fRowData->at(e)));
|
||||
|
||||
for (c = e; c >= b; c--)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
int currRank = getIntValue(fFieldIndex[0]);
|
||||
|
||||
if (currRank != prevRank)
|
||||
{
|
||||
cumeDist = ((double) (prevRank - 1)) / n0;
|
||||
prevRank = currRank;
|
||||
}
|
||||
|
||||
setDoubleValue(fFieldIndex[0], cumeDist);
|
||||
}
|
||||
setDoubleValue(fFieldIndex[0], cumeDist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
} // namespace windowfunction
|
||||
// vim:ts=4 sw=4:
|
||||
|
||||
|
Reference in New Issue
Block a user