1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -54,213 +54,232 @@ namespace windowfunction
template<typename T>
boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const string& name, int ct)
{
boost::shared_ptr<WindowFunctionType> func;
switch (ct)
{
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::BIGINT:
case CalpontSystemCatalog::DECIMAL:
{
func.reset(new WF_lead_lag<int64_t>(id, name));
break;
}
case CalpontSystemCatalog::UTINYINT:
case CalpontSystemCatalog::USMALLINT:
case CalpontSystemCatalog::UMEDINT:
case CalpontSystemCatalog::UINT:
case CalpontSystemCatalog::UBIGINT:
case CalpontSystemCatalog::UDECIMAL:
case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME:
{
func.reset(new WF_lead_lag<uint64_t>(id, name));
break;
}
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
{
func.reset(new WF_lead_lag<double>(id, name));
break;
}
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
func.reset(new WF_lead_lag<float>(id, name));
break;
}
default:
{
func.reset(new WF_lead_lag<string>(id, name));
break;
}
}
boost::shared_ptr<WindowFunctionType> func;
return func;
switch (ct)
{
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::BIGINT:
case CalpontSystemCatalog::DECIMAL:
{
func.reset(new WF_lead_lag<int64_t>(id, name));
break;
}
case CalpontSystemCatalog::UTINYINT:
case CalpontSystemCatalog::USMALLINT:
case CalpontSystemCatalog::UMEDINT:
case CalpontSystemCatalog::UINT:
case CalpontSystemCatalog::UBIGINT:
case CalpontSystemCatalog::UDECIMAL:
case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME:
{
func.reset(new WF_lead_lag<uint64_t>(id, name));
break;
}
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
{
func.reset(new WF_lead_lag<double>(id, name));
break;
}
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
func.reset(new WF_lead_lag<float>(id, name));
break;
}
default:
{
func.reset(new WF_lead_lag<string>(id, name));
break;
}
}
return func;
}
template<typename T>
WindowFunctionType* WF_lead_lag<T>::clone() const
{
return new WF_lead_lag<T>(*this);
return new WF_lead_lag<T>(*this);
}
template<typename T>
void WF_lead_lag<T>::resetData()
{
WindowFunctionType::resetData();
WindowFunctionType::resetData();
}
template<typename T>
void WF_lead_lag<T>::parseParms(const std::vector<execplan::SRCP>& parms)
{
// lead | lag
fLead = 1;
// lead | lag
fLead = 1;
fRespectNulls = true;
fDefNull = false;
fDefault = (T)0;
fOffsetNull = false;
fOffset = 0;
if (fFunctionId == WF__LAG)
fLead = -1;
// parms[0]: value-expr
// skip
if (fFunctionId == WF__LAG)
fLead = -1;
// parms[1]: offset
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[1].get());
if (cc != NULL)
{
fOffsetNull = false;
fOffset = cc->getIntVal(fRow, fOffsetNull) * fLead; // row not used, no need to setData.
}
// parms[0]: value-expr
// skip
// parms[2]: default value
cc = dynamic_cast<ConstantColumn*>(parms[2].get());
if (cc != NULL)
{
fDefNull = false;
getConstValue(cc, fDefault, fDefNull);
}
// parms[1]: offset
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[1].get());
// 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)
{
fOffsetNull = false;
fOffset = cc->getIntVal(fRow, fOffsetNull) * fLead; // row not used, no need to setData.
}
// parms[2]: default value
cc = dynamic_cast<ConstantColumn*>(parms[2].get());
if (cc != NULL)
{
fDefNull = false;
getConstValue(cc, fDefault, fDefNull);
}
// 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);
}
template<typename T>
void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
{
uint64_t colIn = fFieldIndex[1];
bool isNull = true;
for (int64_t c = b; c <= e; c++)
{
if (c % 1000 == 0 && fStep->cancelled())
break;
uint64_t colIn = fFieldIndex[1];
bool isNull = true;
fRow.setData(getPointer(fRowData->at(c)));
// get offset if not constant
int64_t idx = fFieldIndex[2];
if (idx != -1)
{
double tmp = 0.0; // use double to cover all column types
fOffsetNull = fRow.isNullValue(idx);
if (!fOffsetNull)
{
implicit2T(idx, tmp, 0);
for (int64_t c = b; c <= e; c++)
{
if (c % 1000 == 0 && fStep->cancelled())
break;
if (tmp > e) // prevent integer overflow
tmp = e + 1;
else if (tmp + e < 0)
tmp += e - 1;
fRow.setData(getPointer(fRowData->at(c)));
// get offset if not constant
int64_t idx = fFieldIndex[2];
fOffset = (int64_t) tmp;
fOffset *= fLead;
}
}
if (idx != -1)
{
double tmp = 0.0; // use double to cover all column types
fOffsetNull = fRow.isNullValue(idx);
// get default if not constant
idx = fFieldIndex[3];
if (idx != -1)
{
fDefNull = fRow.isNullValue(idx);
if (!fDefNull)
implicit2T(idx, fDefault, (int) fRow.getScale(idx));
}
if (!fOffsetNull)
{
implicit2T(idx, tmp, 0);
int64_t o = c + fOffset;
if (o < b || o > e || fOffsetNull) // out of bound
{
T* v = (fDefNull) ? NULL : &fDefault;
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
continue;
}
if (tmp > e) // prevent integer overflow
tmp = e + 1;
else if (tmp + e < 0)
tmp += e - 1;
if (fRespectNulls == false && fRow.isNullValue(colIn) == true)
{
if(fOffset > 0)
{
while (++o < e)
{
fRow.setData(getPointer(fRowData->at(o)));
if (fRow.isNullValue(colIn) == false)
break;
}
fOffset = (int64_t) tmp;
fOffset *= fLead;
}
}
if (o <= e)
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
}
}
else if (fOffset < 0)
{
while (--o > b)
{
fRow.setData(getPointer(fRowData->at(o)));
if (fRow.isNullValue(colIn) == false)
break;
}
// get default if not constant
idx = fFieldIndex[3];
if (o >= b)
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
}
}
if (idx != -1)
{
fDefNull = fRow.isNullValue(idx);
T* v = NULL;
if (!isNull)
v = &fValue;
else if (!fDefNull)
v = &fDefault;
if (!fDefNull)
implicit2T(idx, fDefault, (int) fRow.getScale(idx));
}
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
}
else
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
int64_t o = c + fOffset;
T* v = NULL;
if (!isNull)
v = &fValue;
else if (!fDefNull)
v = &fDefault;
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
}
}
if (o < b || o > e || fOffsetNull) // out of bound
{
T* v = (fDefNull) ? NULL : &fDefault;
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
continue;
}
if (fRespectNulls == false && fRow.isNullValue(colIn) == true)
{
if (fOffset > 0)
{
while (++o < e)
{
fRow.setData(getPointer(fRowData->at(o)));
if (fRow.isNullValue(colIn) == false)
break;
}
if (o <= e)
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
}
}
else if (fOffset < 0)
{
while (--o > b)
{
fRow.setData(getPointer(fRowData->at(o)));
if (fRow.isNullValue(colIn) == false)
break;
}
if (o >= b)
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
}
}
T* v = NULL;
if (!isNull)
v = &fValue;
else if (!fDefNull)
v = &fDefault;
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
}
else
{
fRow.setData(getPointer(fRowData->at(o)));
getValue(colIn, fValue);
isNull = fRow.isNullValue(colIn);
T* v = NULL;
if (!isNull)
v = &fValue;
else if (!fDefNull)
v = &fDefault;
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
}
}
}