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

@ -42,46 +42,50 @@ namespace
using namespace funcexp;
DateTime getDateTime(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull)
FunctionParm& parm,
bool& isNull)
{
int64_t val;
switch (parm[0]->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::DECIMAL:
{
double value = parm[0]->data()->getDoubleVal(row, isNull);
if (value > 0)
value += 0.5;
else if (value < 0)
value -= 0.5;
val = (int64_t)value;
break;
}
default:
val = parm[0]->data()->getDatetimeIntVal(row, isNull);
}
if (val < 0 || val > helpers::TIMESTAMP_MAX_VALUE)
return 0;
int64_t val;
DateTime dt;
switch (parm[0]->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::DECIMAL:
{
double value = parm[0]->data()->getDoubleVal(row, isNull);
struct tm tmp_tm;
time_t tmp_t= (time_t)val;
localtime_r(&tmp_t, &tmp_tm);
if (value > 0)
value += 0.5;
else if (value < 0)
value -= 0.5;
//to->neg=0;
dt.year = (int64_t) ((tmp_tm.tm_year+1900) % 10000);
dt.month = (int64_t) tmp_tm.tm_mon+1;
dt.day = (int64_t) tmp_tm.tm_mday;
dt.hour = (int64_t) tmp_tm.tm_hour;
dt.minute = (int64_t) tmp_tm.tm_min;
dt.second = (int64_t) tmp_tm.tm_sec;
dt.msecond = 0;
return dt;
val = (int64_t)value;
break;
}
default:
val = parm[0]->data()->getDatetimeIntVal(row, isNull);
}
if (val < 0 || val > helpers::TIMESTAMP_MAX_VALUE)
return 0;
DateTime dt;
struct tm tmp_tm;
time_t tmp_t = (time_t)val;
localtime_r(&tmp_t, &tmp_tm);
//to->neg=0;
dt.year = (int64_t) ((tmp_tm.tm_year + 1900) % 10000);
dt.month = (int64_t) tmp_tm.tm_mon + 1;
dt.day = (int64_t) tmp_tm.tm_mday;
dt.hour = (int64_t) tmp_tm.tm_hour;
dt.minute = (int64_t) tmp_tm.tm_min;
dt.second = (int64_t) tmp_tm.tm_sec;
dt.msecond = 0;
return dt;
}
}
@ -90,96 +94,103 @@ namespace funcexp
CalpontSystemCatalog::ColType Func_from_unixtime::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
{
CalpontSystemCatalog::ColType ct;
ct.colDataType = CalpontSystemCatalog::VARCHAR;
ct.colWidth = 255;
return ct;
CalpontSystemCatalog::ColType ct;
ct.colDataType = CalpontSystemCatalog::VARCHAR;
ct.colWidth = 255;
return ct;
}
string Func_from_unixtime::getStrVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return "";
}
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
DateTime dt = getDateTime(row, parm, isNull);
if (parm.size() == 2)
{
const string& format = parm[1]->data()->getStrVal(row, isNull);
return helpers::IDB_date_format(dt, format);
}
char buf[256] = {0};
DataConvert::datetimeToString(*(reinterpret_cast<int64_t*>(&dt)), buf, 255);
return string(buf, 255);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return "";
}
if (parm.size() == 2)
{
const string& format = parm[1]->data()->getStrVal(row, isNull);
return helpers::IDB_date_format(dt, format);
}
char buf[256] = {0};
DataConvert::datetimeToString(*(reinterpret_cast<int64_t*>(&dt)), buf, 255);
return string(buf, 255);
}
int32_t Func_from_unixtime::getDateIntVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
return (((getDatetimeIntVal(row, parm, isNull, ct) >> 32) & 0xFFFFFFC0) | 0x3E);
}
return (((getDatetimeIntVal(row, parm, isNull, ct) >> 32) & 0xFFFFFFC0) | 0x3E);
}
int64_t Func_from_unixtime::getDatetimeIntVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
return *reinterpret_cast<int64_t*>(&dt);
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
return *reinterpret_cast<int64_t*>(&dt);
}
int64_t Func_from_unixtime::getIntVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
char buf[32]; // actual string guaranteed to be 22
snprintf( buf, 32, "%04d%02d%02d%02d%02d%02d",
dt.year, dt.month, dt.day, dt.hour,
dt.minute, dt.second );
return atoll(buf);
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
char buf[32]; // actual string guaranteed to be 22
snprintf( buf, 32, "%04d%02d%02d%02d%02d%02d",
dt.year, dt.month, dt.day, dt.hour,
dt.minute, dt.second );
return atoll(buf);
}
double Func_from_unixtime::getDoubleVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
if (parm.size() == 1)
{
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
if (parm.size() == 1)
{
DateTime dt = getDateTime(row, parm, isNull);
if (*reinterpret_cast<int64_t*>(&dt) == 0)
{
isNull = true;
return 0;
}
char buf[32]; // actual string guaranteed to be 22
snprintf( buf, 32, "%04d%02d%02d%02d%02d%02d.%06d",
dt.year, dt.month, dt.day, dt.hour,
dt.minute, dt.second, dt.msecond );
return atof(buf);
}
dt.minute, dt.second, dt.msecond );
return atof(buf);
}
return (double) atoi(getStrVal(row, parm, isNull, ct).c_str());
return (double) atoi(getStrVal(row, parm, isNull, ct).c_str());
}