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-5708 Calculate precision and scale for constant decimal. (#3227)
This patch calculates precision and scale for constant decimal value for SUM aggregation function.
This commit is contained in:
@ -58,6 +58,41 @@ int128_t SystemCatalog::TypeAttributesStd::decimal128FromString(const std::strin
|
||||
return result;
|
||||
}
|
||||
|
||||
// SQL parser checks that given `value` is in a valid format.
|
||||
// The first symbol can be `-`. The `value` can contain `.` symbol.
|
||||
void decimalPrecisionAndScale(const utils::NullString& value, int& precision, int& scale)
|
||||
{
|
||||
if (value.isNull())
|
||||
{
|
||||
scale = 0;
|
||||
precision = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto strValue = value.unsafeStringRef();
|
||||
if (strValue.empty())
|
||||
{
|
||||
scale = 0;
|
||||
precision = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
const int len = strValue.size();
|
||||
const auto dotIndex = strValue.find('.');
|
||||
const int minExists = strValue.front() == '-' ? 1 : 0;
|
||||
|
||||
if (dotIndex == std::string::npos)
|
||||
{
|
||||
scale = 0;
|
||||
precision = len - minExists;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = len - dotIndex - 1;
|
||||
precision = len - 1 - minExists;
|
||||
}
|
||||
}
|
||||
|
||||
int128_t SystemCatalog::TypeAttributesStd::decimal128FromString(const utils::NullString& value,
|
||||
bool* saturate) const
|
||||
{
|
||||
|
@ -125,6 +125,8 @@ struct WidthToSIntegralType<16> : _WidthToSIntegralType<16, int128_t>
|
||||
{
|
||||
};
|
||||
|
||||
void decimalPrecisionAndScale(const utils::NullString& value, int& precision, int& scale);
|
||||
|
||||
class SystemCatalog
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user