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
MCOL-4668 PERIOD_DIFF(dec_or_double1,dec_or_double2) is not as in InnoDB
This commit is contained in:
@ -38,11 +38,11 @@ namespace funcexp
|
||||
{
|
||||
#define YY_PART_YEAR 70
|
||||
|
||||
inline int64_t convert_period_to_month(int64_t period)
|
||||
inline uint64_t convert_period_to_month(uint64_t period)
|
||||
{
|
||||
int64_t a, b;
|
||||
uint64_t a, b;
|
||||
|
||||
if (period == 0)
|
||||
if (period == 0 || period > 999912)
|
||||
return 0L;
|
||||
|
||||
if ((a = period / 100) < YY_PART_YEAR)
|
||||
@ -55,144 +55,63 @@ inline int64_t convert_period_to_month(int64_t period)
|
||||
}
|
||||
|
||||
|
||||
int64_t getArgSInt64Val(rowgroup::Row& row, TreeNode *exp, bool& isNull)
|
||||
{
|
||||
switch (exp->resultType().colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
case execplan::CalpontSystemCatalog::TIMESTAMP:
|
||||
return exp->getIntVal(row, isNull);
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = exp->getDecimalVal(row, isNull);
|
||||
return d.toSInt64Round();
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
return atoi(exp->getStrVal(row, isNull).c_str());
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
{
|
||||
datatypes::TDouble d(exp->getDoubleVal(row, isNull));
|
||||
return d.toMCSSInt64Round();
|
||||
}
|
||||
|
||||
default:
|
||||
isNull = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
CalpontSystemCatalog::ColType Func_period_diff::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
|
||||
{
|
||||
return resultType;
|
||||
}
|
||||
|
||||
|
||||
int64_t Func_period_diff::getIntVal(rowgroup::Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
int64_t period1 = 0;
|
||||
|
||||
switch (parm[0]->data()->resultType().colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
case execplan::CalpontSystemCatalog::TIMESTAMP:
|
||||
{
|
||||
period1 = parm[0]->data()->getIntVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
|
||||
if (tmpval > static_cast<int128_t>(INT64_MAX))
|
||||
tmpval = INT64_MAX;
|
||||
else if (tmpval < static_cast<int128_t>(INT64_MIN))
|
||||
tmpval = INT64_MIN;
|
||||
|
||||
period1 = tmpval;
|
||||
}
|
||||
else
|
||||
{
|
||||
period1 = d.value / pow(10.0, d.scale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
period1 = atoi(parm[0]->data()->getStrVal(row, isNull).c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
{
|
||||
period1 = (int64_t) parm[0]->data()->getDoubleVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
isNull = true;
|
||||
}
|
||||
}
|
||||
uint64_t period1 = (uint64_t) getArgSInt64Val(row, parm[0]->data(), isNull);
|
||||
|
||||
if (isNull)
|
||||
return 0;
|
||||
|
||||
int64_t period2 = 0;
|
||||
|
||||
switch (parm[1]->data()->resultType().colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
case execplan::CalpontSystemCatalog::TIMESTAMP:
|
||||
{
|
||||
period2 = parm[1]->data()->getIntVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[1]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
|
||||
if (tmpval > static_cast<int128_t>(INT64_MAX))
|
||||
tmpval = INT64_MAX;
|
||||
else if (tmpval < static_cast<int128_t>(INT64_MIN))
|
||||
tmpval = INT64_MIN;
|
||||
|
||||
period2 = tmpval;
|
||||
}
|
||||
else
|
||||
{
|
||||
period2 = d.value / pow(10.0, d.scale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
period2 = atoi(parm[1]->data()->getStrVal(row, isNull).c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
{
|
||||
period2 = (int64_t) parm[1]->data()->getDoubleVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
isNull = true;
|
||||
}
|
||||
}
|
||||
uint64_t period2 = (uint64_t) getArgSInt64Val(row, parm[1]->data(), isNull);
|
||||
|
||||
if (isNull)
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user