From 25c20bae9bed0830d7309626bcf286a61e6422e9 Mon Sep 17 00:00:00 2001 From: Leonid Fedorov Date: Tue, 13 Aug 2024 13:54:45 +0000 Subject: [PATCH] MCOL-4696: get rid of boost::iequals --- dbcon/execplan/pseudocolumn.cpp | 25 +++++++++++++------------ dbcon/execplan/windowfunctioncolumn.cpp | 23 +++++++++++------------ dbcon/mysql/ha_mcs_client_udfs.cpp | 2 +- dbcon/mysql/ha_mcs_ddl.cpp | 20 +++++++++++++++----- dbcon/mysql/ha_mcs_impl_if.h | 2 +- tools/dbbuilder/dbbuilder.cpp | 2 +- utils/common/collation.h | 8 ++++++++ utils/configcpp/xmlparser.cpp | 19 ++++++++++--------- utils/dataconvert/dataconvert.cpp | 6 +++--- 9 files changed, 63 insertions(+), 44 deletions(-) diff --git a/dbcon/execplan/pseudocolumn.cpp b/dbcon/execplan/pseudocolumn.cpp index 9c06967e2..c361037f0 100644 --- a/dbcon/execplan/pseudocolumn.cpp +++ b/dbcon/execplan/pseudocolumn.cpp @@ -26,9 +26,10 @@ #include using namespace std; -#include #include "bytestream.h" +#include "collation.h" + using namespace messageqcpp; #include "objectreader.h" @@ -197,37 +198,37 @@ bool PseudoColumn::operator!=(const TreeNode* t) const uint32_t PseudoColumn::pseudoNameToType(string& name) { - if (boost::iequals(name, "idbpm")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbpm")) return PSEUDO_PM; - if (boost::iequals(name, "idbdbroot")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbdbroot")) return PSEUDO_DBROOT; - if (boost::iequals(name, "idbextentrelativerid")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbextentrelativerid")) return PSEUDO_EXTENTRELATIVERID; - if (boost::iequals(name, "idbsegment")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbsegment")) return PSEUDO_SEGMENT; - if (boost::iequals(name, "idbsegmentdir")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbsegmentdir")) return PSEUDO_SEGMENTDIR; - if (boost::iequals(name, "idbextentmin")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbextentmin")) return PSEUDO_EXTENTMIN; - if (boost::iequals(name, "idbextentmax")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbextentmax")) return PSEUDO_EXTENTMAX; - if (boost::iequals(name, "idbblockid")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbblockid")) return PSEUDO_BLOCKID; - if (boost::iequals(name, "idbextentid")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbextentid")) return PSEUDO_EXTENTID; - if (boost::iequals(name, "idbpartition")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idbpartition")) return PSEUDO_PARTITION; - if (boost::iequals(name, "idblocalpm")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(name, "idblocalpm")) return PSEUDO_LOCALPM; return PSEUDO_UNKNOWN; diff --git a/dbcon/execplan/windowfunctioncolumn.cpp b/dbcon/execplan/windowfunctioncolumn.cpp index d5ab9647f..47a3bdb3f 100644 --- a/dbcon/execplan/windowfunctioncolumn.cpp +++ b/dbcon/execplan/windowfunctioncolumn.cpp @@ -29,7 +29,6 @@ using namespace std; #include -#include using namespace boost; #include "bytestream.h" @@ -399,23 +398,23 @@ void WindowFunctionColumn::adjustResultType() { if ((fResultType.colDataType == CalpontSystemCatalog::DECIMAL || fResultType.colDataType == CalpontSystemCatalog::UDECIMAL) && - !boost::iequals(fFunctionName, "COUNT") && !boost::iequals(fFunctionName, "COUNT(*)") && - !boost::iequals(fFunctionName, "ROW_NUMBER") && !boost::iequals(fFunctionName, "RANK") && - !boost::iequals(fFunctionName, "PERCENT_RANK") && !boost::iequals(fFunctionName, "DENSE_RANK") && - !boost::iequals(fFunctionName, "CUME_DIST") && !boost::iequals(fFunctionName, "NTILE") && - !boost::iequals(fFunctionName, "PERCENTILE") && !fFunctionParms.empty() && + !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "COUNT") && !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "COUNT(*)") && + !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "ROW_NUMBER") && !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "RANK") && + !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "PERCENT_RANK") && !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "DENSE_RANK") && + !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "CUME_DIST") && !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "NTILE") && + !datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "PERCENTILE") && !fFunctionParms.empty() && fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DOUBLE) fResultType = fFunctionParms[0]->resultType(); - if ((boost::iequals(fFunctionName, "LEAD") || boost::iequals(fFunctionName, "LAG") || - boost::iequals(fFunctionName, "MIN") || boost::iequals(fFunctionName, "MAX") || - boost::iequals(fFunctionName, "FIRST_VALUE") || boost::iequals(fFunctionName, "LAST_VALUE") || - boost::iequals(fFunctionName, "NTH_VALUE")) && + if ((datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "LEAD") || datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "LAG") || + datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "MIN") || datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "MAX") || + datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "FIRST_VALUE") || datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "LAST_VALUE") || + datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "NTH_VALUE")) && !fFunctionParms.empty()) fResultType = fFunctionParms[0]->resultType(); - if (boost::iequals(fFunctionName, "SUM") || boost::iequals(fFunctionName, "AVG") || - boost::iequals(fFunctionName, "AVG_DISTINCT") || boost::iequals(fFunctionName, "PERCENTILE")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "SUM") || datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "AVG") || + datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "AVG_DISTINCT") || datatypes::ASCIIStringCaseInsensetiveEquals(fFunctionName, "PERCENTILE")) { if (fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DECIMAL || fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::UDECIMAL) diff --git a/dbcon/mysql/ha_mcs_client_udfs.cpp b/dbcon/mysql/ha_mcs_client_udfs.cpp index 99f56f1a5..a8cd7c02e 100644 --- a/dbcon/mysql/ha_mcs_client_udfs.cpp +++ b/dbcon/mysql/ha_mcs_client_udfs.cpp @@ -406,7 +406,7 @@ extern "C" localModule = boost::get<0>(st); PrimaryUMModuleName = config::Config::makeConfig()->getConfig("SystemConfig", "PrimaryUMModuleName"); - if (boost::iequals(localModule, PrimaryUMModuleName)) + if (datatypes::ASCIIStringCaseInsensetiveEquals(localModule, PrimaryUMModuleName)) rtn = 1; if (PrimaryUMModuleName == "unassigned") rtn = 1; diff --git a/dbcon/mysql/ha_mcs_ddl.cpp b/dbcon/mysql/ha_mcs_ddl.cpp index e577521f8..9695d21b2 100644 --- a/dbcon/mysql/ha_mcs_ddl.cpp +++ b/dbcon/mysql/ha_mcs_ddl.cpp @@ -37,7 +37,6 @@ using namespace std; #include -#include #include using namespace boost; @@ -1014,8 +1013,13 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl if (autoIncre) { // Check whether there is a column with autoincrement already - if ((isAnyAutoincreCol) && - !(boost::iequals(autoiColName, createTable->fTableDef->fColumns[i]->fName))) + bool isAutoIncrementColumn = + default_table_charset ? datatypes::CollationAwareComparator(default_table_charset)( + autoiColName, createTable->fTableDef->fColumns[i]->fName) + : datatypes::ASCIIStringCaseInsensetiveEquals( + autoiColName, createTable->fTableDef->fColumns[i]->fName); + + if (isAnyAutoincreCol && !isAutoIncrementColumn) { rc = 1; thd->get_stmt_da()->set_overwrite_status(true); @@ -1060,8 +1064,14 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl } } - if (!autoIncre && isAnyAutoincreCol && - (boost::iequals(autoiColName, createTable->fTableDef->fColumns[i]->fName))) + + bool isAutoIncrementColumn = + default_table_charset ? datatypes::CollationAwareComparator(default_table_charset)( + autoiColName, createTable->fTableDef->fColumns[i]->fName) + : datatypes::ASCIIStringCaseInsensetiveEquals( + autoiColName, createTable->fTableDef->fColumns[i]->fName); + + if (!autoIncre && isAnyAutoincreCol && isAutoIncrementColumn) { autoIncre = true; matchedCol = true; diff --git a/dbcon/mysql/ha_mcs_impl_if.h b/dbcon/mysql/ha_mcs_impl_if.h index 34fd0d790..010b056c7 100644 --- a/dbcon/mysql/ha_mcs_impl_if.h +++ b/dbcon/mysql/ha_mcs_impl_if.h @@ -331,7 +331,7 @@ struct cal_connection_info configVal = cf->getConfig("SystemConfig", "PrimaryUMModuleName"); std::string module = execplan::ClientRotator::getModule(); - if (boost::iequals(configVal, module)) + if (datatypes::ASCIIStringCaseInsensetiveEquals(configVal, module)) return false; return true; diff --git a/tools/dbbuilder/dbbuilder.cpp b/tools/dbbuilder/dbbuilder.cpp index 973443fac..33c3323e3 100644 --- a/tools/dbbuilder/dbbuilder.cpp +++ b/tools/dbbuilder/dbbuilder.cpp @@ -257,7 +257,7 @@ int main(int argc, char* argv[]) config::Config* sysConfig = config::Config::makeConfig(calpontConfigFile.c_str()); string tmp = sysConfig->getConfig("Installation", "DBRootStorageType"); - if (boost::iequals(tmp, "hdfs")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(tmp, "hdfs")) { // HDFS is configured if (!IDBPolicy::useHdfs()) // error install plugin diff --git a/utils/common/collation.h b/utils/common/collation.h index 954141ba5..111827a80 100644 --- a/utils/common/collation.h +++ b/utils/common/collation.h @@ -270,4 +270,12 @@ class CollationAwareComparator : public Charset } }; +inline bool ASCIIStringCaseInsensetiveEquals(const std::string& left, const std::string& right) +{ + auto asciiLower = [](char c) { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; }; + return left.size() == right.size() && + std::equal(left.begin(), left.end(), right.begin(), + [&asciiLower](char l, char r) { return asciiLower(l) == asciiLower(r); }); +} + } // end of namespace datatypes diff --git a/utils/configcpp/xmlparser.cpp b/utils/configcpp/xmlparser.cpp index e36b7c094..a12e5944f 100644 --- a/utils/configcpp/xmlparser.cpp +++ b/utils/configcpp/xmlparser.cpp @@ -22,11 +22,12 @@ #include "mcsconfig.h" #include -#include #include #include #include #include + +#include "collation.h" using namespace std; #include "xmlparser.h" @@ -47,7 +48,7 @@ const string XMLParser::getConfig(const xmlDocPtr doc, const string& section, co { string cur1name = (const char*)cur1->name; - if ((boost::iequals(cur1name, section))) + if ((datatypes::ASCIIStringCaseInsensetiveEquals(cur1name, section))) { xmlNodePtr cur2 = cur1->xmlChildrenNode; @@ -55,7 +56,7 @@ const string XMLParser::getConfig(const xmlDocPtr doc, const string& section, co { string cur2name = (const char*)cur2->name; - if ((boost::iequals(cur2name, name))) + if ((datatypes::ASCIIStringCaseInsensetiveEquals(cur2name, name))) { xmlNodePtr cur3 = cur2->xmlChildrenNode; @@ -92,7 +93,7 @@ void XMLParser::getConfig(const xmlDocPtr doc, const string& section, const stri { string cur1name = (const char*)cur1->name; - if ((boost::iequals(cur1name, section))) + if (datatypes::ASCIIStringCaseInsensetiveEquals(cur1name, section)) { xmlNodePtr cur2 = cur1->xmlChildrenNode; @@ -100,7 +101,7 @@ void XMLParser::getConfig(const xmlDocPtr doc, const string& section, const stri { string cur2name = (const char*)cur2->name; - if ((boost::iequals(cur2name, name))) + if (datatypes::ASCIIStringCaseInsensetiveEquals(cur2name, name)) { res.clear(); xmlNodePtr cur3 = cur2->xmlChildrenNode; @@ -134,7 +135,7 @@ void XMLParser::setConfig(xmlDocPtr doc, const string& section, const string& na { string cur1name = (const char*)cur1->name; - if (boost::iequals(cur1name, section)) + if (datatypes::ASCIIStringCaseInsensetiveEquals(cur1name, section)) { cur2 = cur1->xmlChildrenNode; @@ -142,7 +143,7 @@ void XMLParser::setConfig(xmlDocPtr doc, const string& section, const string& na { string cur2name = (const char*)cur2->name; - if (boost::iequals(cur2name, name)) + if (datatypes::ASCIIStringCaseInsensetiveEquals(cur2name, name)) { xmlNodePtr cur3 = cur2->xmlChildrenNode; @@ -201,7 +202,7 @@ void XMLParser::delConfig(xmlDocPtr doc, const string& section, const string& na { string cur1name = (const char*)cur1->name; - if ((boost::iequals(cur1name, section))) + if (datatypes::ASCIIStringCaseInsensetiveEquals(cur1name, section)) { xmlNodePtr cur2 = cur1->xmlChildrenNode; @@ -211,7 +212,7 @@ void XMLParser::delConfig(xmlDocPtr doc, const string& section, const string& na cur2 = cur2->next; string tmpname = (const char*)tmp->name; - if ((boost::iequals(tmpname, name))) + if (datatypes::ASCIIStringCaseInsensetiveEquals(tmpname, name)) { xmlUnlinkNode(tmp); xmlFreeNode(tmp); diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index 7206a1b0c..c93dcdee4 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -124,12 +124,12 @@ void number_int_value(const string& data, cscDataType typeCode, const datatypes: if (y != string::npos) throw QueryDataExcept("')' is not matched.", formatErr); - if (boost::iequals(valStr, "true")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(valStr, "true")) { intVal = 1; return; } - if (boost::iequals(valStr, "false")) + if (datatypes::ASCIIStringCaseInsensetiveEquals(valStr, "false")) { intVal = 0; return; @@ -2004,7 +2004,7 @@ int64_t DataConvert::convertArrowColumnTimestampUs(int64_t timeVal, int& status) int inMinute; int inSecond; int inMicrosecond; - + std::chrono::microseconds duration(timeVal); std::chrono::system_clock::time_point timePoint(duration);