From 5815c5c526a02216c5adc0f5c90379a76e5f8c17 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Tue, 22 Dec 2020 15:43:51 +0000 Subject: [PATCH 1/3] MCOL-4452 RowAggregationUMP2::doUDAF() now calls setUserData() using a correct UDAF context --- utils/rowgroup/rowaggregation.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/rowgroup/rowaggregation.cpp b/utils/rowgroup/rowaggregation.cpp index f8e3cde03..48b2e434f 100755 --- a/utils/rowgroup/rowaggregation.cpp +++ b/utils/rowgroup/rowaggregation.cpp @@ -4627,13 +4627,14 @@ void RowAggregationUMP2::doUDAF(const Row& rowIn, // Call the UDAF subEvaluate method mcsv1sdk::mcsv1_UDAF::ReturnCode rc; rc = udafContextsColl[funcColsIdx].getFunction()->subEvaluate(&udafContextsColl[funcColsIdx], userDataIn.get()); - fRGContext.setUserData(NULL); + udafContextsColl[funcColsIdx].setUserData(NULL); if (rc == mcsv1sdk::mcsv1_UDAF::ERROR) { RowUDAFFunctionCol* rowUDAF = dynamic_cast(fFunctionCols[funcColsIdx].get()); rowUDAF->bInterrupted = true; - throw logging::IDBExcept(fRGContext.getErrorMessage(), logging::aggregateFuncErr); + throw logging::IDBExcept(udafContextsColl[funcColsIdx].getErrorMessage(), + logging::aggregateFuncErr); } } From 2c36eedb2bf406220d311e7f12b60b0e8d3fff0d Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Tue, 22 Dec 2020 15:53:06 +0000 Subject: [PATCH 2/3] MCOL-4466 regr_count() and distinct_count() now use long long for counters and for a type cast to/from boost::any --- utils/regr/regr_count.cpp | 2 +- utils/udfsdk/distinct_count.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/regr/regr_count.cpp b/utils/regr/regr_count.cpp index 7d893e16f..eeb5e09a2 100644 --- a/utils/regr/regr_count.cpp +++ b/utils/regr/regr_count.cpp @@ -38,7 +38,7 @@ static Add_regr_count_ToUDAFMap addToMap; // Use the simple data model struct regr_count_data { - uint64_t cnt; + long long cnt; }; diff --git a/utils/udfsdk/distinct_count.cpp b/utils/udfsdk/distinct_count.cpp index e622bf324..b0a7c15bc 100644 --- a/utils/udfsdk/distinct_count.cpp +++ b/utils/udfsdk/distinct_count.cpp @@ -22,7 +22,7 @@ using namespace mcsv1sdk; struct distinct_count_data { - uint64_t cnt; + long long cnt; }; #define OUT_TYPE int64_t @@ -34,7 +34,7 @@ mcsv1_UDAF::ReturnCode distinct_count::init(mcsv1Context* context, { // The error message will be prepended with // "The storage engine for the table doesn't support " - context->setErrorMessage("avgx() with other than 1 arguments"); + context->setErrorMessage("distinct_count() with other than 1 arguments"); return mcsv1_UDAF::ERROR; } context->setResultType(execplan::CalpontSystemCatalog::BIGINT); From 994d9a512551af6602c589f9c0a6a5d99353ff42 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Tue, 22 Dec 2020 18:20:18 +0000 Subject: [PATCH 3/3] MCOL-4465 Use a proper ColType for UDAF in a projection RowGroup --- dbcon/mysql/ha_mcs_execplan.cpp | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 0e52ebb65..fe69776be 100755 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -463,6 +463,20 @@ bool isDuplicateSF(gp_walk_info *gwip, execplan::SimpleFilter *sfp) return false; } +// DESCRIPTION: +// This f() checks if the arguments is a UDF Item +// PARAMETERS: +// Item * Item to traverse +// RETURN: +// bool +inline bool isUDFSumItem(const Item_sum* isp) +{ + return typeid(*isp) == typeid(Item_sum_udf_int) || + typeid(*isp) == typeid(Item_sum_udf_float) || + typeid(*isp) == typeid(Item_sum_udf_decimal) || + typeid(*isp) == typeid(Item_sum_udf_str); +} + string getViewName(TABLE_LIST* table_ptr) { string viewName = ""; @@ -4979,10 +4993,28 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) ct.precision = 0; ac->resultType(ct); } + // Setting the ColType in the resulting RowGroup + // according with what MDB expects. + // Internal processing UDAF result type will be set below. + else if (isUDFSumItem(isp)) + { + ac->resultType(colType_MysqlToIDB(isp)); + } + // Using the first param to deduce ac data type + else if (ac->aggParms().size() == 1) + { + ac->resultType(parm->resultType()); + } else { - // UDAF result type will be set below. - ac->resultType(parm->resultType()); + gwi.fatalParseError = true; + gwi.parseErrorText = "Can not deduce Aggregate Column resulting type \ +because it has multiple arguments."; + + if (ac) + delete ac; + + return nullptr; } } else if (bIsConst && hasDecimalConst && isAvg)