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-4633 Remove duplicate code for DECIMAL to int64_t rounding conversion
Detailed change list: - Splitting out the narrow part of "class Decimal" into a separate class TDecimal64 - Adding a method TDecimal64::toSInt64Round() - Reusing the method TDecimal64::toSInt64Round() in: * Func_cast_signed::getIntVal() * Func_char::getStrVal() * Func_elt::getStrVal() * makedate() * Func_maketime::getStrVal() Note, reusing this method in Func_char::getStrVal() also fixed this bug: MCOL-4634 CHAR(negativeWideDecimal) is not like InnoDB because the old code handled negative wide decimal values in a wrong way. - Adding a new class TDecimal128 for symmetry. Moving a few wide decimal methods and constexpr's from Decimal to TDecimal128. The new class TDecimal128 does not do much at this point yet. Later we should be able to use TDecimal128 vs TDecimal64 in templates.
This commit is contained in:
@ -74,25 +74,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
hour = static_cast<int64_t>(d.getPosNegRoundedIntegralPart(4));
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
hour = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - hour * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
|
||||
if ( hour >= 0 && lefto > 4 )
|
||||
hour++;
|
||||
|
||||
if ( hour < 0 && lefto < -4 )
|
||||
hour--;
|
||||
}
|
||||
|
||||
hour = parm[0]->data()->getDecimalVal(row, isNull).toSInt64Round();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -123,25 +105,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[1]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
min = static_cast<int64_t>(d.getPosNegRoundedIntegralPart(4));
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
min = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - min * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
|
||||
if ( min >= 0 && lefto > 4 )
|
||||
min++;
|
||||
|
||||
if ( min < 0 && lefto < -4 )
|
||||
min--;
|
||||
}
|
||||
|
||||
min = parm[1]->data()->getDecimalVal(row, isNull).toSInt64Round();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -178,25 +142,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[2]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[2]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
sec = static_cast<int64_t>(d.getPosNegRoundedIntegralPart(4));
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
sec = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - sec * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
|
||||
if ( sec >= 0 && lefto > 4 )
|
||||
sec++;
|
||||
|
||||
if ( sec < 0 && lefto < -4 )
|
||||
sec--;
|
||||
}
|
||||
|
||||
sec = parm[2]->data()->getDecimalVal(row, isNull).toSInt64Round();
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user