[MCOL-4629] Add a helper method mcsv1_UDAF::toDouble() Created: 2021-03-22  Updated: 2021-03-23  Resolved: 2021-03-23

Status: Closed
Project: MariaDB ColumnStore
Component/s: ExeMgr, PrimProc
Affects Version/s: 6.1.1
Fix Version/s: 6.1.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Gagan Goel (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MCOL-4361 Replace pow(10.0, (double)scale) expr... Closed
Sprint: 2021-5

 Description   

This task is a prerequisite for MCOL-4361 and is intended to make the patch MCOL-4361 much smaller.

This code in corr::nextValue() in utils/regr/corr.cpp:

    static_any::any& valIn_y = valsIn[0].columnData;
    static_any::any& valIn_x = valsIn[1].columnData;
    struct  corr_data* data = (struct corr_data*)context->getUserData()->data;
    double valx = 0.0;
    double valy = 0.0;
 
    valx = convertAnyTo<double>(valIn_x);
    valy = convertAnyTo<double>(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);
    }
    ...
    // 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);
    }

repeats a fair amount of time at least in this files:

  • utils/regr/corr.cpp
  • utils/regr/covar_pop.cpp
  • utils/regr/covar_samp.cpp
  • utils/regr/regr_avgx.cpp
  • utils/regr/regr_avgy.cpp
  • utils/regr/regr_intercept.cpp
  • utils/regr/regr_r2.cpp
  • utils/regr/regr_slope.cpp
  • utils/regr/regr_sxx.cpp
  • utils/regr/regr_sxy.cpp
  • utils/regr/regr_syy.cpp
  • utils/udfsdk/avg_mode.cpp
  • utils/udfsdk/avgx.cpp
  • utils/udfsdk/mcsv1_udaf.h
  • utils/udfsdk/ssq.cpp

Let's implement a method mcsv1_UDAF::toDouble() with approximately this content:

    double toDouble(ColumnDatum &datum) const
    {
        double val = convertAnyTo<double>(datum.columnData);
        if (val != 0 && datum.scale > 0)
            val /= pow(10.0, (double) scale);
        return val;
    }

and reuse it in the mentioned files, so the code in corr.cpp and other similar files can be replaced just to these two lines:

    double valy = toDouble(valsIn[0]);
    double valx = toDouble(valsIn[1]);

Later, during MCOL-4361 work, the pow() call will be replaced to a dictionary lookup.


Generated at Thu Feb 08 02:51:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.