diff --git a/mysql-test/columnstore/basic/r/mcs171_null_functions.result b/mysql-test/columnstore/basic/r/mcs171_null_functions.result index 51f2276a4..4c07c0c6b 100644 --- a/mysql-test/columnstore/basic/r/mcs171_null_functions.result +++ b/mysql-test/columnstore/basic/r/mcs171_null_functions.result @@ -97,7 +97,7 @@ c NULL d d SELECT b, NULLIF(b, 15) FROM t1; b NULLIF(b, 15) -NULL -2147483648 +NULL NULL 12 12 13 13 14 14 diff --git a/mysql-test/columnstore/bugfixes/mcol-5992.result b/mysql-test/columnstore/bugfixes/mcol-5992.result new file mode 100644 index 000000000..a061f5f2b --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5992.result @@ -0,0 +1,9 @@ +DROP DATABASE IF EXISTS mcol5992; +CREATE DATABASE mcol5992; +USE mcol5992; +CREATE TABLE `CS_LEG` (`ID` bigint(20) DEFAULT NULL, `sess_count` smallint(6) DEFAULT NULL) ENGINE=Columnstore; +insert into CS_LEG(ID) values(1); +select NULLIF(sess_count,0) from CS_LEG; +NULLIF(sess_count,0) +NULL +DROP DATABASE mcol5992; diff --git a/mysql-test/columnstore/bugfixes/mcol-5992.test b/mysql-test/columnstore/bugfixes/mcol-5992.test new file mode 100644 index 000000000..b67370776 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5992.test @@ -0,0 +1,16 @@ +# MCOL-5992: NULLIF() returns NULL when NULL is the first argument +--source ../include/have_columnstore.inc + +--disable_warnings +DROP DATABASE IF EXISTS mcol5992; +--enable_warnings + +CREATE DATABASE mcol5992; +USE mcol5992; + +CREATE TABLE `CS_LEG` (`ID` bigint(20) DEFAULT NULL, `sess_count` smallint(6) DEFAULT NULL) ENGINE=Columnstore; + +insert into CS_LEG(ID) values(1); +select NULLIF(sess_count,0) from CS_LEG; + +DROP DATABASE mcol5992; diff --git a/utils/funcexp/func_nullif.cpp b/utils/funcexp/func_nullif.cpp index ba8b83559..0097c09f2 100644 --- a/utils/funcexp/func_nullif.cpp +++ b/utils/funcexp/func_nullif.cpp @@ -56,8 +56,15 @@ int64_t Func_nullif::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isN execplan::CalpontSystemCatalog::ColType& op_ct) { int64_t exp1 = parm[0]->data()->getIntVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + + int64_t exp2 = 0; + switch (parm[1]->data()->resultType().colDataType) { case execplan::CalpontSystemCatalog::BIGINT: @@ -236,6 +243,11 @@ uint64_t Func_nullif::getUintVal(rowgroup::Row& row, FunctionParm& parm, bool& i execplan::CalpontSystemCatalog::ColType& op_ct) { uint64_t exp1 = parm[0]->data()->getUintVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + uint64_t exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -349,6 +361,11 @@ string Func_nullif::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu CalpontSystemCatalog::ColType& op_ct) { string exp1 = parm[0]->data()->getStrVal(row, isNull).safeString(""); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + CHARSET_INFO* cs = parm[0]->data()->resultType().getCharset(); if (isNull) @@ -395,6 +412,11 @@ int32_t Func_nullif::getDateIntVal(rowgroup::Row& row, FunctionParm& parm, bool& CalpontSystemCatalog::ColType& ct) { int64_t exp1 = parm[0]->data()->getDateIntVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + int64_t exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -482,6 +504,11 @@ int64_t Func_nullif::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& parm, b CalpontSystemCatalog::ColType& ct) { int64_t exp1 = parm[0]->data()->getDatetimeIntVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + int64_t exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -547,6 +574,11 @@ int64_t Func_nullif::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm, bool& CalpontSystemCatalog::ColType& ct) { int64_t exp1 = parm[0]->data()->getTimeIntVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + int64_t exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -598,6 +630,11 @@ int64_t Func_nullif::getTimestampIntVal(rowgroup::Row& row, FunctionParm& parm, CalpontSystemCatalog::ColType& ct) { int64_t exp1 = parm[0]->data()->getTimestampIntVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + int64_t exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -649,6 +686,11 @@ double Func_nullif::getDoubleVal(rowgroup::Row& row, FunctionParm& parm, bool& i execplan::CalpontSystemCatalog::ColType& op_ct) { double exp1 = parm[0]->data()->getDoubleVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + double exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -737,6 +779,11 @@ long double Func_nullif::getLongDoubleVal(rowgroup::Row& row, FunctionParm& parm execplan::CalpontSystemCatalog::ColType& op_ct) { long double exp1 = parm[0]->data()->getLongDoubleVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + long double exp2 = 0; switch (parm[1]->data()->resultType().colDataType) @@ -838,6 +885,11 @@ execplan::IDB_Decimal Func_nullif::getDecimalVal(rowgroup::Row& row, FunctionPar execplan::CalpontSystemCatalog::ColType& op_ct) { IDB_Decimal exp1 = parm[0]->data()->getDecimalVal(row, isNull); + + // NULL equals anything is NULL, so we return NULL as a value of parm[0] + if (isNull) + return exp1; + IDB_Decimal exp2; switch (parm[1]->data()->resultType().colDataType)