From 7ca4e8403aa690fd4c05e3c4da27352d609ed77c Mon Sep 17 00:00:00 2001 From: Gagan Goel Date: Fri, 20 Mar 2020 21:54:31 +0000 Subject: [PATCH] MCOL-3756 Implement IS(NOT)TRUE() and IS(NOT)FALSE() functions. --- utils/funcexp/funcexp.cpp | 4 ++ utils/funcexp/functor_bool.h | 83 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/utils/funcexp/funcexp.cpp b/utils/funcexp/funcexp.cpp index f96f85b45..5f15ec991 100644 --- a/utils/funcexp/funcexp.cpp +++ b/utils/funcexp/funcexp.cpp @@ -141,6 +141,10 @@ FuncExp::FuncExp() fFuncMap["instr"] = new Func_instr(); fFuncMap["isnull"] = new Func_isnull(false); fFuncMap["isnotnull"] = new Func_isnull(true); + fFuncMap["istrue"] = new Func_IsTrue(); + fFuncMap["isnottrue"] = new Func_IsNotTrue(); + fFuncMap["isfalse"] = new Func_IsFalse(); + fFuncMap["isnotfalse"] = new Func_IsNotFalse(); fFuncMap["last_day"] = new Func_last_day(); fFuncMap["lcase"] = new Func_lcase(); //dlh fFuncMap["least"] = new Func_least(); //dlh diff --git a/utils/funcexp/functor_bool.h b/utils/funcexp/functor_bool.h index 28077e878..7467f57d4 100644 --- a/utils/funcexp/functor_bool.h +++ b/utils/funcexp/functor_bool.h @@ -1,4 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. + Copyright (C) 2020 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -241,6 +242,88 @@ private: }; +/** @brief Func_Truth class + */ +class Func_Truth : public Func_Bool +{ +public: + Func_Truth(const std::string& funcName, bool a_value, bool a_affirmative) : + Func_Bool(funcName), value(a_value), affirmative(a_affirmative) {} + + virtual ~Func_Truth() {} + + execplan::CalpontSystemCatalog::ColType operationType(FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType) + { + assert (fp.size() == 1); + return fp[0]->data()->resultType(); + } + + bool getBoolVal(rowgroup::Row& row, + FunctionParm& fp, + bool& isNull, + execplan::CalpontSystemCatalog::ColType& op_ct) + { + bool val = fp[0]->data()->getBoolVal(row, isNull); + + /* + NULL val IS {TRUE, FALSE} --> FALSE + NULL val IS NOT {TRUE, FALSE} --> TRUE + {TRUE, FALSE} val IS {TRUE, FALSE} value --> val == value + {TRUE, FALSE} val IS NOT {TRUE, FALSE} value --> val != value + These cases can be reduced to the following bitwise operation. + */ + bool ret = (isNull & (!affirmative)) | ((!isNull) & (affirmative ^ (value ^ val))); + + isNull = false; + + return ret; + } + +private: + const bool value, affirmative; +}; + + +/** @brief Func_IsTrue class + */ +class Func_IsTrue : public Func_Truth +{ +public: + Func_IsTrue() : Func_Truth("istrue", true, true) {} + ~Func_IsTrue() {} +}; + + +/** @brief Func_IsNotTrue class + */ +class Func_IsNotTrue : public Func_Truth +{ +public: + Func_IsNotTrue() : Func_Truth("isnottrue", true, false) {} + ~Func_IsNotTrue() {} +}; + + +/** @brief Func_IsFalse class + */ +class Func_IsFalse : public Func_Truth +{ +public: + Func_IsFalse() : Func_Truth("isfalse", false, true) {} + ~Func_IsFalse() {} +}; + + +/** @brief Func_IsNotFalse class + */ +class Func_IsNotFalse : public Func_Truth +{ +public: + Func_IsNotFalse() : Func_Truth("isnotfalse", false, false) {} + ~Func_IsNotFalse() {} +}; + + } #endif