You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-5708 Calculate precision and scale for constant decimal.
This patch calculates precision and scale for constant decimal value for SUM aggregation function.
This commit is contained in:
@ -66,6 +66,41 @@ int128_t TypeAttributesStd::decimal128FromString(const utils::NullString& value,
|
||||
return decimal128FromString(value.unsafeStringRef(), saturate);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
const string& TypeHandlerSInt8::name() const
|
||||
{
|
||||
static const string xname = "TINYINT";
|
||||
|
@ -125,6 +125,8 @@ struct WidthToSIntegralType<16> : _WidthToSIntegralType<16, int128_t>
|
||||
{
|
||||
};
|
||||
|
||||
void decimalPrecisionAndScale(const utils::NullString& value, int &precision, int &scale);
|
||||
|
||||
// XXX: It is assumed here that ALL TYPES have width, scale and precision.
|
||||
// XXX: And then some of them have the type tag itself.
|
||||
// XXX: But, all types have type tag, some need explicit width (decimals, for example)
|
||||
|
Reference in New Issue
Block a user