From d0e9cde78237ca290f54aaac27e25d8ebd0959b7 Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Mon, 10 Oct 2016 16:52:47 -0500 Subject: [PATCH] MCOL-98: Added error message for functions returning out of range values. --- utils/funcexp/func_div.cpp | 9 +++++++-- utils/funcexp/func_exp.cpp | 12 ++++++++++++ utils/funcexp/func_math.cpp | 6 +++--- utils/funcexp/func_pow.cpp | 14 ++++++++++++++ utils/loggingcpp/ErrorMessage.txt | 2 ++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/utils/funcexp/func_div.cpp b/utils/funcexp/func_div.cpp index d75942b6d..5d57b7db2 100644 --- a/utils/funcexp/func_div.cpp +++ b/utils/funcexp/func_div.cpp @@ -34,6 +34,11 @@ using namespace std; #include "rowgroup.h" using namespace execplan; +#include "errorcodes.h" +#include "idberrorinfo.h" +#include "errorids.h" +using namespace logging; + #include "dataconvert.h" namespace funcexp @@ -55,7 +60,7 @@ int64_t Func_div::getIntVal(rowgroup::Row& row, if (int_val2 == 0) { isNull = true; - return 0; + return NULL; } int64_t int_val1 = (int64_t)(val1 > 0 ? val1 + 0.5 : val1 - 0.5); // MCOL-176 If abs(int_val2) is small enough (like -1), then, this may cause overflow. @@ -78,7 +83,7 @@ uint64_t Func_div::getUintVal(rowgroup::Row& row, if (val2 == 0) { isNull = true; - return 0; + return NULL; } return val1 / val2; } diff --git a/utils/funcexp/func_exp.cpp b/utils/funcexp/func_exp.cpp index e36f4e63d..b4a851b22 100644 --- a/utils/funcexp/func_exp.cpp +++ b/utils/funcexp/func_exp.cpp @@ -33,6 +33,11 @@ using namespace execplan; #include "rowgroup.h" using namespace rowgroup; +#include "errorcodes.h" +#include "idberrorinfo.h" +#include "errorids.h" +using namespace logging; + namespace funcexp { @@ -58,7 +63,14 @@ double Func_exp::getDoubleVal(Row& row, if (errno == ERANGE) // display NULL for out range value { if (x > 0) + { isNull = true; + Message::Args args; + args.add("exp"); + args.add(x); + unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT; + throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); + } else ret = 0.0; } diff --git a/utils/funcexp/func_math.cpp b/utils/funcexp/func_math.cpp index 9bf1a97f9..fe84ba6e0 100644 --- a/utils/funcexp/func_math.cpp +++ b/utils/funcexp/func_math.cpp @@ -497,7 +497,7 @@ double Func_cot::getDoubleVal(Row& row, Message::Args args; args.add("cot"); args.add(value); - unsigned errcode = ERR_INCORRECT_VALUE; + unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT; throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); } if (isNull) @@ -518,7 +518,7 @@ double Func_cot::getDoubleVal(Row& row, Message::Args args; args.add("cot"); args.add(value); - unsigned errcode = ERR_INCORRECT_VALUE; + unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT; throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); } @@ -540,7 +540,7 @@ double Func_cot::getDoubleVal(Row& row, Message::Args args; args.add("cot"); args.add((uint64_t)value); - unsigned errcode = ERR_INCORRECT_VALUE; + unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT; throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); } if (isNull) diff --git a/utils/funcexp/func_pow.cpp b/utils/funcexp/func_pow.cpp index f9e98a037..d32814439 100644 --- a/utils/funcexp/func_pow.cpp +++ b/utils/funcexp/func_pow.cpp @@ -37,6 +37,11 @@ using namespace execplan; #include "rowgroup.h" using namespace rowgroup; +#include "errorcodes.h" +#include "idberrorinfo.h" +#include "errorids.h" +using namespace logging; + namespace funcexp { @@ -65,7 +70,16 @@ double Func_pow::getDoubleVal(Row& row, // @bug3490, 4461, rule out domain error, pole error and overflow range error. if (!isfinite(x)) + { isNull = true; + Message::Args args; + args.add("pow"); + args.add(base); + args.add(exponent); + unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT; + throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode); + } + return x; } diff --git a/utils/loggingcpp/ErrorMessage.txt b/utils/loggingcpp/ErrorMessage.txt index afe0c1cde..1266a21e4 100644 --- a/utils/loggingcpp/ErrorMessage.txt +++ b/utils/loggingcpp/ErrorMessage.txt @@ -95,6 +95,8 @@ 2051 ERR_DBJ_DATA_DISTRIBUTION The data distribution in this query overflowed a disk-based join bucket. If possible, raise infinidb_diskjoin_bucketsize and try again. 2052 INFO_SWITCHING_TO_DJS Out of UM memory, switching to disk-based join. +2053 ERR_FUNC_OUT_OF_RANGE_RESULT The result is out of range for function %1% using value(s): %2% %3% + # Sub-query errors 3001 ERR_NON_SUPPORT_SUB_QUERY_TYPE This subquery type is not supported yet. 3002 ERR_MORE_THAN_1_ROW Subquery returns more than 1 row.