From fc05a9c6c230fb30b14725e4ec1aae1c73e7388a Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 30 Apr 2018 08:08:42 +0100 Subject: [PATCH] MCOL-392 Fix greatest() and least() for time --- utils/funcexp/func_greatest.cpp | 12 ++++++++---- utils/funcexp/func_least.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/utils/funcexp/func_greatest.cpp b/utils/funcexp/func_greatest.cpp index 11650ddca..2d7dd15d6 100644 --- a/utils/funcexp/func_greatest.cpp +++ b/utils/funcexp/func_greatest.cpp @@ -212,16 +212,20 @@ int64_t Func_greatest::getTimeIntVal(rowgroup::Row& row, execplan::CalpontSystemCatalog::ColType& ct) { // Strip off unused day - int64_t str = fp[0]->data()->getTimeIntVal(row, isNull) << 12; + int64_t greatestStr = fp[0]->data()->getTimeIntVal(row, isNull); - int64_t greatestStr = str; + int64_t str = greatestStr << 12; for (uint32_t i = 1; i < fp.size(); i++) { - int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull) << 12; + int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull); + int64_t str2 = str1 << 12; - if ( greatestStr < str1 ) + if ( str < str1 ) + { greatestStr = str1; + str = str2; + } } return greatestStr; diff --git a/utils/funcexp/func_least.cpp b/utils/funcexp/func_least.cpp index 70a64f267..2f645af5f 100644 --- a/utils/funcexp/func_least.cpp +++ b/utils/funcexp/func_least.cpp @@ -188,16 +188,20 @@ int64_t Func_least::getTimeIntVal(rowgroup::Row& row, execplan::CalpontSystemCatalog::ColType& op_ct) { // Strip off unused day - int64_t str = fp[0]->data()->getTimeIntVal(row, isNull) << 12; + int64_t leastStr = fp[0]->data()->getTimeIntVal(row, isNull); - int64_t leastStr = str; + int64_t str = leastStr << 12; for (uint32_t i = 1; i < fp.size(); i++) { - int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull) << 12; + int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull); + int64_t str2 = str1 << 12; - if ( leastStr > str1 ) + if ( str > str1 ) + { leastStr = str1; + str = str2; + } } return leastStr;