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-641 Add support for functions (Part 1).
This commit is contained in:
committed by
Roman Nozdrin
parent
554c6da8e8
commit
cfe35b5c7f
@ -19,6 +19,7 @@
|
||||
#define H_DECIMALDATATYPE
|
||||
|
||||
#include <cstdint>
|
||||
#include <cfloat>
|
||||
|
||||
#include "calpontsystemcatalog.h"
|
||||
|
||||
@ -240,6 +241,102 @@ class Decimal
|
||||
ct.scale = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a __float128 value to an int64_t.
|
||||
*/
|
||||
static inline int64_t getInt64FromFloat128(const __float128& value)
|
||||
{
|
||||
if (value > static_cast<__float128>(INT64_MAX))
|
||||
return INT64_MAX;
|
||||
else if (value < static_cast<__float128>(INT64_MIN))
|
||||
return INT64_MIN;
|
||||
|
||||
return static_cast<int64_t>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a __float128 value to an uint64_t.
|
||||
*/
|
||||
static inline uint64_t getUInt64FromFloat128(const __float128& value)
|
||||
{
|
||||
if (value > static_cast<__float128>(UINT64_MAX))
|
||||
return UINT64_MAX;
|
||||
else if (value < 0)
|
||||
return 0;
|
||||
|
||||
return static_cast<uint64_t>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a __float128 value to a double.
|
||||
*/
|
||||
static inline double getDoubleFromFloat128(const __float128& value)
|
||||
{
|
||||
if (value > static_cast<__float128>(DBL_MAX))
|
||||
return DBL_MAX;
|
||||
else if (value < -static_cast<__float128>(DBL_MAX))
|
||||
return -DBL_MAX;
|
||||
|
||||
return static_cast<double>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a wide decimal value to a double.
|
||||
*/
|
||||
static inline double getDoubleFromWideDecimal(const int128_t& value, int8_t scale)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
|
||||
getScaleDivisor(scaleDivisor, scale);
|
||||
|
||||
__float128 tmpval = (__float128) value / scaleDivisor;
|
||||
|
||||
return getDoubleFromFloat128(tmpval);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a wide decimal value to a double.
|
||||
*/
|
||||
static inline double getDoubleFromWideDecimal(const int128_t& value)
|
||||
{
|
||||
return getDoubleFromFloat128(static_cast<__float128>(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a __float128 value to a long double.
|
||||
*/
|
||||
static inline long double getLongDoubleFromFloat128(const __float128& value)
|
||||
{
|
||||
if (value > static_cast<__float128>(LDBL_MAX))
|
||||
return LDBL_MAX;
|
||||
else if (value < -static_cast<__float128>(LDBL_MAX))
|
||||
return -LDBL_MAX;
|
||||
|
||||
return static_cast<long double>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a wide decimal value to a long double.
|
||||
*/
|
||||
static inline long double getLongDoubleFromWideDecimal(const int128_t& value)
|
||||
{
|
||||
return getLongDoubleFromFloat128(static_cast<__float128>(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief The method converts a wide decimal value to an int64_t,
|
||||
saturating the value if necessary.
|
||||
*/
|
||||
static inline int64_t getInt64FromWideDecimal(const int128_t& value)
|
||||
{
|
||||
if (value > static_cast<int128_t>(INT64_MAX))
|
||||
return INT64_MAX;
|
||||
else if (value < static_cast<int128_t>(INT64_MIN))
|
||||
return INT64_MIN;
|
||||
|
||||
return static_cast<int64_t>(value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -256,14 +256,24 @@ public:
|
||||
(datatypes::Decimal::isWideDecimalType(decimal.precision)) ?
|
||||
decimal.s128Value : decimal.value;
|
||||
|
||||
int128_t scaleMultiplier, result;
|
||||
int128_t scaleMultiplier;
|
||||
int32_t scaleDiff = fResultType.scale - decimal.scale;
|
||||
datatypes::getScaleDivisor(scaleMultiplier, abs(scaleDiff));
|
||||
if (scaleMultiplier > 1)
|
||||
{
|
||||
if (scaleDiff > 0)
|
||||
{
|
||||
// WIP MCOL-641 Unconditionall overflow check
|
||||
datatypes::MultiplicationOverflowCheck mul;
|
||||
decimal.s128Value = (scaleDiff > 0
|
||||
&& mul(decimal.s128Value, scaleMultiplier, result))
|
||||
? result : decimal.s128Value / scaleMultiplier;
|
||||
datatypes::MultiplicationNoOverflowCheck mul;
|
||||
mul(decimal.s128Value, scaleMultiplier, decimal.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
decimal.s128Value = (int128_t)(decimal.s128Value > 0 ?
|
||||
(__float128)decimal.s128Value / scaleMultiplier + 0.5 :
|
||||
(__float128)decimal.s128Value / scaleMultiplier - 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fResultType.colWidth == utils::MAXLEGACYWIDTH)
|
||||
{
|
||||
|
@ -63,17 +63,16 @@ typedef execplan::CalpontSystemCatalog::ColType Type;
|
||||
*/
|
||||
struct IDB_Decimal
|
||||
{
|
||||
IDB_Decimal(): value(0), scale(0), precision(0)
|
||||
IDB_Decimal(): s128Value(0), value(0), scale(0), precision(0)
|
||||
{
|
||||
s128Value = 0;
|
||||
}
|
||||
|
||||
IDB_Decimal(int64_t val, int8_t s, uint8_t p) :
|
||||
IDB_Decimal(int64_t val, int8_t s, uint8_t p, int128_t val128 = 0) :
|
||||
s128Value(val128),
|
||||
value(val),
|
||||
scale(s),
|
||||
precision(p)
|
||||
{
|
||||
s128Value = 0;
|
||||
}
|
||||
|
||||
int decimalComp(const IDB_Decimal& d) const
|
||||
@ -117,13 +116,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator==(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value == rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) == 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
const_cast<IDB_Decimal&>(rhs).s128Value = rhs.value;
|
||||
|
||||
if (scale == rhs.scale)
|
||||
return s128Value == rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) == 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value == rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -135,13 +153,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator>(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value > rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) > 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
IDB_Decimal rhstmp(0, rhs.scale, rhs.precision, (int128_t) rhs.value);
|
||||
|
||||
if (scale == rhstmp.scale)
|
||||
return s128Value > rhstmp.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhstmp) > 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value > rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -153,13 +190,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator<(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value < rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) < 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
IDB_Decimal rhstmp(0, rhs.scale, rhs.precision, (int128_t) rhs.value);
|
||||
|
||||
if (scale == rhstmp.scale)
|
||||
return s128Value < rhstmp.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhstmp) < 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value < rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) < 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -171,13 +227,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator>=(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value >= rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) >= 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
IDB_Decimal rhstmp(0, rhs.scale, rhs.precision, (int128_t) rhs.value);
|
||||
|
||||
if (scale == rhstmp.scale)
|
||||
return s128Value >= rhstmp.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhstmp) >= 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value >= rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -189,13 +264,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator<=(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value <= rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) <= 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
IDB_Decimal rhstmp(0, rhs.scale, rhs.precision, (int128_t) rhs.value);
|
||||
|
||||
if (scale == rhstmp.scale)
|
||||
return s128Value <= rhstmp.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhstmp) <= 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value <= rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) <= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -207,13 +301,32 @@ struct IDB_Decimal
|
||||
|
||||
bool operator!=(const IDB_Decimal& rhs) const
|
||||
{
|
||||
if (utils::widthByPrecision(precision) == 16)
|
||||
if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return s128Value != rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhs) != 0);
|
||||
}
|
||||
else if (precision > datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
IDB_Decimal rhstmp(0, rhs.scale, rhs.precision, (int128_t) rhs.value);
|
||||
|
||||
if (scale == rhstmp.scale)
|
||||
return s128Value != rhstmp.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(*this, rhstmp) != 0);
|
||||
}
|
||||
else if (precision <= datatypes::INT64MAXPRECISION &&
|
||||
rhs.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
return (int128_t) value != rhs.s128Value;
|
||||
else
|
||||
return (datatypes::Decimal::compare(IDB_Decimal(0, scale, precision, (int128_t) value), rhs) != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale == rhs.scale)
|
||||
@ -308,7 +421,7 @@ struct Result
|
||||
{
|
||||
Result(): intVal(0), uintVal(0), origIntVal(0), dummy(0),
|
||||
doubleVal(0), longDoubleVal(0), floatVal(0), boolVal(false),
|
||||
strVal(""), decimalVal(IDB_Decimal(0, 0, 0)),
|
||||
strVal(""), decimalVal(IDB_Decimal()),
|
||||
valueConverted(false) {}
|
||||
int64_t intVal;
|
||||
uint64_t uintVal;
|
||||
@ -783,6 +896,9 @@ inline const std::string& TreeNode::getStrVal(const std::string& timeZone)
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
dataconvert::DataConvert::decimalToString(&fResult.decimalVal.s128Value, fResult.decimalVal.scale, tmp, utils::MAXLENGTH16BYTES, fResultType.colDataType);
|
||||
else
|
||||
dataconvert::DataConvert::decimalToString(fResult.decimalVal.value, fResult.decimalVal.scale, tmp, 22, fResultType.colDataType);
|
||||
fResult.strVal = std::string(tmp);
|
||||
break;
|
||||
@ -879,9 +995,22 @@ inline int64_t TreeNode::getIntVal()
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, fResult.decimalVal.scale);
|
||||
|
||||
int128_t tmpval = fResult.decimalVal.s128Value / scaleDivisor;
|
||||
|
||||
return datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int64_t)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
|
||||
}
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
@ -1061,10 +1190,17 @@ inline double TreeNode::getDoubleVal()
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
return datatypes::Decimal::getDoubleFromWideDecimal(fResult.decimalVal.s128Value, fResult.decimalVal.scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this may not be accurate. if this is problematic, change to pre-calculated power array.
|
||||
return (double)(fResult.decimalVal.value / pow((double)10, fResult.decimalVal.scale));
|
||||
}
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
|
@ -529,7 +529,9 @@ void TupleConstantStep::fillInConstants(const rowgroup::Row& rowIn, rowgroup::Ro
|
||||
//fRowConst.copyField(rowOut.getData()+2, 0); // hardcoded 2 for rid length
|
||||
for (uint32_t i = 1; i < rowOut.getColumnCount(); i++)
|
||||
// WIP MCOL-641 implement copyBinaryField inside copyField
|
||||
if (UNLIKELY(utils::isWide(rowIn.getColumnWidth(i - 1))))
|
||||
if (UNLIKELY(utils::isWide(rowIn.getColumnWidth(i - 1)) &&
|
||||
(rowIn.getColType(i - 1) == CalpontSystemCatalog::DECIMAL ||
|
||||
rowIn.getColType(i - 1) == CalpontSystemCatalog::UDECIMAL)))
|
||||
rowIn.copyBinaryField(rowOut, i, i - 1);
|
||||
else
|
||||
rowIn.copyField(rowOut, i, i - 1);
|
||||
|
@ -4095,6 +4095,20 @@ ReturnedColumn* buildFunctionColumn(
|
||||
fc->functionParms(funcParms);
|
||||
fc->resultType(colType_MysqlToIDB(ifp));
|
||||
|
||||
// if the result type is DECIMAL and any function parameter is a wide decimal
|
||||
// column, set the result colwidth to wide
|
||||
if (fc->resultType().colDataType == CalpontSystemCatalog::DECIMAL)
|
||||
{
|
||||
for (size_t i = 0; i < funcParms.size(); i++)
|
||||
{
|
||||
if (datatypes::Decimal::isWideDecimalType(funcParms[i]->data()->resultType()))
|
||||
{
|
||||
fc->resultType().colWidth = datatypes::MAXDECIMALWIDTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MySQL give string result type for date function, but has the flag set.
|
||||
// we should set the result type to be datetime for comparision.
|
||||
if (ifp->field_type() == MYSQL_TYPE_DATETIME ||
|
||||
@ -4410,6 +4424,14 @@ ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi)
|
||||
i = 1;
|
||||
}
|
||||
|
||||
bool specialPrecision = false;
|
||||
|
||||
// handle the case when the constant value is 0.12345678901234567890123456789012345678
|
||||
// In this case idp->decimal_precision() = 39, but we can
|
||||
if (((i + 1) < str->length()) &&
|
||||
str->ptr()[i] == '0' && str->ptr()[i + 1] == '.')
|
||||
specialPrecision = true;
|
||||
|
||||
for (; i < str->length(); i++)
|
||||
{
|
||||
if (str->ptr()[i] == '.')
|
||||
@ -4420,7 +4442,9 @@ ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi)
|
||||
|
||||
if (idp->decimal_precision() <= datatypes::INT64MAXPRECISION)
|
||||
columnstore_decimal.value = strtoll(columnstore_decimal_val.str().c_str(), 0, 10);
|
||||
else if (idp->decimal_precision() <= datatypes::INT128MAXPRECISION)
|
||||
else if (idp->decimal_precision() <= datatypes::INT128MAXPRECISION ||
|
||||
(idp->decimal_precision() <= datatypes::INT128MAXPRECISION + 1 &&
|
||||
specialPrecision))
|
||||
{
|
||||
bool dummy = false;
|
||||
columnstore_decimal.s128Value =
|
||||
@ -4435,9 +4459,10 @@ ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi)
|
||||
columnstore_decimal.value = (int64_t)(val > 0 ? val + 0.5 : val - 0.5);
|
||||
}
|
||||
else
|
||||
columnstore_decimal.scale = idp->decimals;
|
||||
columnstore_decimal.scale = idp->decimal_scale();
|
||||
|
||||
columnstore_decimal.precision = idp->max_length - idp->decimals;
|
||||
columnstore_decimal.precision = (idp->decimal_precision() > datatypes::INT128MAXPRECISION) ?
|
||||
datatypes::INT128MAXPRECISION : idp->decimal_precision();
|
||||
ConstantColumn* cc = new ConstantColumn(valStr, columnstore_decimal);
|
||||
cc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
cc->charsetNumber(idp->collation.collation->number);
|
||||
|
@ -78,30 +78,6 @@ const int64_t columnstore_precision[19] =
|
||||
999999999999999999LL
|
||||
};
|
||||
|
||||
const string columnstore_big_precision[20] =
|
||||
{
|
||||
"9999999999999999999",
|
||||
"99999999999999999999",
|
||||
"999999999999999999999",
|
||||
"9999999999999999999999",
|
||||
"99999999999999999999999",
|
||||
"999999999999999999999999",
|
||||
"9999999999999999999999999",
|
||||
"99999999999999999999999999",
|
||||
"999999999999999999999999999",
|
||||
"9999999999999999999999999999",
|
||||
"99999999999999999999999999999",
|
||||
"999999999999999999999999999999",
|
||||
"9999999999999999999999999999999",
|
||||
"99999999999999999999999999999999",
|
||||
"999999999999999999999999999999999",
|
||||
"9999999999999999999999999999999999",
|
||||
"99999999999999999999999999999999999",
|
||||
"999999999999999999999999999999999999",
|
||||
"9999999999999999999999999999999999999",
|
||||
"99999999999999999999999999999999999999"
|
||||
};
|
||||
|
||||
template <class T>
|
||||
bool from_string(T& t, const std::string& s, std::ios_base & (*f)(std::ios_base&))
|
||||
{
|
||||
|
@ -118,6 +118,30 @@ const int64_t IDB_pow[19] =
|
||||
1000000000000000000LL
|
||||
};
|
||||
|
||||
const std::string columnstore_big_precision[20] =
|
||||
{
|
||||
"9999999999999999999",
|
||||
"99999999999999999999",
|
||||
"999999999999999999999",
|
||||
"9999999999999999999999",
|
||||
"99999999999999999999999",
|
||||
"999999999999999999999999",
|
||||
"9999999999999999999999999",
|
||||
"99999999999999999999999999",
|
||||
"999999999999999999999999999",
|
||||
"9999999999999999999999999999",
|
||||
"99999999999999999999999999999",
|
||||
"999999999999999999999999999999",
|
||||
"9999999999999999999999999999999",
|
||||
"99999999999999999999999999999999",
|
||||
"999999999999999999999999999999999",
|
||||
"9999999999999999999999999999999999",
|
||||
"99999999999999999999999999999999999",
|
||||
"999999999999999999999999999999999999",
|
||||
"9999999999999999999999999999999999999",
|
||||
"99999999999999999999999999999999999999"
|
||||
};
|
||||
|
||||
const int32_t SECS_PER_MIN = 60;
|
||||
const int32_t MINS_PER_HOUR = 60;
|
||||
const int32_t HOURS_PER_DAY = 24;
|
||||
|
@ -112,7 +112,7 @@ add_library(funcexp SHARED ${funcexp_LIB_SRCS})
|
||||
|
||||
add_dependencies(funcexp loggingcpp)
|
||||
|
||||
target_link_libraries(funcexp ${NETSNMP_LIBRARIES})
|
||||
target_link_libraries(funcexp ${NETSNMP_LIBRARIES} quadmath)
|
||||
|
||||
install(TARGETS funcexp DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine)
|
||||
|
||||
|
@ -66,6 +66,10 @@ IDB_Decimal Func_abs::getDecimalVal(Row& row,
|
||||
CalpontSystemCatalog::ColType&)
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
d.s128Value = (d.s128Value < 0) ? -d.s128Value : d.s128Value;
|
||||
else
|
||||
d.value = llabs(d.value);
|
||||
return d;
|
||||
}
|
||||
|
@ -102,6 +102,39 @@ bool getUIntValFromParm(
|
||||
{
|
||||
IDB_Decimal d = parm->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (parm->data()->resultType().colDataType == execplan::CalpontSystemCatalog::UDECIMAL &&
|
||||
d.value < 0)
|
||||
{
|
||||
value = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
if (tmpval > static_cast<int128_t>(INT64_MAX))
|
||||
tmpval = INT64_MAX;
|
||||
else if (tmpval < static_cast<int128_t>(INT64_MIN))
|
||||
tmpval = INT64_MIN;
|
||||
|
||||
value = tmpval;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parm->data()->resultType().colDataType == execplan::CalpontSystemCatalog::UDECIMAL &&
|
||||
d.value < 0)
|
||||
{
|
||||
@ -119,6 +152,7 @@ bool getUIntValFromParm(
|
||||
|
||||
value = tmpval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <quadmath.h>
|
||||
|
||||
#include "functor_dtm.h"
|
||||
#include "functor_int.h"
|
||||
#include "functor_real.h"
|
||||
@ -183,6 +185,28 @@ int64_t Func_cast_signed::getIntVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
return datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
int64_t value = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - value * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
@ -195,6 +219,7 @@ int64_t Func_cast_signed::getIntVal(Row& row,
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
@ -341,13 +366,40 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
double dscale = d.scale;
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.s128Value < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
uint128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval > static_cast<int128_t>(UINT64_MAX))
|
||||
tmpval = UINT64_MAX;
|
||||
|
||||
return static_cast<uint64_t>(tmpval);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d.value < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double dscale = d.scale;
|
||||
|
||||
uint64_t value = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - value * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
|
||||
@ -356,6 +408,7 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row,
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
@ -491,6 +544,9 @@ string Func_cast_char::getStrVal(Row& row,
|
||||
|
||||
char buf[80];
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
dataconvert::DataConvert::decimalToString( &d.s128Value, d.scale, buf, 80, parm[0]->data()->resultType().colDataType);
|
||||
else
|
||||
dataconvert::DataConvert::decimalToString( d.value, d.scale, buf, 80, parm[0]->data()->resultType().colDataType);
|
||||
|
||||
string sbuf = buf;
|
||||
@ -583,6 +639,12 @@ IDB_Decimal Func_cast_date::getDecimalVal(Row& row,
|
||||
{
|
||||
IDB_Decimal decimal;
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
decimal.s128Value = Func_cast_date::getDatetimeIntVal(row,
|
||||
parm,
|
||||
isNull,
|
||||
operationColType);
|
||||
else
|
||||
decimal.value = Func_cast_date::getDatetimeIntVal(row,
|
||||
parm,
|
||||
isNull,
|
||||
@ -886,6 +948,12 @@ IDB_Decimal Func_cast_datetime::getDecimalVal(Row& row,
|
||||
{
|
||||
IDB_Decimal decimal;
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
decimal.s128Value = Func_cast_datetime::getDatetimeIntVal(row,
|
||||
parm,
|
||||
isNull,
|
||||
operationColType);
|
||||
else
|
||||
decimal.value = Func_cast_datetime::getDatetimeIntVal(row,
|
||||
parm,
|
||||
isNull,
|
||||
@ -1139,6 +1207,17 @@ int64_t Func_cast_decimal::getIntVal(Row& row,
|
||||
isNull,
|
||||
operationColType);
|
||||
|
||||
if (decimal.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimal.scale);
|
||||
|
||||
int128_t tmpval = decimal.s128Value / scaleDivisor;
|
||||
|
||||
return datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
|
||||
return (int64_t) decimal.value / helpers::powerOf10_c[decimal.scale];
|
||||
}
|
||||
|
||||
@ -1155,6 +1234,9 @@ string Func_cast_decimal::getStrVal(Row& row,
|
||||
|
||||
char buf[80];
|
||||
|
||||
if (decimal.precision > datatypes::INT64MAXPRECISION)
|
||||
dataconvert::DataConvert::decimalToString( &decimal.s128Value, decimal.scale, buf, 80, operationColType.colDataType);
|
||||
else
|
||||
dataconvert::DataConvert::decimalToString( decimal.value, decimal.scale, buf, 80, operationColType.colDataType);
|
||||
|
||||
string value = buf;
|
||||
@ -1173,12 +1255,10 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
int32_t decimals = parm[1]->data()->getIntVal(row, isNull);
|
||||
int64_t max_length = parm[2]->data()->getIntVal(row, isNull);
|
||||
|
||||
// As of 2.0, max length columnStore can support is 18
|
||||
// decimal(0,0) is valid, and no limit on integer number
|
||||
if (max_length > 18 || max_length <= 0)
|
||||
max_length = 18;
|
||||
if (max_length > datatypes::INT128MAXPRECISION || max_length <= 0)
|
||||
max_length = datatypes::INT128MAXPRECISION;
|
||||
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
decimal.precision = max_length;
|
||||
|
||||
switch (parm[0]->data()->resultType().colDataType)
|
||||
{
|
||||
@ -1188,6 +1268,31 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
decimal.s128Value = parm[0]->data()->getIntVal(row, isNull);
|
||||
decimal.scale = 0;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
int128_t value = decimal.s128Value * scaleDivisor;
|
||||
|
||||
if ( value > max_number_decimal )
|
||||
{
|
||||
decimal.s128Value = max_number_decimal;
|
||||
decimal.scale = decimals;
|
||||
}
|
||||
else if ( value < -max_number_decimal )
|
||||
{
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
decimal.scale = decimals;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
decimal.value = parm[0]->data()->getIntVal(row, isNull);
|
||||
decimal.scale = 0;
|
||||
int64_t value = decimal.value * helpers::powerOf10_c[decimals];
|
||||
@ -1203,6 +1308,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
decimal.scale = decimals;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
@ -1211,6 +1317,35 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
uint128_t uval = parm[0]->data()->getUintVal(row, isNull);
|
||||
|
||||
if (uval > (uint128_t)datatypes::Decimal::maxInt128)
|
||||
{
|
||||
uval = datatypes::Decimal::maxInt128;
|
||||
}
|
||||
|
||||
decimal.s128Value = uval;
|
||||
decimal.scale = 0;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
int128_t value = decimal.s128Value * scaleDivisor;
|
||||
|
||||
if ( value > max_number_decimal )
|
||||
{
|
||||
decimal.s128Value = max_number_decimal;
|
||||
decimal.scale = decimals;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
uint64_t uval = parm[0]->data()->getUintVal(row, isNull);
|
||||
|
||||
if (uval > (uint64_t)numeric_limits<int64_t>::max())
|
||||
@ -1228,6 +1363,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
decimal.scale = decimals;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
@ -1235,6 +1371,35 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
__float128 value = parm[0]->data()->getDoubleVal(row, isNull);
|
||||
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
|
||||
if (value > 0)
|
||||
decimal.s128Value = (int128_t) (value * scaleDivisor + 0.5);
|
||||
else if (value < 0)
|
||||
decimal.s128Value = (int128_t) (value * scaleDivisor - 0.5);
|
||||
else
|
||||
decimal.s128Value = 0;
|
||||
|
||||
decimal.scale = decimals;
|
||||
|
||||
if ( value > max_number_decimal )
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if ( value < -max_number_decimal )
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
double value = parm[0]->data()->getDoubleVal(row, isNull);
|
||||
|
||||
if (value > 0)
|
||||
@ -1251,10 +1416,40 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
else if ( value < -max_number_decimal )
|
||||
decimal.value = -max_number_decimal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
__float128 value = parm[0]->data()->getLongDoubleVal(row, isNull);
|
||||
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
|
||||
if (value > 0)
|
||||
decimal.s128Value = (int128_t) (value * scaleDivisor + 0.5);
|
||||
else if (value < 0)
|
||||
decimal.s128Value = (int128_t) (value * scaleDivisor - 0.5);
|
||||
else
|
||||
decimal.s128Value = 0;
|
||||
|
||||
decimal.scale = decimals;
|
||||
|
||||
if ( value > max_number_decimal )
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if ( value < -max_number_decimal )
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
|
||||
|
||||
if (value > 0)
|
||||
@ -1271,13 +1466,62 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
else if ( value < -max_number_decimal )
|
||||
decimal.value = -max_number_decimal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, abs(decimals - decimal.scale));
|
||||
|
||||
if (decimal.precision <= datatypes::INT64MAXPRECISION)
|
||||
decimal.s128Value = decimal.value;
|
||||
|
||||
decimal.precision = max_length;
|
||||
|
||||
if (scaleDivisor > 1)
|
||||
{
|
||||
if (decimals > decimal.scale)
|
||||
decimal.s128Value *= scaleDivisor;
|
||||
else
|
||||
decimal.s128Value = (int128_t)(decimal.s128Value > 0 ?
|
||||
(__float128)decimal.s128Value / scaleDivisor + 0.5 :
|
||||
(__float128)decimal.s128Value / scaleDivisor - 0.5);
|
||||
}
|
||||
|
||||
decimal.scale = decimals;
|
||||
|
||||
if ( decimal.s128Value > max_number_decimal )
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if ( decimal.s128Value < -max_number_decimal )
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (decimal.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if ( decimal.s128Value > (int128_t) max_number_decimal )
|
||||
decimal.value = max_number_decimal;
|
||||
else if ( decimal.s128Value < (int128_t) -max_number_decimal )
|
||||
decimal.value = -max_number_decimal;
|
||||
else
|
||||
decimal.value = decimal.s128Value;
|
||||
}
|
||||
|
||||
decimal.precision = max_length;
|
||||
|
||||
if (decimals > decimal.scale)
|
||||
decimal.value *= helpers::powerOf10_c[decimals - decimal.scale];
|
||||
@ -1288,15 +1532,12 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
|
||||
decimal.scale = decimals;
|
||||
|
||||
|
||||
|
||||
//int64_t value = decimal.value;
|
||||
|
||||
if ( decimal.value > max_number_decimal )
|
||||
decimal.value = max_number_decimal;
|
||||
else if ( decimal.value < -max_number_decimal )
|
||||
decimal.value = -max_number_decimal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
@ -1313,9 +1554,6 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
int negate = 1;
|
||||
bool bFoundSign = false;
|
||||
bool bRound = false;
|
||||
double floatValue;
|
||||
int64_t value = 0;
|
||||
int64_t frac = 0;
|
||||
|
||||
if (strValue.empty())
|
||||
{
|
||||
@ -1331,7 +1569,42 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
{
|
||||
if (*s == 'e' || *s == 'E')
|
||||
{
|
||||
floatValue = strtod(str, 0);
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
|
||||
__float128 floatValue = strtoflt128 (str, 0);
|
||||
|
||||
// If the float value is too large, the saturated result may end up with
|
||||
// the wrong sign, so we just check first.
|
||||
if ((int128_t)floatValue > max_number_decimal)
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if ((int128_t)floatValue < -max_number_decimal)
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
else if (floatValue > 0)
|
||||
decimal.s128Value = (int128_t) (floatValue * scaleDivisor + 0.5);
|
||||
else if (floatValue < 0)
|
||||
decimal.s128Value = (int128_t) (floatValue * scaleDivisor - 0.5);
|
||||
else
|
||||
decimal.s128Value = 0;
|
||||
|
||||
if (decimal.s128Value > max_number_decimal)
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if (decimal.s128Value < -max_number_decimal)
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
|
||||
return decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
double floatValue = strtod(str, 0);
|
||||
|
||||
// If the float value is too large, the saturated result may end up with
|
||||
// the wrong sign, so we just check first.
|
||||
@ -1354,6 +1627,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
return decimal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// There are cases (such as "-.95" that should return that may not result in the desired rounding.
|
||||
// By stripping the sign and adding it back in later, we can get a more accurate answer.
|
||||
@ -1392,6 +1666,70 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
}
|
||||
}
|
||||
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
bool dummy = false;
|
||||
char *ep = NULL;
|
||||
int128_t max_number_decimal = dataconvert::strtoll128(columnstore_big_precision[max_length - 19].c_str(), dummy, &ep);
|
||||
|
||||
int128_t value = 0, frac = 0;
|
||||
|
||||
if (firstInt) // Checking to see if we have a decimal point, but no previous digits.
|
||||
{
|
||||
value = dataconvert::strtoll128(firstInt, dummy, &endptr);
|
||||
}
|
||||
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, decimals);
|
||||
|
||||
if (!dummy && endptr)
|
||||
{
|
||||
// Scale the integer portion according to the DECIMAL description
|
||||
value *= scaleDivisor;
|
||||
|
||||
// Get the fractional part.
|
||||
if (endptr && (*endptr == *convData->decimal_point || *endptr == '.'))
|
||||
{
|
||||
s = endptr + 1;
|
||||
|
||||
// Get the digits to the right of the decimal
|
||||
// Only retrieve those that matter based on scale.
|
||||
for (fracChars = 0;
|
||||
*s && isdigit(*s) && fracChars < decimals;
|
||||
++fracChars, ++s)
|
||||
{
|
||||
// Save the frac characters to a side buffer. This way we can limit
|
||||
// ourselves to the scale without modifying the original string.
|
||||
fracBuf[fracChars] = *s;
|
||||
}
|
||||
|
||||
fracBuf[fracChars] = 0;
|
||||
|
||||
// Check to see if we need to round
|
||||
if (isdigit(*s) && *s > '4')
|
||||
{
|
||||
bRound = true;
|
||||
}
|
||||
}
|
||||
|
||||
frac = dataconvert::strtoll128(fracBuf, dummy, &ep);
|
||||
value += frac + (bRound ? 1 : 0);
|
||||
value *= negate;
|
||||
}
|
||||
|
||||
decimal.s128Value = value;
|
||||
|
||||
if (decimal.s128Value > max_number_decimal)
|
||||
decimal.s128Value = max_number_decimal;
|
||||
else if (decimal.s128Value < -max_number_decimal)
|
||||
decimal.s128Value = -max_number_decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t max_number_decimal = helpers::maxNumber_c[max_length];
|
||||
|
||||
int64_t value = 0, frac = 0;
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (firstInt) // Checking to see if we have a decimal point, but no previous digits.
|
||||
@ -1441,6 +1779,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
else if (decimal.value < -max_number_decimal)
|
||||
decimal.value = -max_number_decimal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
@ -1452,7 +1791,11 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
decimal.s128Value = x;
|
||||
else
|
||||
decimal.value = x;
|
||||
|
||||
decimal.scale = s;
|
||||
}
|
||||
}
|
||||
@ -1471,7 +1814,11 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
decimal.s128Value = x;
|
||||
else
|
||||
decimal.value = x;
|
||||
|
||||
decimal.scale = s;
|
||||
}
|
||||
}
|
||||
@ -1490,7 +1837,11 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
decimal.s128Value = x;
|
||||
else
|
||||
decimal.value = x;
|
||||
|
||||
decimal.scale = s;
|
||||
}
|
||||
}
|
||||
@ -1509,7 +1860,11 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
if (max_length > datatypes::INT64MAXPRECISION)
|
||||
decimal.s128Value = x;
|
||||
else
|
||||
decimal.value = x;
|
||||
|
||||
decimal.scale = s;
|
||||
}
|
||||
}
|
||||
@ -1536,6 +1891,11 @@ double Func_cast_decimal::getDoubleVal(Row& row,
|
||||
isNull,
|
||||
operationColType);
|
||||
|
||||
if (decimal.precision > datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
return datatypes::Decimal::getDoubleFromWideDecimal(decimal.s128Value, decimal.scale);
|
||||
}
|
||||
|
||||
return (double) decimal.value / helpers::powerOf10_c[decimal.scale];
|
||||
}
|
||||
|
||||
@ -1642,8 +2002,15 @@ double Func_cast_double::getDoubleVal(Row& row,
|
||||
{
|
||||
IDB_Decimal decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
dblval = datatypes::Decimal::getDoubleFromWideDecimal(decimal.s128Value, decimal.scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
dblval = (double)(decimal.value / pow((double)10, decimal.scale));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
|
@ -65,42 +65,58 @@ int64_t Func_ceil::getIntVal(Row& row,
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (op_ct.scale == 0)
|
||||
{
|
||||
ret = parm[0]->data()->getIntVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
IDB_Decimal decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
// ceil(decimal(38,38)) leads to this path
|
||||
// otherwise Func_ceil::getDecimalVal() is called
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
ret = decimal.value;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (decimal.scale > 0)
|
||||
if (d.scale > 0)
|
||||
{
|
||||
|
||||
if (decimal.scale >= 19)
|
||||
if (d.scale > datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "ceil: datatype of " << colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) decimal.scale << " is beyond supported scale";
|
||||
oss << "ceil: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) d.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
// Adjust to an int based on the scale.
|
||||
int64_t tmp = ret;
|
||||
ret /= helpers::powerOf10_c[decimal.scale];
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t tmp = d.s128Value;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
d.s128Value /= scaleDivisor;
|
||||
|
||||
// Add 1 if this is a positive number and there were values to the right of the
|
||||
// decimal point so that we return the largest integer value not less than X.
|
||||
if ((tmp - (ret * helpers::powerOf10_c[decimal.scale]) > 0))
|
||||
ret += 1;
|
||||
if ((tmp - (d.s128Value * scaleDivisor)) > 0)
|
||||
d.s128Value += 1;
|
||||
|
||||
ret = datatypes::Decimal::getInt64FromWideDecimal(d.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t tmp = d.value;
|
||||
d.value /= helpers::powerOf10_c[d.scale];
|
||||
|
||||
// Add 1 if this is a positive number and there were values to the right of the
|
||||
// decimal point so that we return the largest integer value not less than X.
|
||||
if ((tmp - (d.value * helpers::powerOf10_c[d.scale])) > 0)
|
||||
d.value += 1;
|
||||
|
||||
ret = d.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -308,6 +324,20 @@ double Func_ceil::getDoubleVal(Row& row,
|
||||
{
|
||||
ret = (double)ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isUnsigned(op_ct.colDataType))
|
||||
@ -350,6 +380,20 @@ long double Func_ceil::getLongDoubleVal(Row& row,
|
||||
if (!isNull)
|
||||
ret = ceil(strtod(str.c_str(), 0));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getLongDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (long double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isUnsigned(op_ct.colDataType))
|
||||
@ -403,6 +447,20 @@ string Func_ceil::getStrVal(Row& row,
|
||||
|
||||
*d = '\0';
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal d = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(&d.s128Value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(d.value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
}
|
||||
else if (isUnsigned(op_ct.colDataType))
|
||||
{
|
||||
#ifndef __LP64__
|
||||
@ -424,5 +482,156 @@ string Func_ceil::getStrVal(Row& row,
|
||||
}
|
||||
|
||||
|
||||
IDB_Decimal Func_ceil::getDecimalVal(Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
IDB_Decimal ret;
|
||||
|
||||
switch (op_ct.colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
{
|
||||
ret.value = parm[0]->data()->getIntVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
ret = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (ret.scale > 0)
|
||||
{
|
||||
if (ret.scale > datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "ceil: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) ret.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t tmp = ret.s128Value;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, ret.scale);
|
||||
ret.s128Value /= scaleDivisor;
|
||||
|
||||
// Add 1 if this is a positive number and there were values to the right of the
|
||||
// decimal point so that we return the largest integer value not less than X.
|
||||
if ((tmp - (ret.s128Value * scaleDivisor)) > 0)
|
||||
ret.s128Value += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t tmp = ret.value;
|
||||
ret.value /= helpers::powerOf10_c[ret.scale];
|
||||
|
||||
// Add 1 if this is a positive number and there were values to the right of the
|
||||
// decimal point so that we return the largest integer value not less than X.
|
||||
if ((tmp - (ret.value * helpers::powerOf10_c[ret.scale])) > 0)
|
||||
ret.value += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
{
|
||||
ret.value = (int64_t)parm[0]->data()->getUintVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
ret.value = (int64_t) ceil(parm[0]->data()->getDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
ret.value = (int64_t) ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
const string& str = parm[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = (int64_t) ceil(strtod(str.c_str(), 0));
|
||||
}
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DATE:
|
||||
{
|
||||
Date d (parm[0]->data()->getDateIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = d.convertToMySQLint();
|
||||
}
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
DateTime dt(parm[0]->data()->getDatetimeIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = dt.convertToMySQLint();
|
||||
}
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::TIMESTAMP:
|
||||
{
|
||||
TimeStamp dt(parm[0]->data()->getTimestampIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = dt.convertToMySQLint(timeZone());
|
||||
}
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::TIME:
|
||||
{
|
||||
Time dt(parm[0]->data()->getTimeIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = dt.convertToMySQLint();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "ceil: datatype of " << colDataTypeToString(op_ct.colDataType)
|
||||
<< " is not supported";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
}
|
||||
|
||||
ret.scale = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
@ -134,15 +134,50 @@ string Func_char::getStrVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = rc->getDecimalVal(row, isNull);
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.s128Value < 0)
|
||||
return "";
|
||||
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval > static_cast<int128_t>(INT64_MAX))
|
||||
tmpval = INT64_MAX;
|
||||
|
||||
if ( !getChar((int64_t)tmpval, buf) )
|
||||
{
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
// get decimal and round up
|
||||
value = d.value / pow(10.0, dscale);
|
||||
int value = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - value * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
|
||||
if ( lefto > 4 )
|
||||
value++;
|
||||
|
||||
if ( !getChar((int64_t)value, buf) )
|
||||
{
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -73,6 +73,28 @@ string Func_elt::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (utils::is_nonnegative(tmpval) >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (utils::is_negative(tmpval) < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
number = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
number = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - number * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
@ -82,6 +104,7 @@ string Func_elt::getStrVal(rowgroup::Row& row,
|
||||
|
||||
if ( utils::is_negative(number) && lefto < -4 )
|
||||
number--;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -62,41 +62,8 @@ int64_t Func_floor::getIntVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (op_ct.scale == 0)
|
||||
{
|
||||
ret = parm[0]->data()->getIntVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
IDB_Decimal decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
ret = decimal.value;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (decimal.scale > 0)
|
||||
{
|
||||
|
||||
if (decimal.scale >= 19)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) decimal.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
int64_t tmp = ret;
|
||||
ret /= helpers::powerOf10_c[decimal.scale];
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret)
|
||||
ret -= 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -338,6 +305,20 @@ double Func_floor::getDoubleVal(Row& row,
|
||||
if (!isNull)
|
||||
ret = floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (double) getIntVal(row, parm, isNull, op_ct);
|
||||
@ -371,6 +352,20 @@ long double Func_floor::getLongDoubleVal(Row& row,
|
||||
if (!isNull)
|
||||
ret = floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getLongDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (long double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (long double) getIntVal(row, parm, isNull, op_ct);
|
||||
@ -416,6 +411,20 @@ string Func_floor::getStrVal(Row& row,
|
||||
|
||||
*d = '\0';
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal d = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(&d.s128Value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(d.value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
}
|
||||
else if (isUnsigned(op_ct.colDataType))
|
||||
{
|
||||
#ifndef __LP64__
|
||||
@ -436,6 +445,165 @@ string Func_floor::getStrVal(Row& row,
|
||||
return string(tmp);
|
||||
}
|
||||
|
||||
IDB_Decimal Func_floor::getDecimalVal(Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
IDB_Decimal ret;
|
||||
|
||||
switch (op_ct.colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
{
|
||||
ret.value = parm[0]->data()->getIntVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
ret = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (ret.scale > 0)
|
||||
{
|
||||
if (ret.scale > datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) ret.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t tmp = ret.s128Value;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, ret.scale);
|
||||
ret.s128Value /= scaleDivisor;
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret.s128Value)
|
||||
ret.s128Value -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t tmp = ret.value;
|
||||
ret.value /= helpers::powerOf10_c[ret.scale];
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret.value)
|
||||
ret.value -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
{
|
||||
ret.value = (int64_t)parm[0]->data()->getUintVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
ret.value = (int64_t) floor(parm[0]->data()->getDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
ret.value = (int64_t) floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
const string& str = parm[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = (int64_t) floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
{
|
||||
string str = DataConvert::dateToString1(parm[0]->data()->getDateIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
string str =
|
||||
DataConvert::datetimeToString1(parm[0]->data()->getDatetimeIntVal(row, isNull));
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::TIMESTAMP:
|
||||
{
|
||||
string str =
|
||||
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::TIME:
|
||||
{
|
||||
string str =
|
||||
DataConvert::timeToString1(parm[0]->data()->getTimeIntVal(row, isNull));
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType);
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
}
|
||||
|
||||
ret.scale = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
@ -154,21 +154,34 @@ execplan::IDB_Decimal Func_inet_aton::getDecimalVal(rowgroup::Row& row,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
// std::cout << "In Func_inet_aton::getDecimalVal" << std::endl;
|
||||
|
||||
execplan::IDB_Decimal dValue ( joblist::NULL_INT64, 0, 0 );
|
||||
execplan::CalpontSystemCatalog::ColType colType = fp[0]->data()->resultType();
|
||||
|
||||
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (colType.precision <= datatypes::INT64MAXPRECISION)
|
||||
{
|
||||
if (!isNull)
|
||||
{
|
||||
int64_t iValue = convertAton( sValue, isNull );
|
||||
|
||||
if (!isNull)
|
||||
return execplan::IDB_Decimal( iValue, 0, 0 );
|
||||
return execplan::IDB_Decimal( iValue, colType.scale, colType.precision );
|
||||
}
|
||||
|
||||
return dValue;
|
||||
return execplan::IDB_Decimal( joblist::NULL_INT64, colType.scale, colType.precision );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNull)
|
||||
{
|
||||
int64_t iValue = convertAton( sValue, isNull );
|
||||
|
||||
if (!isNull)
|
||||
return execplan::IDB_Decimal( 0, colType.scale, colType.precision, (int128_t) iValue );
|
||||
}
|
||||
|
||||
return execplan::IDB_Decimal( 0, colType.scale, colType.precision, datatypes::Decimal128Null );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -211,8 +211,6 @@ execplan::IDB_Decimal Func_inet_ntoa::getDecimalVal(rowgroup::Row& row,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
// std::cout << "In Func_inet_ntoa::getDecimalVal" << std::endl;
|
||||
|
||||
// IDB_Decimal dValue = fp[0]->data()->getDecimalVal(row, isNull);
|
||||
execplan::IDB_Decimal dValue ( joblist::NULL_INT64, 0, 0 );
|
||||
isNull = true;
|
||||
|
@ -68,6 +68,28 @@ uint64_t makedate(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
year = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
year = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - year * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
@ -77,6 +99,7 @@ uint64_t makedate(rowgroup::Row& row,
|
||||
|
||||
if ( year < 0 && lefto < -4 )
|
||||
year--;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -128,6 +151,35 @@ uint64_t makedate(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[1]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
if (tmpval < 1)
|
||||
{
|
||||
isNull = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t tmpval64 = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
dayofyear = helpers::intToString(tmpval64);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dscale = d.scale;
|
||||
int64_t tmp = d.value / pow(10.0, dscale);
|
||||
int lefto = (d.value - tmp * pow(10.0, dscale)) / pow(10.0, dscale - 1);
|
||||
@ -145,6 +197,7 @@ uint64_t makedate(rowgroup::Row& row,
|
||||
}
|
||||
|
||||
dayofyear = helpers::intToString(tmp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,28 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
hour = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
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);
|
||||
@ -83,6 +105,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
|
||||
if ( hour < 0 && lefto < -4 )
|
||||
hour--;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -114,6 +137,28 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[1]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
min = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
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);
|
||||
@ -123,6 +168,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
|
||||
if ( min < 0 && lefto < -4 )
|
||||
min--;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -160,6 +206,28 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[2]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[2]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t scaleDivisor, scaleDivisor2;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
|
||||
scaleDivisor2 = (scaleDivisor <= 10) ? 1 : (scaleDivisor / 10);
|
||||
|
||||
int128_t tmpval = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = (d.s128Value - tmpval * scaleDivisor) / scaleDivisor2;
|
||||
|
||||
if (tmpval >= 0 && lefto > 4)
|
||||
tmpval++;
|
||||
|
||||
if (tmpval < 0 && lefto < -4)
|
||||
tmpval--;
|
||||
|
||||
sec = datatypes::Decimal::getInt64FromWideDecimal(tmpval);
|
||||
}
|
||||
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);
|
||||
@ -169,6 +237,7 @@ string Func_maketime::getStrVal(rowgroup::Row& row,
|
||||
|
||||
if ( sec < 0 && lefto < -4 )
|
||||
sec--;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <quadmath.h>
|
||||
|
||||
#include "functor_real.h"
|
||||
#include "funchelpers.h"
|
||||
#include "functioncolumn.h"
|
||||
@ -54,7 +56,6 @@ IDB_Decimal Func_mod::getDecimalVal(Row& row,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& operationColType)
|
||||
{
|
||||
|
||||
IDB_Decimal retValue;
|
||||
retValue.value = 0;
|
||||
retValue.scale = 0;
|
||||
@ -65,6 +66,68 @@ IDB_Decimal Func_mod::getDecimalVal(Row& row,
|
||||
return retValue;
|
||||
}
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH ||
|
||||
parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
IDB_Decimal div = parm[1]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
int128_t divInt, dividendInt;
|
||||
|
||||
if (parm[1]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
divInt = div.s128Value;
|
||||
else
|
||||
divInt = div.value;
|
||||
|
||||
if (divInt == 0)
|
||||
{
|
||||
isNull = true;
|
||||
return retValue;
|
||||
}
|
||||
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
dividendInt = d.s128Value;
|
||||
else
|
||||
dividendInt = d.value;
|
||||
|
||||
// integer division
|
||||
if (d.scale == 0 && div.scale == 0)
|
||||
{
|
||||
retValue.s128Value = dividendInt % divInt;
|
||||
}
|
||||
// special case integer division
|
||||
else if (div.scale == 0)
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t value = dividendInt / scaleDivisor;
|
||||
int128_t lefto = dividendInt % scaleDivisor;
|
||||
int128_t mod = (value % divInt) * scaleDivisor + lefto;
|
||||
retValue.s128Value = mod;
|
||||
}
|
||||
// float division
|
||||
else
|
||||
{
|
||||
__float128 divF, dividendF;
|
||||
|
||||
int128_t scaleDivisor;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, div.scale);
|
||||
divF = (__float128) divInt / scaleDivisor;
|
||||
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
dividendF = (__float128) dividendInt / scaleDivisor;
|
||||
|
||||
__float128 mod = fmodq(dividendF, divF) * scaleDivisor;
|
||||
|
||||
retValue.s128Value = (int128_t) mod;
|
||||
}
|
||||
retValue.scale = d.scale;
|
||||
retValue.precision = datatypes::INT128MAXPRECISION;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t div = parm[1]->data()->getIntVal(row, isNull);
|
||||
|
||||
if ( div == 0 )
|
||||
@ -81,6 +144,7 @@ IDB_Decimal Func_mod::getDecimalVal(Row& row,
|
||||
|
||||
retValue.value = mod;
|
||||
retValue.scale = d.scale;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
@ -164,10 +228,29 @@ double Func_mod::getDoubleVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.scale == 0)
|
||||
{
|
||||
mod = d.s128Value % div;
|
||||
}
|
||||
else
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t value = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = d.s128Value % scaleDivisor;
|
||||
__float128 tmp = (__float128) (value % div) + (__float128) lefto / scaleDivisor;
|
||||
mod = datatypes::Decimal::getDoubleFromFloat128(tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
mod = value % div;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
@ -268,10 +351,29 @@ long double Func_mod::getLongDoubleVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.scale == 0)
|
||||
{
|
||||
mod = d.s128Value % div;
|
||||
}
|
||||
else
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t value = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = d.s128Value % scaleDivisor;
|
||||
__float128 tmp = (__float128) (value % div) + (__float128) lefto / scaleDivisor;
|
||||
mod = datatypes::Decimal::getLongDoubleFromFloat128(tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
mod = value % div;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
@ -375,10 +477,29 @@ int64_t Func_mod::getIntVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.scale == 0)
|
||||
{
|
||||
mod = d.s128Value % div;
|
||||
}
|
||||
else
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t value = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = d.s128Value % scaleDivisor;
|
||||
__float128 tmp = (__float128) (value % div) + (__float128) lefto / scaleDivisor;
|
||||
mod = datatypes::Decimal::getInt64FromFloat128(tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
mod = value % div;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -473,10 +594,29 @@ uint64_t Func_mod::getUIntVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
if (d.scale == 0)
|
||||
{
|
||||
mod = d.s128Value % div;
|
||||
}
|
||||
else
|
||||
{
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, d.scale);
|
||||
int128_t value = d.s128Value / scaleDivisor;
|
||||
int128_t lefto = d.s128Value % scaleDivisor;
|
||||
__float128 tmp = (__float128) (value % div) + (__float128) lefto / scaleDivisor;
|
||||
mod = datatypes::Decimal::getUInt64FromFloat128(tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t value = d.value / pow(10.0, d.scale);
|
||||
mod = value % div;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -197,6 +197,10 @@ execplan::IDB_Decimal Func_monthname::getDecimalVal(rowgroup::Row& row,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
IDB_Decimal d;
|
||||
|
||||
if (fp[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
d.s128Value = getIntVal(row, fp, isNull, op_ct);
|
||||
else
|
||||
d.value = getIntVal(row, fp, isNull, op_ct);
|
||||
d.scale = 0;
|
||||
return d;
|
||||
|
@ -86,7 +86,24 @@ int64_t Func_period_diff::getIntVal(rowgroup::Row& row,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -135,7 +152,24 @@ int64_t Func_period_diff::getIntVal(rowgroup::Row& row,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,8 @@ int64_t Func_round::getIntVal(Row& row,
|
||||
{
|
||||
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
{
|
||||
if (x.scale > 0)
|
||||
{
|
||||
while (x.scale-- > 0)
|
||||
@ -129,6 +131,22 @@ int64_t Func_round::getIntVal(Row& row,
|
||||
|
||||
return x.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x.scale > 0)
|
||||
{
|
||||
while (x.scale-- > 0)
|
||||
x.s128Value /= 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (x.scale++ < 0)
|
||||
x.s128Value *= 10;
|
||||
}
|
||||
|
||||
return datatypes::Decimal::getInt64FromWideDecimal(x.s128Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t Func_round::getUintVal(Row& row,
|
||||
@ -187,7 +205,12 @@ double Func_round::getDoubleVal(Row& row,
|
||||
if (isNull)
|
||||
return 0.0;
|
||||
|
||||
double d = x.value;
|
||||
double d;
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
d = x.value;
|
||||
else
|
||||
d = datatypes::Decimal::getDoubleFromWideDecimal(x.s128Value);
|
||||
|
||||
if (x.scale > 0)
|
||||
{
|
||||
@ -249,7 +272,12 @@ long double Func_round::getLongDoubleVal(Row& row,
|
||||
if (isNull)
|
||||
return 0.0;
|
||||
|
||||
double d = x.value;
|
||||
double d;
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
d = x.value;
|
||||
else
|
||||
d = datatypes::Decimal::getDoubleFromWideDecimal(x.s128Value);
|
||||
|
||||
if (x.scale > 0)
|
||||
{
|
||||
@ -283,9 +311,12 @@ IDB_Decimal Func_round::getDecimalVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
int64_t d = 0;
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
{
|
||||
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
|
||||
volatile int64_t p = 1;
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (!isNull && parm.size() > 1) // round(X, D)
|
||||
{
|
||||
@ -340,6 +371,71 @@ IDB_Decimal Func_round::getDecimalVal(Row& row,
|
||||
|
||||
decimal.value = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
|
||||
volatile int128_t p = 1;
|
||||
|
||||
if (!isNull && parm.size() > 1) // round(X, D)
|
||||
{
|
||||
int128_t nvp = p;
|
||||
d = parm[1]->data()->getIntVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
helpers::decimalPlaceDec(d, nvp, decimal.scale);
|
||||
|
||||
p = nvp;
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
if (d < -datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
decimal.s128Value = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int128_t x = decimal.s128Value;
|
||||
|
||||
if (d > 0)
|
||||
{
|
||||
x = x * p;
|
||||
}
|
||||
else if (d < 0)
|
||||
{
|
||||
int128_t h = p / 2; // 0.5
|
||||
|
||||
if ((x >= h) || (x <= -h))
|
||||
{
|
||||
if (x >= 0)
|
||||
x += h;
|
||||
else
|
||||
x -= h;
|
||||
|
||||
if (p != 0)
|
||||
x = x / p;
|
||||
else
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// negative scale is not supported by CNX yet, set d to 0.
|
||||
if (decimal.scale < 0)
|
||||
{
|
||||
do
|
||||
x *= 10;
|
||||
|
||||
while (++decimal.scale < 0);
|
||||
}
|
||||
|
||||
decimal.s128Value = x;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
@ -624,7 +720,14 @@ string Func_round::getStrVal(Row& row,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
return dataconvert::DataConvert::decimalToString(x.value, x.scale, op_ct.colDataType);
|
||||
else
|
||||
{
|
||||
char buf[utils::MAXLENGTH16BYTES];
|
||||
dataconvert::DataConvert::decimalToString( &x.s128Value, x.scale, buf, utils::MAXLENGTH16BYTES, op_ct.colDataType);
|
||||
return string(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -257,12 +257,15 @@ execplan::IDB_Decimal Func_sec_to_time::getDecimalVal(rowgroup::Row& row,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
IDB_Decimal d;
|
||||
|
||||
int64_t val = parm[0]->data()->getIntVal(row, isNull);
|
||||
|
||||
int64_t tmpVal;
|
||||
|
||||
if (val > 3020399)
|
||||
d.value = 8385959;
|
||||
tmpVal = 8385959;
|
||||
else if (val < -3020399)
|
||||
d.value = 4286581337LL;
|
||||
tmpVal = 4286581337LL;
|
||||
else
|
||||
{
|
||||
string time = getStrVal(row, parm, isNull, op_ct);
|
||||
@ -277,15 +280,17 @@ execplan::IDB_Decimal Func_sec_to_time::getDecimalVal(rowgroup::Row& row,
|
||||
char* ep = NULL;
|
||||
const char* str = time.c_str();
|
||||
errno = 0;
|
||||
d.value = strtoll(str, &ep, 10);
|
||||
tmpVal = strtoll(str, &ep, 10);
|
||||
}
|
||||
|
||||
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
d.s128Value = tmpVal;
|
||||
else
|
||||
d.value = tmpVal;
|
||||
|
||||
d.scale = 0;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
@ -119,6 +119,8 @@ int64_t Func_truncate::getIntVal(Row& row,
|
||||
{
|
||||
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
{
|
||||
if (x.scale > 0)
|
||||
{
|
||||
while (x.scale-- > 0)
|
||||
@ -132,6 +134,22 @@ int64_t Func_truncate::getIntVal(Row& row,
|
||||
|
||||
return x.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x.scale > 0)
|
||||
{
|
||||
while (x.scale-- > 0)
|
||||
x.s128Value /= 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (x.scale++ < 0)
|
||||
x.s128Value *= 10;
|
||||
}
|
||||
|
||||
return datatypes::Decimal::getInt64FromWideDecimal(x.s128Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t Func_truncate::getUintVal(Row& row,
|
||||
@ -210,7 +228,12 @@ double Func_truncate::getDoubleVal(Row& row,
|
||||
if (isNull)
|
||||
return 0.0;
|
||||
|
||||
double d = x.value;
|
||||
double d;
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
d = x.value;
|
||||
else
|
||||
d = datatypes::Decimal::getDoubleFromWideDecimal(x.s128Value);
|
||||
|
||||
if (x.scale > 0)
|
||||
{
|
||||
@ -265,7 +288,12 @@ long double Func_truncate::getLongDoubleVal(Row& row,
|
||||
if (isNull)
|
||||
return 0.0;
|
||||
|
||||
double d = x.value;
|
||||
double d;
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
d = x.value;
|
||||
else
|
||||
d = datatypes::Decimal::getDoubleFromWideDecimal(x.s128Value);
|
||||
|
||||
if (x.scale > 0)
|
||||
{
|
||||
@ -304,9 +332,12 @@ IDB_Decimal Func_truncate::getDecimalVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
int64_t d = 0;
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
{
|
||||
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
|
||||
volatile int64_t p = 1;
|
||||
decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
@ -354,6 +385,64 @@ IDB_Decimal Func_truncate::getDecimalVal(Row& row,
|
||||
|
||||
decimal.value = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
|
||||
volatile int128_t p = 1;
|
||||
|
||||
if (!isNull)
|
||||
{
|
||||
int128_t nvp = p;
|
||||
d = parm[1]->data()->getIntVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
helpers::decimalPlaceDec(d, nvp, decimal.scale);
|
||||
|
||||
p = nvp;
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
if (d < -datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
decimal.s128Value = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int128_t x = decimal.s128Value;
|
||||
|
||||
if (d > 0)
|
||||
{
|
||||
x = x * p;
|
||||
}
|
||||
else if (d < 0)
|
||||
{
|
||||
if ((x >= p) || (x <= -p))
|
||||
{
|
||||
if (p != 0)
|
||||
x = x / p;
|
||||
else
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// negative scale is not supported by CNX yet, set d to 0.
|
||||
if (decimal.scale < 0)
|
||||
{
|
||||
do
|
||||
x *= 10;
|
||||
|
||||
while (++decimal.scale < 0);
|
||||
}
|
||||
|
||||
decimal.s128Value = x;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
@ -650,7 +739,14 @@ string Func_truncate::getStrVal(Row& row,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!datatypes::Decimal::isWideDecimalType(op_ct))
|
||||
return dataconvert::DataConvert::decimalToString(x.value, x.scale, op_ct.colDataType);
|
||||
else
|
||||
{
|
||||
char buf[utils::MAXLENGTH16BYTES];
|
||||
dataconvert::DataConvert::decimalToString( &x.s128Value, x.scale, buf, utils::MAXLENGTH16BYTES, op_ct.colDataType);
|
||||
return string(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -470,7 +470,8 @@ inline int power ( int16_t a )
|
||||
return b;
|
||||
}
|
||||
|
||||
inline void decimalPlaceDec(int64_t& d, int64_t& p, int8_t& s)
|
||||
template <typename T>
|
||||
inline void decimalPlaceDec(int64_t& d, T& p, int8_t& s)
|
||||
{
|
||||
// find new scale if D < s
|
||||
if (d < s)
|
||||
|
@ -281,6 +281,11 @@ public:
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
|
||||
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
};
|
||||
|
||||
|
||||
@ -318,6 +323,11 @@ public:
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
|
||||
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
};
|
||||
|
||||
|
||||
|
@ -1947,6 +1947,10 @@ inline void copyRow(const Row& in, Row* out, uint32_t colCount)
|
||||
out->setUintField(in.getUintField(i), i);
|
||||
else if (UNLIKELY(in.getColTypes()[i] == execplan::CalpontSystemCatalog::LONGDOUBLE))
|
||||
out->setLongDoubleField(in.getLongDoubleField(i), i);
|
||||
else if (UNLIKELY((in.getColType(i) == execplan::CalpontSystemCatalog::DECIMAL ||
|
||||
in.getColType(i) == execplan::CalpontSystemCatalog::UDECIMAL) &&
|
||||
in.getColumnWidth(i) == datatypes::MAXDECIMALWIDTH))
|
||||
in.copyBinaryField(*out, i, i);
|
||||
else
|
||||
out->setIntField(in.getIntField(i), i);
|
||||
}
|
||||
|
Reference in New Issue
Block a user