1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-05 16:15:50 +03:00

MCOL-4180 Add some missing support for wide decimals to dbcon/execplan

classes.
This commit is contained in:
Gagan Goel
2020-12-12 00:14:48 +00:00
parent 9c623a5434
commit ed7811e161
5 changed files with 67 additions and 9 deletions

View File

@@ -347,12 +347,31 @@ class Decimal: public TSInt128
return toDouble(); return toDouble();
} }
inline long double toLongDouble() const inline float toFloat() const
{ {
datatypes::TFloat128 y(s128Value); int128_t scaleDivisor;
return static_cast<long double>(y); getScaleDivisor(scaleDivisor, scale);
datatypes::TFloat128 tmpval((__float128) s128Value / scaleDivisor);
return static_cast<float>(tmpval);
} }
inline operator float() const
{
return toFloat();
}
inline long double toLongDouble() const
{
int128_t scaleDivisor;
getScaleDivisor(scaleDivisor, scale);
datatypes::TFloat128 tmpval((__float128) s128Value / scaleDivisor);
return static_cast<long double>(tmpval);
}
inline operator long double() const
{
return toLongDouble();
}
// This method returns integral part as a TSInt128 and // This method returns integral part as a TSInt128 and
// fractional part as a TFloat128 // fractional part as a TFloat128

View File

@@ -102,6 +102,21 @@ class TFloat128
return toLongDouble(); return toLongDouble();
} }
inline operator float() const
{
return toFloat();
}
inline float toFloat() const
{
if (value > static_cast<__float128>(FLT_MAX))
return FLT_MAX;
else if (value < -static_cast<__float128>(FLT_MAX))
return -FLT_MAX;
return static_cast<float>(value);
}
inline int64_t toTSInt64() const inline int64_t toTSInt64() const
{ {
if (value > static_cast<__float128>(INT64_MAX)) if (value > static_cast<__float128>(INT64_MAX))

View File

@@ -127,7 +127,8 @@ bool ArithmeticOperator::operator!=(const TreeNode* t) const
void ArithmeticOperator::adjustResultType(const CalpontSystemCatalog::ColType& m) void ArithmeticOperator::adjustResultType(const CalpontSystemCatalog::ColType& m)
{ {
if (m.colDataType != CalpontSystemCatalog::DECIMAL) if (m.colDataType != CalpontSystemCatalog::DECIMAL &&
m.colDataType != CalpontSystemCatalog::UDECIMAL)
{ {
fResultType = m; fResultType = m;
} }

View File

@@ -246,11 +246,12 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
case execplan::CalpontSystemCatalog::LONGDOUBLE: case execplan::CalpontSystemCatalog::LONGDOUBLE:
fResult.longDoubleVal = execute(lop->getLongDoubleVal(row, isNull), rop->getLongDoubleVal(row, isNull), isNull); fResult.longDoubleVal = execute(lop->getLongDoubleVal(row, isNull), rop->getLongDoubleVal(row, isNull), isNull);
break; break;
// WIP MCOL-641
case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
execute(fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull); execute(fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull);
break; break;
default: default:
{ {
std::ostringstream oss; std::ostringstream oss;

View File

@@ -762,9 +762,16 @@ inline uint64_t TreeNode::getUintVal()
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
{
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
{
return static_cast<uint64_t>(fResult.decimalVal.getIntegralPart());
}
else
{ {
return (uint64_t)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale)); return (uint64_t)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
} }
}
case CalpontSystemCatalog::DATE: case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME: case CalpontSystemCatalog::DATETIME:
@@ -829,9 +836,17 @@ inline float TreeNode::getFloatVal()
return (float)fResult.doubleVal; return (float)fResult.doubleVal;
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
{
return static_cast<float>(fResult.decimalVal);
}
else
{ {
return (fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale)); return (fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
} }
}
case CalpontSystemCatalog::DATE: case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME: case CalpontSystemCatalog::DATETIME:
@@ -973,10 +988,17 @@ inline long double TreeNode::getLongDoubleVal()
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
{
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
{
return static_cast<long double>(fResult.decimalVal);
}
else
{ {
// this may not be accurate. if this is problematic, change to pre-calculated power array. // this may not be accurate. if this is problematic, change to pre-calculated power array.
return (long double)(fResult.decimalVal.value / pow((long double)10, fResult.decimalVal.scale)); return (long double)(fResult.decimalVal.value / pow((long double)10, fResult.decimalVal.scale));
} }
}
case CalpontSystemCatalog::DATE: case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME: case CalpontSystemCatalog::DATETIME: