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-1822 add LONG DOUBLE support
This commit is contained in:
@ -498,6 +498,14 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
if (row.equals(LONGDOUBLENULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.longDoubleVal = row.getLongDoubleField(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
switch (fResultType.colWidth)
|
||||
|
@ -155,6 +155,10 @@ const string colDataTypeToString(CalpontSystemCatalog::ColDataType cdt)
|
||||
return "double";
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
return "long double";
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
return "datetime";
|
||||
break;
|
||||
|
@ -76,6 +76,8 @@ const float MAX_FLOAT __attribute__ ((unused)) = std::numeric_limits<float>::ma
|
||||
const float MIN_FLOAT __attribute__ ((unused)) = -std::numeric_limits<float>::max();
|
||||
const double MAX_DOUBLE __attribute__ ((unused)) = std::numeric_limits<double>::max(); //1.7976931348623157e+308
|
||||
const double MIN_DOUBLE __attribute__ ((unused)) = -std::numeric_limits<double>::max();
|
||||
const long double MAX_LONGDOUBLE __attribute__ ((unused)) = std::numeric_limits<long double>::max(); //1.7976931348623157e+308
|
||||
const long double MIN_LONGDOUBLE __attribute__ ((unused)) = -std::numeric_limits<long double>::max();
|
||||
|
||||
|
||||
const uint64_t AUTOINCR_SATURATED __attribute__ ((unused)) = std::numeric_limits<uint64_t>::max();
|
||||
|
@ -51,7 +51,7 @@ ConstantColumn::ConstantColumn(const string& sql, TYPE type) :
|
||||
fData(sql)
|
||||
{
|
||||
fResult.strVal = sql;
|
||||
|
||||
|
||||
if (type == LITERAL && sql.length() < 9)
|
||||
{
|
||||
memcpy(tmp, sql.c_str(), sql.length());
|
||||
@ -67,6 +67,7 @@ ConstantColumn::ConstantColumn(const string& sql, TYPE type) :
|
||||
|
||||
fResult.floatVal = atof(sql.c_str());
|
||||
fResult.doubleVal = atof(sql.c_str());
|
||||
fResult.longDoubleVal = strtold(sql.c_str(), NULL);
|
||||
|
||||
// decimal for constant should be constructed by the caller and call the decimal constructor
|
||||
fResult.decimalVal.value = fResult.intVal;
|
||||
@ -105,6 +106,27 @@ ConstantColumn::ConstantColumn(const string& sql, const double val) :
|
||||
fResult.intVal = (int64_t)val;
|
||||
fResult.uintVal = (uint64_t)val;
|
||||
fResult.floatVal = (float)val;
|
||||
fResult.longDoubleVal = val;
|
||||
// decimal for constant should be constructed by the caller and call the decimal constructor
|
||||
fResult.decimalVal.value = fResult.intVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
fResult.decimalVal.precision = 18;
|
||||
fResultType.colDataType = CalpontSystemCatalog::DOUBLE;
|
||||
fResultType.colWidth = 8;
|
||||
}
|
||||
|
||||
ConstantColumn::ConstantColumn(const string& sql, const long double val) :
|
||||
ReturnedColumn(),
|
||||
fConstval(sql),
|
||||
fType(NUM),
|
||||
fData(sql)
|
||||
{
|
||||
fResult.strVal = sql;
|
||||
fResult.doubleVal = (double)val;
|
||||
fResult.intVal = (int64_t)val;
|
||||
fResult.uintVal = (uint64_t)val;
|
||||
fResult.floatVal = (float)val;
|
||||
fResult.longDoubleVal = val;
|
||||
// decimal for constant should be constructed by the caller and call the decimal constructor
|
||||
fResult.decimalVal.value = fResult.intVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
@ -124,6 +146,7 @@ ConstantColumn::ConstantColumn(const string& sql, const int64_t val, TYPE type)
|
||||
fResult.uintVal = (uint64_t)fResult.intVal;
|
||||
fResult.floatVal = (float)fResult.intVal;
|
||||
fResult.doubleVal = (double)fResult.intVal;
|
||||
fResult.longDoubleVal = (long double)fResult.intVal;
|
||||
fResult.decimalVal.value = fResult.intVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
fResultType.colDataType = CalpontSystemCatalog::BIGINT;
|
||||
@ -141,6 +164,7 @@ ConstantColumn::ConstantColumn(const string& sql, const uint64_t val, TYPE type)
|
||||
fResult.intVal = (int64_t)fResult.uintVal;
|
||||
fResult.floatVal = (float)fResult.uintVal;
|
||||
fResult.doubleVal = (double)fResult.uintVal;
|
||||
fResult.longDoubleVal = (long double)fResult.uintVal;
|
||||
fResult.decimalVal.value = fResult.uintVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
fResultType.colDataType = CalpontSystemCatalog::UBIGINT;
|
||||
@ -158,6 +182,7 @@ ConstantColumn::ConstantColumn(const string& sql, const IDB_Decimal& val) :
|
||||
fResult.uintVal = strtoull(sql.c_str(), NULL, 0);
|
||||
fResult.floatVal = atof(sql.c_str());
|
||||
fResult.doubleVal = atof(sql.c_str());
|
||||
fResult.longDoubleVal = strtold(sql.c_str(), NULL);
|
||||
fResult.decimalVal = val;
|
||||
fResultType.colDataType = CalpontSystemCatalog::DECIMAL;
|
||||
fResultType.colWidth = 8;
|
||||
@ -201,6 +226,7 @@ ConstantColumn::ConstantColumn(const int64_t val, TYPE type) :
|
||||
fResult.uintVal = (uint64_t)fResult.intVal;
|
||||
fResult.floatVal = (float)fResult.intVal;
|
||||
fResult.doubleVal = (double)fResult.intVal;
|
||||
fResult.longDoubleVal = (long double)fResult.intVal;
|
||||
fResult.decimalVal.value = fResult.intVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
fResultType.colDataType = CalpontSystemCatalog::BIGINT;
|
||||
@ -220,6 +246,7 @@ ConstantColumn::ConstantColumn(const uint64_t val, TYPE type) :
|
||||
fResult.uintVal = val;
|
||||
fResult.floatVal = (float)fResult.uintVal;
|
||||
fResult.doubleVal = (double)fResult.uintVal;
|
||||
fResult.longDoubleVal = (long double)fResult.uintVal;
|
||||
fResult.decimalVal.value = fResult.uintVal;
|
||||
fResult.decimalVal.scale = 0;
|
||||
fResultType.colDataType = CalpontSystemCatalog::UBIGINT;
|
||||
@ -281,13 +308,15 @@ void ConstantColumn::serialize(messageqcpp::ByteStream& b) const
|
||||
b << static_cast<const ByteStream::doublebyte>(fReturnAll);
|
||||
b << (uint64_t)fResult.intVal;
|
||||
b << fResult.uintVal;
|
||||
b << (*(uint64_t*)(&fResult.doubleVal));
|
||||
b << (*(uint32_t*)(&fResult.floatVal));
|
||||
b << fResult.doubleVal;
|
||||
b << fResult.longDoubleVal;
|
||||
b << fResult.floatVal;
|
||||
b << (uint8_t)fResult.boolVal;
|
||||
b << fResult.strVal;
|
||||
b << (uint64_t)fResult.decimalVal.value;
|
||||
b << (uint8_t)fResult.decimalVal.scale;
|
||||
b << (uint8_t)fResult.decimalVal.precision;
|
||||
b << fResult.longDoubleVal;
|
||||
}
|
||||
|
||||
void ConstantColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
@ -303,8 +332,9 @@ void ConstantColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
b >> reinterpret_cast< ByteStream::doublebyte&>(fReturnAll);
|
||||
b >> (uint64_t&)fResult.intVal;
|
||||
b >> fResult.uintVal;
|
||||
b >> (uint64_t&)fResult.doubleVal;
|
||||
b >> (uint32_t&)fResult.floatVal;
|
||||
b >> fResult.doubleVal;
|
||||
b >> fResult.longDoubleVal;
|
||||
b >> fResult.floatVal;
|
||||
b >> (uint8_t&)fResult.boolVal;
|
||||
b >> fResult.strVal;
|
||||
b >> (uint64_t&)fResult.decimalVal.value;
|
||||
|
@ -200,6 +200,10 @@ public:
|
||||
* ctor
|
||||
*/
|
||||
ConstantColumn(const std::string& sql, const double val);
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
ConstantColumn(const std::string& sql, const long double val);
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
|
@ -592,6 +592,12 @@ void SimpleColumn::evaluate(Row& row, bool& isNull)
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
fResult.longDoubleVal = row.getLongDoubleField(fInputIndex);
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
|
@ -249,6 +249,7 @@ struct Result
|
||||
// when converting origIntVal
|
||||
uint64_t dummy;
|
||||
double doubleVal;
|
||||
long double longDoubleVal;
|
||||
float floatVal;
|
||||
bool boolVal;
|
||||
std::string strVal;
|
||||
@ -376,6 +377,10 @@ public:
|
||||
{
|
||||
return fResult.doubleVal;
|
||||
}
|
||||
virtual long double getLongDoubleVal(rowgroup::Row& row, bool& isNull)
|
||||
{
|
||||
return fResult.longDoubleVal;
|
||||
}
|
||||
virtual IDB_Decimal getDecimalVal(rowgroup::Row& row, bool& isNull)
|
||||
{
|
||||
return fResult.decimalVal;
|
||||
@ -517,6 +522,9 @@ inline bool TreeNode::getBoolVal()
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
return (fResult.doubleVal != 0);
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
return (fResult.longDoubleVal != 0);
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
return (fResult.decimalVal.value != 0);
|
||||
@ -646,6 +654,40 @@ inline const std::string& TreeNode::getStrVal()
|
||||
fResult.strVal += tmp;
|
||||
}
|
||||
|
||||
// snprintf(tmp, 312, "%e", fResult.doubleVal);
|
||||
// fResult.strVal = tmp;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
if ((fabsl(fResult.longDoubleVal) > (1.0 / IDB_pow[13])) &&
|
||||
(fabsl(fResult.longDoubleVal) < (float) IDB_pow[15]))
|
||||
{
|
||||
snprintf(tmp, 312, "%Lf", fResult.longDoubleVal);
|
||||
fResult.strVal = removeTrailing0(tmp, 312);
|
||||
}
|
||||
else
|
||||
{
|
||||
// MCOL-299 Print scientific with 9 mantissa and no + sign for exponent
|
||||
int exponent = (int)floorl(log10( fabsl(fResult.longDoubleVal))); // This will round down the exponent
|
||||
long double base = fResult.longDoubleVal * pow(10, -1.0 * exponent);
|
||||
|
||||
if (isnan(exponent) || isnan(base))
|
||||
{
|
||||
snprintf(tmp, 312, "%Lf", fResult.longDoubleVal);
|
||||
fResult.strVal = removeTrailing0(tmp, 312);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(tmp, 312, "%.14Lf", base);
|
||||
fResult.strVal = removeTrailing0(tmp, 312);
|
||||
snprintf(tmp, 312, "e%02d", exponent);
|
||||
fResult.strVal += tmp;
|
||||
}
|
||||
|
||||
// snprintf(tmp, 312, "%e", fResult.doubleVal);
|
||||
// fResult.strVal = tmp;
|
||||
}
|
||||
@ -736,6 +778,9 @@ inline int64_t TreeNode::getIntVal()
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
return (int64_t)fResult.doubleVal;
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
return (int64_t)fResult.longDoubleVal;
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
@ -779,6 +824,9 @@ inline uint64_t TreeNode::getUintVal()
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
return (uint64_t)fResult.doubleVal;
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
return (uint64_t)fResult.longDoubleVal;
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
@ -843,6 +891,9 @@ inline float TreeNode::getFloatVal()
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
return (float)fResult.doubleVal;
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
return (float)fResult.doubleVal;
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
return (fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
|
||||
@ -978,6 +1029,9 @@ inline IDB_Decimal TreeNode::getDecimalVal()
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
throw logging::InvalidConversionExcept("TreeNode::getDecimalVal: non-support conversion from double unsigned");
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
throw logging::InvalidConversionExcept("TreeNode::getDecimalVal: non-support conversion from long double");
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
return fResult.decimalVal;
|
||||
|
@ -583,6 +583,16 @@ void WindowFunctionColumn::evaluate(Row& row, bool& isNull)
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
if (row.equals(LONGDOUBLENULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.longDoubleVal = row.getLongDoubleField(fInputIndex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
|
Reference in New Issue
Block a user