You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-1793, fix REGR_SLOPE calculations, change scale to DECIMAL_NOT_SPECIFIED (variable length) for most REGR_*** functions.
This commit is contained in:
@ -61,8 +61,8 @@ mcsv1_UDAF::ReturnCode corr::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(corr_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode covar_pop::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(covar_pop_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode covar_samp::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(covar_samp_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
@ -136,7 +136,7 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a
|
||||
{
|
||||
struct covar_samp_data* data = (struct covar_samp_data*)context->getUserData()->data;
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
if (N > 1)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
@ -145,6 +145,11 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a
|
||||
double covar_samp = (sumxy - ((sumx * sumy) / N)) / (N - 1);
|
||||
valOut = covar_samp;
|
||||
}
|
||||
else
|
||||
if (N == 1)
|
||||
{
|
||||
valOut = 0;
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ mcsv1_UDAF::ReturnCode regr_intercept::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_intercept_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
@ -145,13 +145,13 @@ mcsv1_UDAF::ReturnCode regr_intercept::evaluate(mcsv1Context* context, static_an
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumxy = data->sumxy;
|
||||
double slope = 0.0;
|
||||
double slope = 0;
|
||||
double variance = (N * sumx2) - (sumx * sumx);
|
||||
if (variance != 0)
|
||||
{
|
||||
slope = ((N * sumxy) - (sumx * sumy)) / variance;
|
||||
valOut = (sumy - (slope * sumx)) / N;
|
||||
}
|
||||
valOut = (sumy - (slope * sumx)) / N;
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ mcsv1_UDAF::ReturnCode regr_r2::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_r2_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -60,8 +60,8 @@ mcsv1_UDAF::ReturnCode regr_slope::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_slope_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
@ -141,14 +141,16 @@ mcsv1_UDAF::ReturnCode regr_slope::evaluate(mcsv1Context* context, static_any::a
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
{
|
||||
// COVAR_POP(y, x) / VAR_POP(x)
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumxy = data->sumxy;
|
||||
double variance = (N * sumx2) - (sumx * sumx);
|
||||
if (variance != 0)
|
||||
double covar_pop = N * sumxy - sumx * sumy;
|
||||
double var_pop = N * sumx2 - sumx * sumx;
|
||||
if (var_pop != 0)
|
||||
{
|
||||
double slope = ((N * sumxy) - (sumx * sumy)) / variance;
|
||||
double slope = covar_pop / var_pop;
|
||||
valOut = slope;
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ mcsv1_UDAF::ReturnCode regr_sxx::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_sxx_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode regr_sxy::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_sxy_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -58,8 +58,8 @@ mcsv1_UDAF::ReturnCode regr_syy::init(mcsv1Context* context,
|
||||
context->setUserDataSize(sizeof(regr_syy_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(colTypes[0].scale + 8);
|
||||
context->setPrecision(19);
|
||||
context->setScale(DECIMAL_NOT_SPECIFIED);
|
||||
context->setPrecision(0);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
|
@ -581,12 +581,13 @@ extern "C"
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumxy = data->sumxy;
|
||||
double slope = 0;
|
||||
double variance = (N * sumx2) - (sumx * sumx);
|
||||
if (variance)
|
||||
{
|
||||
double slope = ((N * sumxy) - (sumx * sumy)) / variance;
|
||||
return (sumy - (slope * sumx)) / N;
|
||||
slope = ((N * sumxy) - (sumx * sumy)) / variance;
|
||||
}
|
||||
return (sumy - (slope * sumx)) / N;
|
||||
}
|
||||
*is_null = 1;
|
||||
return 0;
|
||||
|
@ -1673,11 +1673,10 @@ void RowAggregation::updateEntry(const Row& rowIn)
|
||||
{
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[i];
|
||||
int64_t colIn = pFunctionCol->fInputColumnIndex;
|
||||
int64_t colOut = pFunctionCol->fOutputColumnIndex;
|
||||
int64_t colIn = fFunctionCols[i]->fInputColumnIndex;
|
||||
int64_t colOut = fFunctionCols[i]->fOutputColumnIndex;
|
||||
|
||||
switch (pFunctionCol->fAggFunction)
|
||||
switch (fFunctionCols[i]->fAggFunction)
|
||||
{
|
||||
case ROWAGG_COUNT_COL_NAME:
|
||||
|
||||
@ -1691,7 +1690,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_MIN:
|
||||
case ROWAGG_MAX:
|
||||
case ROWAGG_SUM:
|
||||
doMinMaxSum(rowIn, colIn, colOut, pFunctionCol->fAggFunction);
|
||||
doMinMaxSum(rowIn, colIn, colOut, fFunctionCols[i]->fAggFunction);
|
||||
break;
|
||||
|
||||
case ROWAGG_AVG:
|
||||
@ -1708,7 +1707,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_BIT_OR:
|
||||
case ROWAGG_BIT_XOR:
|
||||
{
|
||||
doBitOp(rowIn, colIn, colOut, pFunctionCol->fAggFunction);
|
||||
doBitOp(rowIn, colIn, colOut, fFunctionCols[i]->fAggFunction);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1731,7 +1730,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "RowAggregation: function (id = " <<
|
||||
(uint64_t) pFunctionCol->fAggFunction << ") is not supported.";
|
||||
(uint64_t) fFunctionCols[i]->fAggFunction << ") is not supported.";
|
||||
cerr << errmsg.str() << endl;
|
||||
throw logging::QueryDataExcept(errmsg.str(), logging::aggregateFuncErr);
|
||||
break;
|
||||
@ -2015,7 +2014,6 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
|
||||
for (uint32_t i = 0; i < paramCount; ++i)
|
||||
{
|
||||
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[funcColsIdx];
|
||||
mcsv1sdk::ColumnDatum& datum = valsIn[i];
|
||||
// Turn on NULL flags based on the data
|
||||
dataFlags[i] = 0;
|
||||
@ -2024,9 +2022,9 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
// to acces the constant value rather than a row value.
|
||||
cc = NULL;
|
||||
|
||||
if (pFunctionCol->fpConstCol)
|
||||
if (fFunctionCols[funcColsIdx]->fpConstCol)
|
||||
{
|
||||
cc = dynamic_cast<ConstantColumn*>(pFunctionCol->fpConstCol.get());
|
||||
cc = dynamic_cast<ConstantColumn*>(fFunctionCols[funcColsIdx]->fpConstCol.get());
|
||||
}
|
||||
|
||||
if ((cc && cc->type() == ConstantColumn::NULLDATA)
|
||||
@ -2243,9 +2241,8 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
&& fFunctionCols[funcColsIdx + 1]->fAggFunction == ROWAGG_MULTI_PARM)
|
||||
{
|
||||
++funcColsIdx;
|
||||
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[funcColsIdx];
|
||||
colIn = pFunctionCol->fInputColumnIndex;
|
||||
colOut = pFunctionCol->fOutputColumnIndex;
|
||||
colIn = fFunctionCols[funcColsIdx]->fInputColumnIndex;
|
||||
colOut = fFunctionCols[funcColsIdx]->fOutputColumnIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user