From 96063759399b97a3c6d29cd44837ccc829ad3e8c Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 3 Oct 2016 22:27:30 +0100 Subject: [PATCH] MCOL-289 Fix MCOL(0) handling Now throws an error instead of returning NULL to align with MariaDB --- utils/funcexp/func_math.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/utils/funcexp/func_math.cpp b/utils/funcexp/func_math.cpp index a8e902677..9bf1a97f9 100644 --- a/utils/funcexp/func_math.cpp +++ b/utils/funcexp/func_math.cpp @@ -469,7 +469,7 @@ double Func_cot::getDoubleVal(Row& row, bool& isNull, CalpontSystemCatalog::ColType&) { - switch (parm[0]->data()->resultType().colDataType) + switch (parm[0]->data()->resultType().colDataType) { case execplan::CalpontSystemCatalog::BIGINT: case execplan::CalpontSystemCatalog::INT: @@ -492,6 +492,14 @@ double Func_cot::getDoubleVal(Row& row, { // null value is indicated by isNull double value = parm[0]->data()->getDoubleVal(row, isNull); + if (value == 0) + { + Message::Args args; + args.add("cot"); + args.add(value); + unsigned errcode = ERR_INCORRECT_VALUE; + throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); + } if (isNull) { isNull = true; @@ -505,6 +513,15 @@ double Func_cot::getDoubleVal(Row& row, case execplan::CalpontSystemCatalog::DATE: { int32_t value = parm[0]->data()->getDateIntVal(row, isNull); + if (value == 0) + { + Message::Args args; + args.add("cot"); + args.add(value); + unsigned errcode = ERR_INCORRECT_VALUE; + throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); + } + if (isNull) { isNull = true; @@ -518,6 +535,14 @@ double Func_cot::getDoubleVal(Row& row, case execplan::CalpontSystemCatalog::DATETIME: { int64_t value = parm[0]->data()->getDatetimeIntVal(row, isNull); + if (value == 0) + { + Message::Args args; + args.add("cot"); + args.add((uint64_t)value); + unsigned errcode = ERR_INCORRECT_VALUE; + throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); + } if (isNull) { isNull = true; @@ -530,7 +555,7 @@ double Func_cot::getDoubleVal(Row& row, default: { - std::ostringstream oss; + std::ostringstream oss; oss << "cot: datatype of " << execplan::colDataTypeToString(parm[0]->data()->resultType().colDataType); throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT); }