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

fix(utils): MCOL-4605 handle negative decimals in FROM_UNIXTIME (#3466)

This commit is contained in:
Amr Elmohamady
2025-03-28 00:11:16 +02:00
committed by GitHub
parent 1fdeb740c9
commit 2d69b49ba0
3 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,9 @@ FROM_UNIXTIME(0)
SELECT FROM_UNIXTIME(-1) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(-1) FROM t1 LIMIT 1;
FROM_UNIXTIME(-1) FROM_UNIXTIME(-1)
NULL NULL
SELECT FROM_UNIXTIME(-0.1) FROM t1 LIMIT 1;
FROM_UNIXTIME(-0.1)
NULL
SELECT FROM_UNIXTIME(1) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(1) FROM t1 LIMIT 1;
FROM_UNIXTIME(1) FROM_UNIXTIME(1)
1970-01-01 00:00:01 1970-01-01 00:00:01

View File

@ -31,6 +31,7 @@ INSERT INTO t1 VALUES(9913, 98765.4321, repeat('q', 5), '09-12-11', '01:08:59');
SELECT FROM_UNIXTIME(0) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(0) FROM t1 LIMIT 1;
SELECT FROM_UNIXTIME(-1) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(-1) FROM t1 LIMIT 1;
SELECT FROM_UNIXTIME(-0.1) FROM t1 LIMIT 1;
SELECT FROM_UNIXTIME(1) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(1) FROM t1 LIMIT 1;
SELECT FROM_UNIXTIME(1547432997) FROM t1 LIMIT 1; SELECT FROM_UNIXTIME(1547432997) FROM t1 LIMIT 1;
SELECT FROM_UNIXTIME('1547432997') FROM t1 LIMIT 1; SELECT FROM_UNIXTIME('1547432997') FROM t1 LIMIT 1;

View File

@ -51,6 +51,12 @@ DateTime getDateTime(rowgroup::Row& row, FunctionParm& parm, bool& isNull)
case execplan::CalpontSystemCatalog::DOUBLE: case execplan::CalpontSystemCatalog::DOUBLE:
{ {
double value = parm[0]->data()->getDoubleVal(row, isNull); double value = parm[0]->data()->getDoubleVal(row, isNull);
if (value < 0)
{
isNull = true;
return 0;
}
double fracpart, intpart; double fracpart, intpart;
fracpart = modf(value, &intpart); fracpart = modf(value, &intpart);
val = (int64_t)intpart; val = (int64_t)intpart;
@ -62,6 +68,12 @@ DateTime getDateTime(rowgroup::Row& row, FunctionParm& parm, bool& isNull)
{ {
IDB_Decimal dec = parm[0]->data()->getDecimalVal(row, isNull); IDB_Decimal dec = parm[0]->data()->getDecimalVal(row, isNull);
if (dec.value < 0)
{
isNull = true;
return 0;
}
if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH) if (parm[0]->data()->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
auto integralAndFractional = dec.getIntegralAndFractional(); auto integralAndFractional = dec.getIntegralAndFractional();