Skip to content

Commit 45197c4

Browse files
authored
Merge pull request mariadb-corporation#1678 from tntnatbry/MCOL-4180
MCOL-4180 Add some missing support for wide decimals to dbcon/execplan classes.
2 parents 0a9fc05 + ed7811e commit 45197c4

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

datatypes/mcs_decimal.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,31 @@ class Decimal: public TSInt128
347347
return toDouble();
348348
}
349349

350+
inline float toFloat() const
351+
{
352+
int128_t scaleDivisor;
353+
getScaleDivisor(scaleDivisor, scale);
354+
datatypes::TFloat128 tmpval((__float128) s128Value / scaleDivisor);
355+
return static_cast<float>(tmpval);
356+
}
357+
358+
inline operator float() const
359+
{
360+
return toFloat();
361+
}
362+
350363
inline long double toLongDouble() const
351364
{
352-
datatypes::TFloat128 y(s128Value);
353-
return static_cast<long double>(y);
365+
int128_t scaleDivisor;
366+
getScaleDivisor(scaleDivisor, scale);
367+
datatypes::TFloat128 tmpval((__float128) s128Value / scaleDivisor);
368+
return static_cast<long double>(tmpval);
354369
}
355370

371+
inline operator long double() const
372+
{
373+
return toLongDouble();
374+
}
356375

357376
// This method returns integral part as a TSInt128 and
358377
// fractional part as a TFloat128

datatypes/mcs_float128.h

+15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ class TFloat128
102102
return toLongDouble();
103103
}
104104

105+
inline operator float() const
106+
{
107+
return toFloat();
108+
}
109+
110+
inline float toFloat() const
111+
{
112+
if (value > static_cast<__float128>(FLT_MAX))
113+
return FLT_MAX;
114+
else if (value < -static_cast<__float128>(FLT_MAX))
115+
return -FLT_MAX;
116+
117+
return static_cast<float>(value);
118+
}
119+
105120
inline int64_t toTSInt64() const
106121
{
107122
if (value > static_cast<__float128>(INT64_MAX))

dbcon/execplan/arithmeticoperator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ bool ArithmeticOperator::operator!=(const TreeNode* t) const
127127

128128
void ArithmeticOperator::adjustResultType(const CalpontSystemCatalog::ColType& m)
129129
{
130-
if (m.colDataType != CalpontSystemCatalog::DECIMAL)
130+
if (m.colDataType != CalpontSystemCatalog::DECIMAL &&
131+
m.colDataType != CalpontSystemCatalog::UDECIMAL)
131132
{
132133
fResultType = m;
133134
}

dbcon/execplan/arithmeticoperator.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
246246
case execplan::CalpontSystemCatalog::LONGDOUBLE:
247247
fResult.longDoubleVal = execute(lop->getLongDoubleVal(row, isNull), rop->getLongDoubleVal(row, isNull), isNull);
248248
break;
249-
// WIP MCOL-641
249+
250250
case execplan::CalpontSystemCatalog::DECIMAL:
251251
case execplan::CalpontSystemCatalog::UDECIMAL:
252252
execute(fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull);
253253
break;
254+
254255
default:
255256
{
256257
std::ostringstream oss;

dbcon/execplan/treenode.h

+26-4
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,14 @@ inline uint64_t TreeNode::getUintVal()
763763
case CalpontSystemCatalog::DECIMAL:
764764
case CalpontSystemCatalog::UDECIMAL:
765765
{
766-
return (uint64_t)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
766+
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
767+
{
768+
return static_cast<uint64_t>(fResult.decimalVal.getIntegralPart());
769+
}
770+
else
771+
{
772+
return (uint64_t)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
773+
}
767774
}
768775

769776
case CalpontSystemCatalog::DATE:
@@ -829,8 +836,16 @@ inline float TreeNode::getFloatVal()
829836
return (float)fResult.doubleVal;
830837

831838
case CalpontSystemCatalog::DECIMAL:
839+
case CalpontSystemCatalog::UDECIMAL:
832840
{
833-
return (fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
841+
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
842+
{
843+
return static_cast<float>(fResult.decimalVal);
844+
}
845+
else
846+
{
847+
return (fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
848+
}
834849
}
835850

836851
case CalpontSystemCatalog::DATE:
@@ -974,8 +989,15 @@ inline long double TreeNode::getLongDoubleVal()
974989
case CalpontSystemCatalog::DECIMAL:
975990
case CalpontSystemCatalog::UDECIMAL:
976991
{
977-
// this may not be accurate. if this is problematic, change to pre-calculated power array.
978-
return (long double)(fResult.decimalVal.value / pow((long double)10, fResult.decimalVal.scale));
992+
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
993+
{
994+
return static_cast<long double>(fResult.decimalVal);
995+
}
996+
else
997+
{
998+
// this may not be accurate. if this is problematic, change to pre-calculated power array.
999+
return (long double)(fResult.decimalVal.value / pow((long double)10, fResult.decimalVal.scale));
1000+
}
9791001
}
9801002

9811003
case CalpontSystemCatalog::DATE:

0 commit comments

Comments
 (0)