diff --git a/dbcon/execplan/CMakeLists.txt b/dbcon/execplan/CMakeLists.txt index 6542a87c5..e13609f91 100755 --- a/dbcon/execplan/CMakeLists.txt +++ b/dbcon/execplan/CMakeLists.txt @@ -51,6 +51,6 @@ add_library(execplan SHARED ${execplan_LIB_SRCS}) add_dependencies(execplan loggingcpp) -target_link_libraries(execplan messageqcpp ${NETSNMP_LIBRARIES} ${MARIADB_STRING_LIBS} ${ENGINE_DT_LIB}) +target_link_libraries(execplan messageqcpp ${NETSNMP_LIBRARIES} ${MARIADB_STRING_LIBS} ${ENGINE_DT_LIB} pron) install(TARGETS execplan DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine) diff --git a/dbcon/execplan/calpontselectexecutionplan.cpp b/dbcon/execplan/calpontselectexecutionplan.cpp index 4354fd187..965a1f7ee 100644 --- a/dbcon/execplan/calpontselectexecutionplan.cpp +++ b/dbcon/execplan/calpontselectexecutionplan.cpp @@ -37,6 +37,8 @@ using namespace messageqcpp; #include "querystats.h" #include "querytele.h" +#include "utils/pron/pron.h" + using namespace querytele; namespace @@ -465,6 +467,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const b << (uint8_t)fIsDML; messageqcpp::ByteStream::octbyte timeZone = fTimeZone; b << timeZone; + b << fPron; } void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b) @@ -664,6 +667,8 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b) messageqcpp::ByteStream::octbyte timeZone; b >> timeZone; fTimeZone = timeZone; + b >> fPron; + utils::Pron::instance().pron(fPron); } bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t) const @@ -818,4 +823,9 @@ void CalpontSelectExecutionPlan::rmParms(const RMParmVec& parms) frmParms.assign(parms.begin(), parms.end()); } +void CalpontSelectExecutionPlan::pron(std::string&& pron) +{ + fPron = pron; +} + } // namespace execplan diff --git a/dbcon/execplan/calpontselectexecutionplan.h b/dbcon/execplan/calpontselectexecutionplan.h index 992e2b41f..940bb2a47 100644 --- a/dbcon/execplan/calpontselectexecutionplan.h +++ b/dbcon/execplan/calpontselectexecutionplan.h @@ -596,6 +596,8 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan return fOrderByThreads; } + void pron(std::string&& pron); + void selectSubList(const SelectList& selectSubList) { fSelectSubList = selectSubList; @@ -944,6 +946,7 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan bool fIsDML = false; long fTimeZone = 0; std::vector fDynamicParseTreeVec; + std::string fPron; }; /** diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 290c5f101..2c056f46b 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -8543,6 +8543,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i } } + // json dictionary for debug and testing options + csep->pron(get_pron(gwi.thd)); + // We don't currently support limit with correlated subquery if ((rc = processLimitAndOffset(select_lex, gwi, csep, unionSel, isUnion, isSelectHandlerTop))) { diff --git a/dbcon/mysql/ha_mcs_sysvars.cpp b/dbcon/mysql/ha_mcs_sysvars.cpp index d597e772e..698d87e3d 100644 --- a/dbcon/mysql/ha_mcs_sysvars.cpp +++ b/dbcon/mysql/ha_mcs_sysvars.cpp @@ -205,6 +205,7 @@ static MYSQL_THDVAR_STR(cmapi_version, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC, static MYSQL_THDVAR_STR(cmapi_key, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC, "CMAPI key", NULL, NULL, ""); +static MYSQL_THDVAR_STR(pron, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC, "Debug options json dictionary", NULL, NULL, ""); static MYSQL_THDVAR_ULONGLONG(cmapi_port, PLUGIN_VAR_NOCMDOPT, "CMAPI port", NULL, NULL, 8640, 100, 65356, 1); @@ -251,6 +252,7 @@ st_mysql_sys_var* mcs_system_variables[] = {MYSQL_SYSVAR(compression_type), MYSQL_SYSVAR(s3_key), MYSQL_SYSVAR(s3_secret), MYSQL_SYSVAR(s3_region), + MYSQL_SYSVAR(pron), NULL}; st_mysql_show_var mcs_status_variables[] = {{"columnstore_version", (char*)&cs_version, SHOW_CHAR}, @@ -596,6 +598,16 @@ void set_cmapi_key(THD* thd, char* value) THDVAR(thd, cmapi_key) = value; } +const char* get_pron(THD* thd) +{ + return (thd == NULL) ? "" : THDVAR(thd, pron); +} + +void set_pron(THD* thd, char* value) +{ + THDVAR(thd, pron) = value; +} + const char* get_s3_key(THD* thd) { return THDVAR(thd, s3_key); diff --git a/dbcon/mysql/ha_mcs_sysvars.h b/dbcon/mysql/ha_mcs_sysvars.h index 03abc67e2..c0976806f 100644 --- a/dbcon/mysql/ha_mcs_sysvars.h +++ b/dbcon/mysql/ha_mcs_sysvars.h @@ -170,3 +170,6 @@ void set_s3_secret(THD* thd, char* value); const char* get_s3_region(THD* thd); void set_s3_region(THD* thd, char* value); + +const char* get_pron(THD* thd); +void set_pron(THD* thd, char* value); diff --git a/mysql-test/columnstore/basic/r/pron.result b/mysql-test/columnstore/basic/r/pron.result new file mode 100644 index 000000000..ea4e8ddbd --- /dev/null +++ b/mysql-test/columnstore/basic/r/pron.result @@ -0,0 +1,36 @@ +DROP DATABASE IF EXISTS pron; +CREATE DATABASE pron; +USE pron; +CREATE TABLE t +( +a double +) ENGINE=Columnstore; +INSERT INTO t VALUES(1.5707963267948966); +SHOW variables like 'columnstore_pron'; +Variable_name Value +columnstore_pron +SELECT sin(a) from t; +sin(a) +1 +SET columnstore_pron='{"megasinus": "123"}'; +SHOW variables like 'columnstore_pron'; +Variable_name Value +columnstore_pron {"megasinus": "123"} +SELECT sin(a) from t; +sin(a) +123 +SET columnstore_pron='{"megasinus": "-200"}'; +SHOW variables like 'columnstore_pron'; +Variable_name Value +columnstore_pron {"megasinus": "-200"} +SELECT sin(a) from t; +sin(a) +-200 +SET columnstore_pron=''; +SHOW variables like 'columnstore_pron'; +Variable_name Value +columnstore_pron +SELECT sin(a) from t; +sin(a) +1 +DROP DATABASE pron; diff --git a/mysql-test/columnstore/basic/t/pron.test b/mysql-test/columnstore/basic/t/pron.test new file mode 100644 index 000000000..a2af190ba --- /dev/null +++ b/mysql-test/columnstore/basic/t/pron.test @@ -0,0 +1,36 @@ +# Here we test the usage of columnstore_pron dictionary +# Sine function has codepath checking the value of megasinus +# just for exmaple. Maybe deleted after another proper usages + +--source ../include/have_columnstore.inc + +--disable_warnings +DROP DATABASE IF EXISTS pron; +--enable_warnings + +CREATE DATABASE pron; +USE pron; + +CREATE TABLE t +( + a double +) ENGINE=Columnstore; + +INSERT INTO t VALUES(1.5707963267948966); + +SHOW variables like 'columnstore_pron'; +SELECT sin(a) from t; + +SET columnstore_pron='{"megasinus": "123"}'; +SHOW variables like 'columnstore_pron'; +SELECT sin(a) from t; + +SET columnstore_pron='{"megasinus": "-200"}'; +SHOW variables like 'columnstore_pron'; +SELECT sin(a) from t; + +SET columnstore_pron=''; +SHOW variables like 'columnstore_pron'; +SELECT sin(a) from t; + +DROP DATABASE pron; diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index b0bea845a..42d57b415 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -24,3 +24,4 @@ add_subdirectory(libmysql_client) add_subdirectory(regr) add_subdirectory(cloudio) add_subdirectory(libmarias3) +add_subdirectory(pron) diff --git a/utils/funcexp/CMakeLists.txt b/utils/funcexp/CMakeLists.txt index a708c34e4..3c94dea39 100644 --- a/utils/funcexp/CMakeLists.txt +++ b/utils/funcexp/CMakeLists.txt @@ -150,7 +150,7 @@ add_library(funcexp SHARED ${funcexp_LIB_SRCS}) add_dependencies(funcexp loggingcpp) -target_link_libraries(funcexp ${NETSNMP_LIBRARIES}) +target_link_libraries(funcexp ${NETSNMP_LIBRARIES} pron) install(TARGETS funcexp DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine) diff --git a/utils/funcexp/func_math.cpp b/utils/funcexp/func_math.cpp index 8992411cd..21214141f 100644 --- a/utils/funcexp/func_math.cpp +++ b/utils/funcexp/func_math.cpp @@ -25,6 +25,7 @@ #include #include #include + #define _USE_MATH_DEFINES // MSC: enable math defines #include #include @@ -45,6 +46,8 @@ using namespace logging; #include "funchelpers.h" +#include "utils/pron/pron.h" + // Just in case they're missing... #ifndef M_LN2 #define M_LN2 0.69314718055994530942 /* log_e 2 */ @@ -1330,6 +1333,20 @@ CalpontSystemCatalog::ColType Func_sin::operationType(FunctionParm& fp, double Func_sin::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&) { + auto& pron = utils::Pron::instance(); + if (pron.pron().count("megasinus") != 0) + { + try + { + double fakesin = std::stod(pron.pron().at("megasinus")); + return fakesin; + } + catch (std::exception&) + { + // do nothing + } + } + switch (parm[0]->data()->resultType().colDataType) { case execplan::CalpontSystemCatalog::BIGINT: diff --git a/utils/pron/CMakeLists.txt b/utils/pron/CMakeLists.txt new file mode 100644 index 000000000..85cd9190b --- /dev/null +++ b/utils/pron/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories( ${ENGINE_COMMON_INCLUDES} ) + +set(pron_LIB_SRCS pron.cpp) + +add_library(pron STATIC ${pron_LIB_SRCS}) + +target_link_libraries(pron messageqcpp loggingcpp) + +install(TARGETS pron DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine) diff --git a/utils/pron/pron.cpp b/utils/pron/pron.cpp new file mode 100644 index 000000000..e8ee9886b --- /dev/null +++ b/utils/pron/pron.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +#include "pron.h" + +namespace utils +{ + +void makeLog(logging::Message::Args& args) +{ + logging::Message msg(1); + msg.format(args); + logging::LoggingID logid(20, 0, 0); + logging::Logger logger(logid.fSubsysID); + logger.logMessage(logging::LOG_TYPE_DEBUG, msg, logid); +} + +void Pron::pron(std::string& pron) +{ + if (pron.empty()) + { + pron_.clear(); + return; + } + + try + { + nlohmann::json j = nlohmann::json::parse(pron); + pron_ = j.get(); + + logging::Message::Args args; + args.add("Pron settings were set: "); + args.add(pron); + makeLog(args); + } + catch (const std::exception& e) + { + logging::Message::Args args; + args.add("Pron parsing error: "); + args.add(e.what()); + makeLog(args); + } +} + +} // namespace utils \ No newline at end of file diff --git a/utils/pron/pron.h b/utils/pron/pron.h new file mode 100644 index 000000000..30257951b --- /dev/null +++ b/utils/pron/pron.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include + +namespace utils +{ + +class Pron +{ + private: + Pron() = default; + + public: + using StringMap = std::unordered_map; + + static Pron& instance() + { + static Pron pron; + return pron; + } + const StringMap& pron() + { + return pron_; + } + + void pron(std::string& pron); + + private: + StringMap pron_; +}; + +} // namespace utils \ No newline at end of file