From 9bec66c36fbcca26307e7d983374e7ea8efa3fac Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 23 Apr 2020 09:54:33 -0500 Subject: [PATCH] MCOL-3959 1.5 make from_unixtimestamp msec aware When using the function with decimal or float types, the fractional portion is the msec. --- utils/funcexp/func_from_unixtime.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/utils/funcexp/func_from_unixtime.cpp b/utils/funcexp/func_from_unixtime.cpp index 8f5f3d051..fc649344c 100644 --- a/utils/funcexp/func_from_unixtime.cpp +++ b/utils/funcexp/func_from_unixtime.cpp @@ -45,7 +45,8 @@ DateTime getDateTime(rowgroup::Row& row, FunctionParm& parm, bool& isNull) { - int64_t val; + int64_t val = 0; + uint32_t msec = 0; switch (parm[0]->data()->resultType().colDataType) { @@ -54,13 +55,10 @@ DateTime getDateTime(rowgroup::Row& row, case execplan::CalpontSystemCatalog::DECIMAL: { double value = parm[0]->data()->getDoubleVal(row, isNull); - - if (value > 0) - value += 0.5; - else if (value < 0) - value -= 0.5; - - val = (int64_t)value; + double fracpart, intpart; + fracpart = modf(value, &intpart); + val = (int64_t)intpart; + msec = (uint32_t)(fracpart * IDB_pow[parm[0]->data()->resultType().scale]); break; } @@ -84,7 +82,7 @@ DateTime getDateTime(rowgroup::Row& row, dt.hour = (int64_t) tmp_tm.tm_hour; dt.minute = (int64_t) tmp_tm.tm_min; dt.second = (int64_t) tmp_tm.tm_sec; - dt.msecond = 0; + dt.msecond = msec; return dt; } }