diff --git a/utils/regr/corr.cpp b/utils/regr/corr.cpp index a49baf1c7..5740bd8fe 100644 --- a/utils/regr/corr.cpp +++ b/utils/regr/corr.cpp @@ -89,34 +89,13 @@ mcsv1_UDAF::ReturnCode corr::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode corr::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct corr_data* data = (struct corr_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; data->sumy2 += valy*valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumx2 += valx*valx; @@ -182,35 +161,13 @@ mcsv1_UDAF::ReturnCode corr::evaluate(mcsv1Context* context, static_any::any& va mcsv1_UDAF::ReturnCode corr::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct corr_data* data = (struct corr_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; data->sumy2 -= valy*valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumx2 -= valx*valx; diff --git a/utils/regr/covar_pop.cpp b/utils/regr/covar_pop.cpp index 0f0ab8c96..0a3bb923d 100644 --- a/utils/regr/covar_pop.cpp +++ b/utils/regr/covar_pop.cpp @@ -85,33 +85,11 @@ mcsv1_UDAF::ReturnCode covar_pop::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode covar_pop::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct covar_pop_data* data = (struct covar_pop_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumxy += valx*valy; @@ -157,34 +135,11 @@ mcsv1_UDAF::ReturnCode covar_pop::evaluate(mcsv1Context* context, static_any::an mcsv1_UDAF::ReturnCode covar_pop::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct covar_pop_data* data = (struct covar_pop_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumxy -= valx*valy; diff --git a/utils/regr/covar_samp.cpp b/utils/regr/covar_samp.cpp index 98fa99fe9..8966f8db9 100644 --- a/utils/regr/covar_samp.cpp +++ b/utils/regr/covar_samp.cpp @@ -85,33 +85,12 @@ mcsv1_UDAF::ReturnCode covar_samp::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode covar_samp::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct covar_samp_data* data = (struct covar_samp_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumxy += valx*valy; @@ -162,34 +141,12 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a mcsv1_UDAF::ReturnCode covar_samp::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct covar_samp_data* data = (struct covar_samp_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumxy -= valx*valy; diff --git a/utils/regr/regr_avgx.cpp b/utils/regr/regr_avgx.cpp index bec098116..39448efbe 100644 --- a/utils/regr/regr_avgx.cpp +++ b/utils/regr/regr_avgx.cpp @@ -84,16 +84,8 @@ mcsv1_UDAF::ReturnCode regr_avgx::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_avgx::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_x = valsIn[1].columnData; + DATATYPE val = toDouble(valsIn[1]); struct regr_avgx_data* data = (struct regr_avgx_data*)context->getUserData()->data; - DATATYPE val = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsIn[1].scale; - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } data->sum += val; ++data->cnt; @@ -133,16 +125,8 @@ mcsv1_UDAF::ReturnCode regr_avgx::evaluate(mcsv1Context* context, static_any::an mcsv1_UDAF::ReturnCode regr_avgx::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_x = valsDropped[1].columnData; + double val = toDouble(valsDropped[1]); struct regr_avgx_data* data = (struct regr_avgx_data*)context->getUserData()->data; - double val = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsDropped[1].scale; - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } data->sum -= val; --data->cnt; diff --git a/utils/regr/regr_avgy.cpp b/utils/regr/regr_avgy.cpp index 512e3e48d..ddfb1c914 100644 --- a/utils/regr/regr_avgy.cpp +++ b/utils/regr/regr_avgy.cpp @@ -84,16 +84,8 @@ mcsv1_UDAF::ReturnCode regr_avgy::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_avgy::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; + double val = toDouble(valsIn[0]); struct regr_avgy_data* data = (struct regr_avgy_data*)context->getUserData()->data; - double val = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsIn[0].scale; - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } data->sum += val; ++data->cnt; @@ -130,16 +122,8 @@ mcsv1_UDAF::ReturnCode regr_avgy::evaluate(mcsv1Context* context, static_any::an mcsv1_UDAF::ReturnCode regr_avgy::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; + double val = toDouble(valsDropped[0]); struct regr_avgy_data* data = (struct regr_avgy_data*)context->getUserData()->data; - double val = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsDropped[0].scale; - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } data->sum -= val; --data->cnt; diff --git a/utils/regr/regr_intercept.cpp b/utils/regr/regr_intercept.cpp index e649fa55c..f27522d63 100644 --- a/utils/regr/regr_intercept.cpp +++ b/utils/regr/regr_intercept.cpp @@ -87,33 +87,11 @@ mcsv1_UDAF::ReturnCode regr_intercept::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_intercept::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct regr_intercept_data* data = (struct regr_intercept_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumx2 += valx*valx; @@ -166,34 +144,11 @@ mcsv1_UDAF::ReturnCode regr_intercept::evaluate(mcsv1Context* context, static_an mcsv1_UDAF::ReturnCode regr_intercept::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct regr_intercept_data* data = (struct regr_intercept_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumx2 -= valx*valx; diff --git a/utils/regr/regr_r2.cpp b/utils/regr/regr_r2.cpp index b69d9abe0..31b1ba2fb 100644 --- a/utils/regr/regr_r2.cpp +++ b/utils/regr/regr_r2.cpp @@ -89,34 +89,13 @@ mcsv1_UDAF::ReturnCode regr_r2::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_r2::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct regr_r2_data* data = (struct regr_r2_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; data->sumy2 += valy*valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumx2 += valx*valx; @@ -183,35 +162,13 @@ mcsv1_UDAF::ReturnCode regr_r2::evaluate(mcsv1Context* context, static_any::any& mcsv1_UDAF::ReturnCode regr_r2::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct regr_r2_data* data = (struct regr_r2_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; data->sumy2 -= valy*valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumx2 -= valx*valx; diff --git a/utils/regr/regr_slope.cpp b/utils/regr/regr_slope.cpp index b6aeedbd5..df85e484d 100644 --- a/utils/regr/regr_slope.cpp +++ b/utils/regr/regr_slope.cpp @@ -86,36 +86,13 @@ mcsv1_UDAF::ReturnCode regr_slope::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_slope::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct regr_slope_data* data = (struct regr_slope_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumx2 += valx*valx; - data->sumxy += valx*valy; ++data->cnt; @@ -167,37 +144,13 @@ mcsv1_UDAF::ReturnCode regr_slope::evaluate(mcsv1Context* context, static_any::a mcsv1_UDAF::ReturnCode regr_slope::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct regr_slope_data* data = (struct regr_slope_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumx2 -= valx*valx; - data->sumxy -= valx*valy; --data->cnt; diff --git a/utils/regr/regr_sxx.cpp b/utils/regr/regr_sxx.cpp index 07569abd5..6141c87d7 100644 --- a/utils/regr/regr_sxx.cpp +++ b/utils/regr/regr_sxx.cpp @@ -83,19 +83,8 @@ mcsv1_UDAF::ReturnCode regr_sxx::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_sxx::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_x = valsIn[1].columnData; + double valx = toDouble(valsIn[1]); struct regr_sxx_data* data = (struct regr_sxx_data*)context->getUserData()->data; - double valx = 0.0; - - valx = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } data->sumx += valx; data->sumx2 += valx*valx; @@ -138,21 +127,9 @@ mcsv1_UDAF::ReturnCode regr_sxx::evaluate(mcsv1Context* context, static_any::any mcsv1_UDAF::ReturnCode regr_sxx::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_x = valsDropped[1].columnData; + double valx = toDouble(valsDropped[1]); struct regr_sxx_data* data = (struct regr_sxx_data*)context->getUserData()->data; - double valx = 0.0; - - valx = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumx2 -= valx*valx; diff --git a/utils/regr/regr_sxy.cpp b/utils/regr/regr_sxy.cpp index cad3e69eb..b78e98f08 100644 --- a/utils/regr/regr_sxy.cpp +++ b/utils/regr/regr_sxy.cpp @@ -85,33 +85,12 @@ mcsv1_UDAF::ReturnCode regr_sxy::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_sxy::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; - static_any::any& valIn_x = valsIn[1].columnData; + double valy = toDouble(valsIn[0]); + double valx = toDouble(valsIn[1]); struct regr_sxy_data* data = (struct regr_sxy_data*)context->getUserData()->data; - long double valx = 0.0; - long double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsIn[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx += valx; data->sumxy += valx*valy; @@ -153,34 +132,12 @@ mcsv1_UDAF::ReturnCode regr_sxy::evaluate(mcsv1Context* context, static_any::any mcsv1_UDAF::ReturnCode regr_sxy::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; - static_any::any& valIn_x = valsDropped[1].columnData; + double valy = toDouble(valsDropped[0]); + double valx = toDouble(valsDropped[1]); struct regr_sxy_data* data = (struct regr_sxy_data*)context->getUserData()->data; - double valx = 0.0; - double valy = 0.0; - - valx = convertAnyTo(valIn_x); - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; - // For decimal types, we need to move the decimal point. - uint32_t scalex = valsDropped[1].scale; - - if (valx != 0 && scalex > 0) - { - valx /= pow(10.0, (double)scalex); - } - data->sumx -= valx; data->sumxy -= valx*valy; diff --git a/utils/regr/regr_syy.cpp b/utils/regr/regr_syy.cpp index 3c9116b74..ab94b866e 100644 --- a/utils/regr/regr_syy.cpp +++ b/utils/regr/regr_syy.cpp @@ -83,19 +83,8 @@ mcsv1_UDAF::ReturnCode regr_syy::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode regr_syy::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_y = valsIn[0].columnData; + double valy = toDouble(valsIn[0]); struct regr_syy_data* data = (struct regr_syy_data*)context->getUserData()->data; - double valy = 0.0; - - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsIn[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } data->sumy += valy; data->sumy2 += valy*valy; @@ -138,21 +127,9 @@ mcsv1_UDAF::ReturnCode regr_syy::evaluate(mcsv1Context* context, static_any::any mcsv1_UDAF::ReturnCode regr_syy::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_y = valsDropped[0].columnData; + double valy = toDouble(valsDropped[0]); struct regr_syy_data* data = (struct regr_syy_data*)context->getUserData()->data; - double valy = 0.0; - - valy = convertAnyTo(valIn_y); - - // For decimal types, we need to move the decimal point. - uint32_t scaley = valsDropped[0].scale; - - if (valy != 0 && scaley > 0) - { - valy /= pow(10.0, (double)scaley); - } - data->sumy -= valy; data->sumy2 -= valy*valy; diff --git a/utils/udfsdk/avg_mode.cpp b/utils/udfsdk/avg_mode.cpp index 87b2d6b2e..5c0ebfbc7 100644 --- a/utils/udfsdk/avg_mode.cpp +++ b/utils/udfsdk/avg_mode.cpp @@ -67,23 +67,14 @@ mcsv1_UDAF::ReturnCode avg_mode::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode avg_mode::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn = valsIn[0].columnData; MODE_DATA& data = static_cast(context->getUserData())->mData; - if (valIn.empty()) + if (valsIn[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on. } - DATATYPE val = convertAnyTo(valIn); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsIn[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsIn[0]); data[val]++; @@ -136,23 +127,14 @@ mcsv1_UDAF::ReturnCode avg_mode::evaluate(mcsv1Context* context, static_any::any mcsv1_UDAF::ReturnCode avg_mode::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn = valsDropped[0].columnData; MODE_DATA& data = static_cast(context->getUserData())->mData; - if (valIn.empty()) + if (valsDropped[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on. } - DATATYPE val = convertAnyTo(valIn); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsDropped[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsDropped[0]); data[val]--; diff --git a/utils/udfsdk/avgx.cpp b/utils/udfsdk/avgx.cpp index b0c666541..f57b98691 100644 --- a/utils/udfsdk/avgx.cpp +++ b/utils/udfsdk/avgx.cpp @@ -73,23 +73,14 @@ mcsv1_UDAF::ReturnCode avgx::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode avgx::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn_x = valsIn[0].columnData; struct avgx_data* data = (struct avgx_data*)context->getUserData()->data; - if (valIn_x.empty()) + if (valsIn[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on. } - DATATYPE val = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsIn[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsIn[0]); data->sum += val; ++data->cnt; @@ -125,23 +116,14 @@ mcsv1_UDAF::ReturnCode avgx::evaluate(mcsv1Context* context, static_any::any& va mcsv1_UDAF::ReturnCode avgx::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn_x = valsDropped[0].columnData; struct avgx_data* data = (struct avgx_data*)context->getUserData()->data; - if (valIn_x.empty()) + if (valsDropped[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on. } - DATATYPE val = convertAnyTo(valIn_x); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsDropped[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsDropped[0]); data->sum -= val; --data->cnt; diff --git a/utils/udfsdk/mcsv1_udaf.h b/utils/udfsdk/mcsv1_udaf.h index ff37457ef..794cad8a5 100755 --- a/utils/udfsdk/mcsv1_udaf.h +++ b/utils/udfsdk/mcsv1_udaf.h @@ -628,9 +628,18 @@ public: virtual ReturnCode createUserData(UserData*& userdata, int32_t& length); protected: + + double toDouble(ColumnDatum &datum) const + { + double val = convertAnyTo(datum.columnData); + if (val != 0 && datum.scale > 0) + val /= pow(10.0, (double) datum.scale); + return val; + } + // some handy conversion routines template - T convertAnyTo(static_any::any&); + T convertAnyTo(static_any::any&) const; // These are handy for testing the actual type of static_any static const static_any::any& charTypeId; static const static_any::any& scharTypeId; @@ -1015,7 +1024,7 @@ inline mcsv1_UDAF::ReturnCode mcsv1_UDAF::createUserData(UserData*& userData, in // Handy helper functions template -inline T mcsv1_UDAF::convertAnyTo(static_any::any& valIn) +inline T mcsv1_UDAF::convertAnyTo(static_any::any& valIn) const { T val = 0; if (valIn.compatible(longTypeId)) diff --git a/utils/udfsdk/ssq.cpp b/utils/udfsdk/ssq.cpp index 9b4c411aa..ecd96ff78 100644 --- a/utils/udfsdk/ssq.cpp +++ b/utils/udfsdk/ssq.cpp @@ -83,23 +83,14 @@ mcsv1_UDAF::ReturnCode ssq::reset(mcsv1Context* context) mcsv1_UDAF::ReturnCode ssq::nextValue(mcsv1Context* context, ColumnDatum* valsIn) { - static_any::any& valIn = valsIn[0].columnData; struct ssq_data* data = (struct ssq_data*)context->getUserData()->data; - if (context->isParamNull(0) || valIn.empty()) + if (context->isParamNull(0) || valsIn[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; } - DATATYPE val = convertAnyTo(valIn); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsIn[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsIn[0]); data->sumsq += val * val; return mcsv1_UDAF::SUCCESS; @@ -132,23 +123,14 @@ mcsv1_UDAF::ReturnCode ssq::evaluate(mcsv1Context* context, static_any::any& val mcsv1_UDAF::ReturnCode ssq::dropValue(mcsv1Context* context, ColumnDatum* valsDropped) { - static_any::any& valIn = valsDropped[0].columnData; struct ssq_data* data = (struct ssq_data*)context->getUserData()->data; - if (valIn.empty()) + if (valsDropped[0].columnData.empty()) { return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on. } - DATATYPE val = convertAnyTo(valIn); - - // For decimal types, we need to move the decimal point. - uint32_t scale = valsDropped[0].scale; - - if (val != 0 && scale > 0) - { - val /= pow(10.0, (double)scale); - } + DATATYPE val = toDouble(valsDropped[0]); data->sumsq -= val * val; return mcsv1_UDAF::SUCCESS;