1
0
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:
Gagan Goel
2020-04-19 23:27:43 -04:00
committed by Roman Nozdrin
parent 554c6da8e8
commit cfe35b5c7f
28 changed files with 2102 additions and 462 deletions

View File

@ -119,18 +119,36 @@ int64_t Func_truncate::getIntVal(Row& row,
{
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
if (x.scale > 0)
if (!datatypes::Decimal::isWideDecimalType(op_ct))
{
while (x.scale-- > 0)
x.value /= 10;
if (x.scale > 0)
{
while (x.scale-- > 0)
x.value /= 10;
}
else
{
while (x.scale++ < 0)
x.value *= 10;
}
return x.value;
}
else
{
while (x.scale++ < 0)
x.value *= 10;
}
if (x.scale > 0)
{
while (x.scale-- > 0)
x.s128Value /= 10;
}
else
{
while (x.scale++ < 0)
x.s128Value *= 10;
}
return x.value;
return datatypes::Decimal::getInt64FromWideDecimal(x.s128Value);
}
}
@ -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,55 +332,116 @@ IDB_Decimal Func_truncate::getDecimalVal(Row& row,
case execplan::CalpontSystemCatalog::UDECIMAL:
{
int64_t d = 0;
//@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)
if (!datatypes::Decimal::isWideDecimalType(op_ct))
{
int64_t nvp = p;
d = parm[1]->data()->getIntVal(row, isNull);
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
volatile int64_t p = 1;
if (!isNull)
helpers::decimalPlaceDec(d, nvp, decimal.scale);
p = nvp;
}
if (isNull)
break;
int64_t x = decimal.value;
if (d > 0)
{
x = x * p;
}
else if (d < 0)
{
if ((x >= p) || (x <= -p))
{
if (p != 0)
x = x / p;
int64_t nvp = p;
d = parm[1]->data()->getIntVal(row, isNull);
if (!isNull)
helpers::decimalPlaceDec(d, nvp, decimal.scale);
p = nvp;
}
if (isNull)
break;
int64_t x = decimal.value;
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;
}
}
else
// negative scale is not supported by CNX yet, set d to 0.
if (decimal.scale < 0)
{
x = 0;
do
x *= 10;
while (++decimal.scale < 0);
}
}
// negative scale is not supported by CNX yet, set d to 0.
if (decimal.scale < 0)
decimal.value = x;
}
else
{
do
x *= 10;
//@Bug 3101 - GCC 4.5.1 optimizes too aggressively here. Mark as volatile.
volatile int128_t p = 1;
while (++decimal.scale < 0);
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;
}
decimal.value = x;
}
break;
@ -650,7 +739,14 @@ string Func_truncate::getStrVal(Row& row,
break;
}
return dataconvert::DataConvert::decimalToString(x.value, x.scale, op_ct.colDataType);
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);
}
}