From ed5f51b5934b2545f31a150317d19b46cbf2b018 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 17 May 2017 10:35:50 +0100 Subject: [PATCH] MCOL-719 Add date/datetime to func_least/greatest Support was missing and int casting caused unexpected results --- utils/funcexp/func_greatest.cpp | 38 +++++++++++++++++++++++++++++++++ utils/funcexp/func_least.cpp | 38 +++++++++++++++++++++++++++++++++ utils/funcexp/functor_all.h | 20 +++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/utils/funcexp/func_greatest.cpp b/utils/funcexp/func_greatest.cpp index 6e680c529..753c2f03f 100644 --- a/utils/funcexp/func_greatest.cpp +++ b/utils/funcexp/func_greatest.cpp @@ -159,6 +159,44 @@ IDB_Decimal Func_greatest::getDecimalVal(Row& row, return greatestStr; } +int32_t Func_greatest::getDateIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& ct) +{ + int32_t str = fp[0]->data()->getDateIntVal(row, isNull); + + int32_t greatestStr = str; + for (uint32_t i = 1; i < fp.size(); i++) + { + int32_t str1 = fp[i]->data()->getDateIntVal(row, isNull); + + if ( greatestStr < str1 ) + greatestStr = str1; + } + + return greatestStr; +} + +int64_t Func_greatest::getDatetimeIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& ct) +{ + int64_t str = fp[0]->data()->getDatetimeIntVal(row, isNull); + + int64_t greatestStr = str; + for (uint32_t i = 1; i < fp.size(); i++) + { + int64_t str1 = fp[i]->data()->getDatetimeIntVal(row, isNull); + + if ( greatestStr < str1 ) + greatestStr = str1; + } + + return greatestStr; +} + } // namespace funcexp // vim:ts=4 sw=4: diff --git a/utils/funcexp/func_least.cpp b/utils/funcexp/func_least.cpp index 3ec8b703f..5eeb24c0c 100644 --- a/utils/funcexp/func_least.cpp +++ b/utils/funcexp/func_least.cpp @@ -137,6 +137,44 @@ IDB_Decimal Func_least::getDecimalVal(Row& row, return leastStr; } +int32_t Func_least::getDateIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct) +{ + int32_t str = fp[0]->data()->getDateIntVal(row, isNull); + + int32_t leastStr = str; + for (uint32_t i = 1; i < fp.size(); i++) + { + int32_t str1 = fp[i]->data()->getDateIntVal(row, isNull); + + if ( leastStr > str1 ) + leastStr = str1; + } + + return leastStr; +} + +int64_t Func_least::getDatetimeIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct) +{ + int64_t str = fp[0]->data()->getDatetimeIntVal(row, isNull); + + int64_t leastStr = str; + for (uint32_t i = 1; i < fp.size(); i++) + { + int64_t str1 = fp[i]->data()->getDatetimeIntVal(row, isNull); + + if ( leastStr > str1 ) + leastStr = str1; + } + + return leastStr; +} + } // namespace funcexp diff --git a/utils/funcexp/functor_all.h b/utils/funcexp/functor_all.h index 29969136e..db7b8a491 100644 --- a/utils/funcexp/functor_all.h +++ b/utils/funcexp/functor_all.h @@ -267,6 +267,16 @@ public: FunctionParm& fp, bool& isNull, execplan::CalpontSystemCatalog::ColType& op_ct); + + int32_t getDateIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct); + + int64_t getDatetimeIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct); }; @@ -299,6 +309,16 @@ public: FunctionParm& fp, bool& isNull, execplan::CalpontSystemCatalog::ColType& op_ct); + + int32_t getDateIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct); + + int64_t getDatetimeIntVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct); };