1
0
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:
Denis Khalikov
2024-06-27 23:31:03 +03:00
committed by GitHub
parent 88e3af4ba5
commit 9f4231f87f
5 changed files with 90 additions and 2 deletions

View File

@ -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
{

View File

@ -125,6 +125,8 @@ struct WidthToSIntegralType<16> : _WidthToSIntegralType<16, int128_t>
{
};
void decimalPrecisionAndScale(const utils::NullString& value, int& precision, int& scale);
class SystemCatalog
{
public: