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
Reformat all code to coding standard
This commit is contained in:
@ -46,24 +46,25 @@ namespace helpers
|
||||
|
||||
const string timediff( int64_t time1, int64_t time2)
|
||||
{
|
||||
long long seconds;
|
||||
long long microseconds;
|
||||
int l_sign = 1;
|
||||
long long seconds;
|
||||
long long microseconds;
|
||||
int l_sign = 1;
|
||||
|
||||
if ( (time1 < 0 && time2 >= 0) ||
|
||||
(time2 < 0 && time1 >= 0) )
|
||||
l_sign = -l_sign;
|
||||
if ( (time1 < 0 && time2 >= 0) ||
|
||||
(time2 < 0 && time1 >= 0) )
|
||||
l_sign = -l_sign;
|
||||
|
||||
if ( time1 > time2 )
|
||||
helpers::calc_time_diff(time1, time2, l_sign, &seconds, µseconds);
|
||||
else
|
||||
helpers::calc_time_diff(time2, time1, l_sign, &seconds, µseconds);
|
||||
if ( time1 > time2 )
|
||||
helpers::calc_time_diff(time1, time2, l_sign, &seconds, µseconds);
|
||||
else
|
||||
helpers::calc_time_diff(time2, time1, l_sign, &seconds, µseconds);
|
||||
|
||||
long t_seconds;
|
||||
int hour = seconds / 3600L;
|
||||
t_seconds = seconds % 3600L;
|
||||
int minute = t_seconds / 60L;
|
||||
int second = t_seconds % 60L;
|
||||
|
||||
long t_seconds;
|
||||
int hour= seconds/3600L;
|
||||
t_seconds= seconds%3600L;
|
||||
int minute= t_seconds/60L;
|
||||
int second= t_seconds%60L;
|
||||
// Bug 5099: Standardize to mysql behavior. No timediff may be > 838:59:59
|
||||
if (hour > 838)
|
||||
{
|
||||
@ -71,151 +72,165 @@ const string timediff( int64_t time1, int64_t time2)
|
||||
minute = 59;
|
||||
second = 59;
|
||||
}
|
||||
int sign = 0;
|
||||
if ( time1 < time2 )
|
||||
sign = 1;
|
||||
|
||||
char buf[256];
|
||||
char* ptr = buf;
|
||||
string time3;
|
||||
if ( microseconds == 0 )
|
||||
sprintf (ptr, "%s%02d:%02d:%02d", sign ? "-" : "", hour, minute, second);
|
||||
else
|
||||
sprintf (ptr, "%s%02d:%02d:%02d:%06lld", sign ? "-" : "",hour, minute, second, microseconds);
|
||||
int sign = 0;
|
||||
|
||||
time3 = ptr;
|
||||
if ( time1 < time2 )
|
||||
sign = 1;
|
||||
|
||||
return time3;
|
||||
char buf[256];
|
||||
char* ptr = buf;
|
||||
string time3;
|
||||
|
||||
if ( microseconds == 0 )
|
||||
sprintf (ptr, "%s%02d:%02d:%02d", sign ? "-" : "", hour, minute, second);
|
||||
else
|
||||
sprintf (ptr, "%s%02d:%02d:%02d:%06lld", sign ? "-" : "", hour, minute, second, microseconds);
|
||||
|
||||
time3 = ptr;
|
||||
|
||||
return time3;
|
||||
}
|
||||
}
|
||||
|
||||
CalpontSystemCatalog::ColType Func_timediff::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
|
||||
{
|
||||
return resultType;
|
||||
return resultType;
|
||||
}
|
||||
|
||||
string Func_timediff::getStrVal(rowgroup::Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
int16_t type1 = parm[0]->data()->resultType().colDataType;
|
||||
int16_t type2 = parm[1]->data()->resultType().colDataType;
|
||||
|
||||
int64_t val1 = -1, val2 = -1;
|
||||
bool isDate1 = false, isDate2 = false;
|
||||
int16_t type1 = parm[0]->data()->resultType().colDataType;
|
||||
int16_t type2 = parm[1]->data()->resultType().colDataType;
|
||||
|
||||
switch (type1)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
val1 = parm[0]->data()->getDatetimeIntVal(row, isNull);
|
||||
isDate1 = true;
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
val1 = parm[0]->data()->getDatetimeIntVal(row, isNull);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
val1 = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull), &isDate1);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
val1 = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull), &isDate1);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
if (parm[0]->data()->resultType().scale != 0)
|
||||
{
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
val1 = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull), &isDate1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
isNull = true;
|
||||
}
|
||||
|
||||
switch (type2)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
val2 = parm[1]->data()->getDatetimeIntVal(row, isNull);
|
||||
isDate2 = true;
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
val2 = parm[1]->data()->getDatetimeIntVal(row, isNull);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
val2 = dataconvert::DataConvert::stringToDatetime(parm[1]->data()->getStrVal(row, isNull), &isDate2);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
val2 = dataconvert::DataConvert::intToDatetime(parm[1]->data()->getIntVal(row, isNull), &isDate2);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
if (parm[1]->data()->resultType().scale != 0)
|
||||
{
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
val2 = dataconvert::DataConvert::intToDatetime(parm[1]->data()->getIntVal(row, isNull), &isDate2);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
isNull = true;
|
||||
}
|
||||
|
||||
if (isNull || val1 == -1 || val2 == -1)
|
||||
{
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
|
||||
// both date format or both datetime format
|
||||
if ((isDate1 && isDate2) || (!isDate1 && !isDate2))
|
||||
return helpers::timediff( val1, val2);
|
||||
isNull = true;
|
||||
return "";
|
||||
int64_t val1 = -1, val2 = -1;
|
||||
bool isDate1 = false, isDate2 = false;
|
||||
|
||||
switch (type1)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
val1 = parm[0]->data()->getDatetimeIntVal(row, isNull);
|
||||
isDate1 = true;
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
val1 = parm[0]->data()->getDatetimeIntVal(row, isNull);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
val1 = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull), &isDate1);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
val1 = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull), &isDate1);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
if (parm[0]->data()->resultType().scale != 0)
|
||||
{
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
val1 = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull), &isDate1);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
isNull = true;
|
||||
}
|
||||
|
||||
switch (type2)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
val2 = parm[1]->data()->getDatetimeIntVal(row, isNull);
|
||||
isDate2 = true;
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
val2 = parm[1]->data()->getDatetimeIntVal(row, isNull);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
val2 = dataconvert::DataConvert::stringToDatetime(parm[1]->data()->getStrVal(row, isNull), &isDate2);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
val2 = dataconvert::DataConvert::intToDatetime(parm[1]->data()->getIntVal(row, isNull), &isDate2);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
if (parm[1]->data()->resultType().scale != 0)
|
||||
{
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
val2 = dataconvert::DataConvert::intToDatetime(parm[1]->data()->getIntVal(row, isNull), &isDate2);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
isNull = true;
|
||||
}
|
||||
|
||||
if (isNull || val1 == -1 || val2 == -1)
|
||||
{
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
|
||||
// both date format or both datetime format
|
||||
if ((isDate1 && isDate2) || (!isDate1 && !isDate2))
|
||||
return helpers::timediff( val1, val2);
|
||||
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
|
||||
int64_t Func_timediff::getDatetimeIntVal(rowgroup::Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
return dataconvert::DataConvert::datetimeToInt(getStrVal(row, parm, isNull, ct));
|
||||
return dataconvert::DataConvert::datetimeToInt(getStrVal(row, parm, isNull, ct));
|
||||
}
|
||||
|
||||
int64_t Func_timediff::getIntVal(rowgroup::Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
// @bug 3585
|
||||
//return dataconvert::DataConvert::datetimeToInt(getStrVal(row, parm, isNull, ct));
|
||||
return strtoll(getStrVal(row, parm, isNull, ct).c_str(), 0, 10);
|
||||
// @bug 3585
|
||||
//return dataconvert::DataConvert::datetimeToInt(getStrVal(row, parm, isNull, ct));
|
||||
return strtoll(getStrVal(row, parm, isNull, ct).c_str(), 0, 10);
|
||||
}
|
||||
|
||||
double Func_timediff::getDoubleVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
// @bug 3585
|
||||
//return (double)dataconvert::DataConvert::datetimeToInt(getStrVal(row, fp, isNull, op_ct));
|
||||
return atof(getStrVal(row, fp, isNull, op_ct).c_str());
|
||||
// @bug 3585
|
||||
//return (double)dataconvert::DataConvert::datetimeToInt(getStrVal(row, fp, isNull, op_ct));
|
||||
return atof(getStrVal(row, fp, isNull, op_ct).c_str());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user