1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

MCOL-2057 Fix truncate(x,d) when d < 0 for unsigned int data types

For unsigned data types in the int family (tinyint, smallint, int, bigint),
truncate(x, d) now properly applies zeros when d < 0.
This commit is contained in:
Gagan Goel
2019-01-08 20:15:04 -05:00
parent a6a7970e28
commit 6deb5e1bfd

View File

@ -136,7 +136,34 @@ uint64_t Func_truncate::getUintVal(Row& row,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
return parm[0]->data()->getUintVal(row, isNull);
uint64_t val = parm[0]->data()->getUintVal(row, isNull);
if (isNull)
return val;
int64_t d = parm[1]->data()->getIntVal(row, isNull);
if (isNull || d >= 0)
return val;
uint64_t p = 1;
int64_t i = (-d);
// Handle overflow since p can't have more than 19 0's
if (i >= 20)
{
val = 0;
}
else
{
while (i--)
p *= 10;
val /= p;
val *= p;
}
return val;
}