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-641 Add support for functions (Part 1).
This commit is contained in:
committed by
Roman Nozdrin
parent
554c6da8e8
commit
cfe35b5c7f
@ -62,41 +62,8 @@ int64_t Func_floor::getIntVal(Row& row,
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (op_ct.scale == 0)
|
||||
{
|
||||
ret = parm[0]->data()->getIntVal(row, isNull);
|
||||
break;
|
||||
}
|
||||
|
||||
IDB_Decimal decimal = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
ret = decimal.value;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (decimal.scale > 0)
|
||||
{
|
||||
|
||||
if (decimal.scale >= 19)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) decimal.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
int64_t tmp = ret;
|
||||
ret /= helpers::powerOf10_c[decimal.scale];
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret)
|
||||
ret -= 1;
|
||||
}
|
||||
ret = parm[0]->data()->getIntVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -338,6 +305,20 @@ double Func_floor::getDoubleVal(Row& row,
|
||||
if (!isNull)
|
||||
ret = floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (double) getIntVal(row, parm, isNull, op_ct);
|
||||
@ -371,6 +352,20 @@ long double Func_floor::getLongDoubleVal(Row& row,
|
||||
if (!isNull)
|
||||
ret = floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal tmp = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
ret = datatypes::Decimal::getLongDoubleFromWideDecimal(tmp.s128Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (long double) tmp.value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (long double) getIntVal(row, parm, isNull, op_ct);
|
||||
@ -416,6 +411,20 @@ string Func_floor::getStrVal(Row& row,
|
||||
|
||||
*d = '\0';
|
||||
}
|
||||
else if (op_ct.colDataType == CalpontSystemCatalog::DECIMAL ||
|
||||
op_ct.colDataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
IDB_Decimal d = getDecimalVal(row, parm, isNull, op_ct);
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(&d.s128Value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString(d.value, d.scale, tmp, 511, op_ct.colDataType);
|
||||
}
|
||||
}
|
||||
else if (isUnsigned(op_ct.colDataType))
|
||||
{
|
||||
#ifndef __LP64__
|
||||
@ -436,6 +445,165 @@ string Func_floor::getStrVal(Row& row,
|
||||
return string(tmp);
|
||||
}
|
||||
|
||||
IDB_Decimal Func_floor::getDecimalVal(Row& row,
|
||||
FunctionParm& parm,
|
||||
bool& isNull,
|
||||
CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
IDB_Decimal ret;
|
||||
|
||||
switch (op_ct.colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
{
|
||||
ret.value = parm[0]->data()->getIntVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
ret = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
break;
|
||||
|
||||
// negative scale is not supported by CNX yet
|
||||
if (ret.scale > 0)
|
||||
{
|
||||
if (ret.scale > datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType)
|
||||
<< " with scale " << (int) ret.scale << " is beyond supported scale";
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
if (op_ct.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
{
|
||||
int128_t tmp = ret.s128Value;
|
||||
int128_t scaleDivisor;
|
||||
datatypes::getScaleDivisor(scaleDivisor, ret.scale);
|
||||
ret.s128Value /= scaleDivisor;
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret.s128Value)
|
||||
ret.s128Value -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t tmp = ret.value;
|
||||
ret.value /= helpers::powerOf10_c[ret.scale];
|
||||
|
||||
// Largest integer value not greater than X.
|
||||
if (tmp < 0 && tmp < ret.value)
|
||||
ret.value -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
{
|
||||
ret.value = (int64_t)parm[0]->data()->getUintVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
ret.value = (int64_t) floor(parm[0]->data()->getDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
ret.value = (int64_t) floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
const string& str = parm[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = (int64_t) floor(strtod(str.c_str(), 0));
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
{
|
||||
string str = DataConvert::dateToString1(parm[0]->data()->getDateIntVal(row, isNull));
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
string str =
|
||||
DataConvert::datetimeToString1(parm[0]->data()->getDatetimeIntVal(row, isNull));
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::TIMESTAMP:
|
||||
{
|
||||
string str =
|
||||
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::TIME:
|
||||
{
|
||||
string str =
|
||||
DataConvert::timeToString1(parm[0]->data()->getTimeIntVal(row, isNull));
|
||||
|
||||
// strip off micro seconds
|
||||
str = str.substr(0, 14);
|
||||
|
||||
if (!isNull)
|
||||
ret.value = atoll(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "floor: datatype of " << execplan::colDataTypeToString(op_ct.colDataType);
|
||||
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
|
||||
}
|
||||
}
|
||||
|
||||
ret.scale = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
Reference in New Issue
Block a user