You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
Merge pull request #652 from mariadb-corporation/MCOL-1983
MCOL-1983 Have regr_intercept, regr_slope and regr_r2 return NULL for…
This commit is contained in:
@ -39,11 +39,11 @@ static Add_corr_ToUDAFMap addToMap;
|
||||
struct corr_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumx2; // sum of (x squared)
|
||||
double sumy;
|
||||
double sumy2; // sum of (y squared)
|
||||
double sumxy; // sum of x * y
|
||||
long double sumx;
|
||||
long double sumx2; // sum of (x squared)
|
||||
long double sumy;
|
||||
long double sumy2; // sum of (y squared)
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -57,6 +57,13 @@ mcsv1_UDAF::ReturnCode corr::init(mcsv1Context* context,
|
||||
context->setErrorMessage("corr() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("corr() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(corr_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -146,29 +153,29 @@ mcsv1_UDAF::ReturnCode corr::evaluate(mcsv1Context* context, static_any::any& va
|
||||
double N = data->cnt;
|
||||
if (N > 1)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumy2 = data->sumy2;
|
||||
double sumxy = data->sumxy;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumx2 = data->sumx2;
|
||||
long double sumy2 = data->sumy2;
|
||||
long double sumxy = data->sumxy;
|
||||
|
||||
double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
long double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
if (var_popx == 0)
|
||||
{
|
||||
// When var_popx is 0, NULL is the result.
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
double var_popy = (sumy2 - (sumy * sumy / N)) / N;
|
||||
long double var_popy = (sumy2 - (sumy * sumy / N)) / N;
|
||||
if (var_popy == 0)
|
||||
{
|
||||
// When var_popy is 0, NULL is the result
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
double std_popx = sqrt(var_popx);
|
||||
double std_popy = sqrt(var_popy);
|
||||
double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
double corr = covar_pop / (std_popy * std_popx);
|
||||
valOut = corr;
|
||||
long double std_popx = sqrt(var_popx);
|
||||
long double std_popy = sqrt(var_popy);
|
||||
long double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
long double corr = covar_pop / (std_popy * std_popx);
|
||||
valOut = static_cast<double>(corr);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ static Add_covar_pop_ToUDAFMap addToMap;
|
||||
struct covar_pop_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumy;
|
||||
double sumxy; // sum of x * y
|
||||
long double sumx;
|
||||
long double sumy;
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -55,6 +55,13 @@ mcsv1_UDAF::ReturnCode covar_pop::init(mcsv1Context* context,
|
||||
context->setErrorMessage("covar_pop() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("covar_pop() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(covar_pop_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -138,12 +145,12 @@ mcsv1_UDAF::ReturnCode covar_pop::evaluate(mcsv1Context* context, static_any::an
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumxy = data->sumxy;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumxy = data->sumxy;
|
||||
|
||||
double covar_pop = (sumxy - ((sumx * sumy) / N)) / N ;
|
||||
valOut = covar_pop;
|
||||
long double covar_pop = (sumxy - ((sumx * sumy) / N)) / N ;
|
||||
valOut = static_cast<double>(covar_pop);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ static Add_covar_samp_ToUDAFMap addToMap;
|
||||
struct covar_samp_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumy;
|
||||
double sumxy; // sum of x * y
|
||||
long double sumx;
|
||||
long double sumy;
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -55,6 +55,13 @@ mcsv1_UDAF::ReturnCode covar_samp::init(mcsv1Context* context,
|
||||
context->setErrorMessage("covar_samp() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("covar_samp() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(covar_samp_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -138,12 +145,12 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a
|
||||
double N = data->cnt;
|
||||
if (N > 1)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumxy = data->sumxy;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumxy = data->sumxy;
|
||||
|
||||
double covar_samp = (sumxy - ((sumx * sumy) / N)) / (N - 1);
|
||||
valOut = covar_samp;
|
||||
long double covar_samp = (sumxy - ((sumx * sumy) / N)) / (N - 1);
|
||||
valOut = static_cast<double>(covar_samp);
|
||||
}
|
||||
else
|
||||
if (N == 1)
|
||||
|
@ -40,7 +40,7 @@ static Add_regr_avgx_ToUDAFMap addToMap;
|
||||
// Use the simple data model
|
||||
struct regr_avgx_data
|
||||
{
|
||||
double sum;
|
||||
long double sum;
|
||||
uint64_t cnt;
|
||||
};
|
||||
|
||||
@ -63,6 +63,13 @@ mcsv1_UDAF::ReturnCode regr_avgx::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_avgx() with a non-numeric x argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_avgx() with a non-numeric independant (second) argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_avgx_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -125,7 +132,7 @@ mcsv1_UDAF::ReturnCode regr_avgx::evaluate(mcsv1Context* context, static_any::an
|
||||
|
||||
if (data->cnt > 0)
|
||||
{
|
||||
valOut = data->sum / (double)data->cnt;
|
||||
valOut = static_cast<double>(data->sum / (long double)data->cnt);
|
||||
}
|
||||
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
@ -40,7 +40,7 @@ static Add_regr_avgy_ToUDAFMap addToMap;
|
||||
// Use the simple data model
|
||||
struct regr_avgy_data
|
||||
{
|
||||
double sum;
|
||||
long double sum;
|
||||
uint64_t cnt;
|
||||
};
|
||||
|
||||
@ -63,6 +63,13 @@ mcsv1_UDAF::ReturnCode regr_avgy::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_avgy() with a non-numeric x argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_avgy() with a non-numeric dependant (first) argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_avgy_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -123,7 +130,7 @@ mcsv1_UDAF::ReturnCode regr_avgy::evaluate(mcsv1Context* context, static_any::an
|
||||
|
||||
if (data->cnt > 0)
|
||||
{
|
||||
valOut = data->sum / (double)data->cnt;
|
||||
valOut = static_cast<double>(data->sum / (long double)data->cnt);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ static Add_regr_intercept_ToUDAFMap addToMap;
|
||||
struct regr_intercept_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumx2; // sum of (x squared)
|
||||
double sumy;
|
||||
double sumxy; // sum of (x*y)
|
||||
long double sumx;
|
||||
long double sumx2; // sum of (x squared)
|
||||
long double sumy;
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -56,6 +56,13 @@ mcsv1_UDAF::ReturnCode regr_intercept::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_intercept() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_intercept() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_intercept_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -139,17 +146,17 @@ mcsv1_UDAF::ReturnCode regr_intercept::evaluate(mcsv1Context* context, static_an
|
||||
{
|
||||
struct regr_intercept_data* data = (struct regr_intercept_data*)context->getUserData()->data;
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
if (N > 1)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumxy = data->sumxy;
|
||||
double numerator = sumy * sumx2 - sumx * sumxy;
|
||||
double var_pop = (N * sumx2) - (sumx * sumx);
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumx2 = data->sumx2;
|
||||
long double sumxy = data->sumxy;
|
||||
long double numerator = sumy * sumx2 - sumx * sumxy;
|
||||
long double var_pop = (N * sumx2) - (sumx * sumx);
|
||||
if (var_pop != 0)
|
||||
{
|
||||
valOut = numerator / var_pop;
|
||||
valOut = static_cast<double>(numerator / var_pop);
|
||||
}
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
@ -39,11 +39,11 @@ static Add_regr_r2_ToUDAFMap addToMap;
|
||||
struct regr_r2_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumx2; // sum of (x squared)
|
||||
double sumy;
|
||||
double sumy2; // sum of (y squared)
|
||||
double sumxy; // sum of x * y
|
||||
long double sumx;
|
||||
long double sumx2; // sum of (x squared)
|
||||
long double sumy;
|
||||
long double sumy2; // sum of (y squared)
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -57,6 +57,13 @@ mcsv1_UDAF::ReturnCode regr_r2::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_r2() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_r2() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_r2_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -144,15 +151,15 @@ mcsv1_UDAF::ReturnCode regr_r2::evaluate(mcsv1Context* context, static_any::any&
|
||||
{
|
||||
struct regr_r2_data* data = (struct regr_r2_data*)context->getUserData()->data;
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
if (N > 1)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumy2 = data->sumy2;
|
||||
double sumxy = data->sumxy;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumx2 = data->sumx2;
|
||||
long double sumy2 = data->sumy2;
|
||||
long double sumxy = data->sumxy;
|
||||
|
||||
double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
long double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
if (var_popx == 0)
|
||||
{
|
||||
// When var_popx is 0, NULL is the result.
|
||||
@ -165,11 +172,11 @@ mcsv1_UDAF::ReturnCode regr_r2::evaluate(mcsv1Context* context, static_any::any&
|
||||
valOut = 1.0;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
double std_popx = sqrt(var_popx);
|
||||
double std_popy = sqrt(var_popy);
|
||||
double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
double corr = covar_pop / (std_popy * std_popx);
|
||||
valOut = corr * corr;
|
||||
long double std_popx = sqrt(var_popx);
|
||||
long double std_popy = sqrt(var_popy);
|
||||
long double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
long double corr = covar_pop / (std_popy * std_popx);
|
||||
valOut = static_cast<double>(corr * corr);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ static Add_regr_slope_ToUDAFMap addToMap;
|
||||
struct regr_slope_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumx2; // sum of (x squared)
|
||||
double sumy;
|
||||
double sumxy; // sum of (x*y)
|
||||
long double sumx;
|
||||
long double sumx2; // sum of (x squared)
|
||||
long double sumy;
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -56,7 +56,13 @@ mcsv1_UDAF::ReturnCode regr_slope::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_slope() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_slope() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
context->setUserDataSize(sizeof(regr_slope_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
@ -139,19 +145,19 @@ mcsv1_UDAF::ReturnCode regr_slope::evaluate(mcsv1Context* context, static_any::a
|
||||
{
|
||||
struct regr_slope_data* data = (struct regr_slope_data*)context->getUserData()->data;
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
if (N > 1)
|
||||
{
|
||||
// COVAR_POP(y, x) / VAR_POP(x)
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumx2 = data->sumx2;
|
||||
double sumxy = data->sumxy;
|
||||
double covar_pop = N * sumxy - sumx * sumy;
|
||||
double var_pop = N * sumx2 - sumx * sumx;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumx2 = data->sumx2;
|
||||
long double sumxy = data->sumxy;
|
||||
long double covar_pop = N * sumxy - sumx * sumy;
|
||||
long double var_pop = N * sumx2 - sumx * sumx;
|
||||
if (var_pop != 0)
|
||||
{
|
||||
double slope = covar_pop / var_pop;
|
||||
valOut = slope;
|
||||
long double slope = covar_pop / var_pop;
|
||||
valOut = static_cast<double>(slope);
|
||||
}
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
@ -39,8 +39,8 @@ static Add_regr_sxx_ToUDAFMap addToMap;
|
||||
struct regr_sxx_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumx2; // sum of (x squared)
|
||||
long double sumx;
|
||||
long double sumx2; // sum of (x squared)
|
||||
};
|
||||
|
||||
|
||||
@ -54,6 +54,13 @@ mcsv1_UDAF::ReturnCode regr_sxx::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_sxx() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_sxx() with a non-numeric independant (second) argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_sxx_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -121,11 +128,11 @@ mcsv1_UDAF::ReturnCode regr_sxx::evaluate(mcsv1Context* context, static_any::any
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumx2 = data->sumx2;
|
||||
long double sumx = data->sumx;
|
||||
long double sumx2 = data->sumx2;
|
||||
|
||||
double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
valOut = data->cnt * var_popx;
|
||||
long double var_popx = (sumx2 - (sumx * sumx / N)) / N;
|
||||
valOut = static_cast<double>(data->cnt * var_popx);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ static Add_regr_sxy_ToUDAFMap addToMap;
|
||||
struct regr_sxy_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumx;
|
||||
double sumy;
|
||||
double sumxy; // sum of x * y
|
||||
long double sumx;
|
||||
long double sumy;
|
||||
long double sumxy; // sum of x * y
|
||||
};
|
||||
|
||||
|
||||
@ -55,6 +55,13 @@ mcsv1_UDAF::ReturnCode regr_sxy::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_sxy() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType) && isNumeric(colTypes[1].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_sxy() with non-numeric arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_sxy_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -81,8 +88,8 @@ mcsv1_UDAF::ReturnCode regr_sxy::nextValue(mcsv1Context* context, ColumnDatum* v
|
||||
static_any::any& valIn_y = valsIn[0].columnData;
|
||||
static_any::any& valIn_x = valsIn[1].columnData;
|
||||
struct regr_sxy_data* data = (struct regr_sxy_data*)context->getUserData()->data;
|
||||
double valx = 0.0;
|
||||
double valy = 0.0;
|
||||
long double valx = 0.0;
|
||||
long double valy = 0.0;
|
||||
|
||||
valx = convertAnyTo<double>(valIn_x);
|
||||
valy = convertAnyTo<double>(valIn_y);
|
||||
@ -138,13 +145,13 @@ mcsv1_UDAF::ReturnCode regr_sxy::evaluate(mcsv1Context* context, static_any::any
|
||||
double N = data->cnt;
|
||||
if (N > 0)
|
||||
{
|
||||
double sumx = data->sumx;
|
||||
double sumy = data->sumy;
|
||||
double sumxy = data->sumxy;
|
||||
long double sumx = data->sumx;
|
||||
long double sumy = data->sumy;
|
||||
long double sumxy = data->sumxy;
|
||||
|
||||
double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
double regr_sxy = data->cnt * covar_pop;
|
||||
valOut = regr_sxy;
|
||||
long double covar_pop = (sumxy - ((sumx * sumy) / N)) / N;
|
||||
long double regr_sxy = data->cnt * covar_pop;
|
||||
valOut = static_cast<double>(regr_sxy);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ static Add_regr_syy_ToUDAFMap addToMap;
|
||||
struct regr_syy_data
|
||||
{
|
||||
uint64_t cnt;
|
||||
double sumy;
|
||||
double sumy2; // sum of (y squared)
|
||||
long double sumy;
|
||||
long double sumy2; // sum of (y squared)
|
||||
};
|
||||
|
||||
|
||||
@ -54,6 +54,13 @@ mcsv1_UDAF::ReturnCode regr_syy::init(mcsv1Context* context,
|
||||
context->setErrorMessage("regr_syy() with other than 2 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (!(isNumeric(colTypes[0].dataType)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("regr_syy() with a non-numeric dependant (first) argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(regr_syy_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
@ -118,14 +125,14 @@ mcsv1_UDAF::ReturnCode regr_syy::subEvaluate(mcsv1Context* context, const UserDa
|
||||
mcsv1_UDAF::ReturnCode regr_syy::evaluate(mcsv1Context* context, static_any::any& valOut)
|
||||
{
|
||||
struct regr_syy_data* data = (struct regr_syy_data*)context->getUserData()->data;
|
||||
double N = data->cnt;
|
||||
long double N = data->cnt;
|
||||
if (N > 0)
|
||||
{
|
||||
double sumy = data->sumy;
|
||||
double sumy2 = data->sumy2;
|
||||
long double sumy = data->sumy;
|
||||
long double sumy2 = data->sumy2;
|
||||
|
||||
double var_popy = (sumy2 - (sumy * sumy / N)) / N;
|
||||
valOut = data->cnt * var_popy;
|
||||
long double var_popy = (sumy2 - (sumy * sumy / N)) / N;
|
||||
valOut = static_cast<double>(data->cnt * var_popy);
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
@ -2,12 +2,30 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
using namespace std;
|
||||
|
||||
#include "idb_mysql.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
inline bool isNumeric(int type, const char* attr)
|
||||
{
|
||||
if (type == INT_RESULT || type == REAL_RESULT || type == DECIMAL_RESULT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#if _MSC_VER
|
||||
if (_strnicmp("NULL", attr, 4) == 0))
|
||||
#else
|
||||
if (strncasecmp("NULL", attr, 4) == 0)
|
||||
#endif
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline double cvtArgToDouble(int t, const char* v)
|
||||
{
|
||||
double d = 0.0;
|
||||
@ -144,6 +162,11 @@ extern "C"
|
||||
strcpy(message,"regr_avgx() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_avgx() with a non-numeric independant (second) argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_avgx_data*) malloc(sizeof(struct regr_avgx_data))))
|
||||
{
|
||||
@ -228,6 +251,11 @@ extern "C"
|
||||
strcpy(message,"regr_avgy() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0])))
|
||||
{
|
||||
strcpy(message,"regr_avgy() with a non-numeric dependant (first) argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_avgy_data*) malloc(sizeof(struct regr_avgy_data))))
|
||||
{
|
||||
@ -394,6 +422,11 @@ extern "C"
|
||||
strcpy(message,"regr_slope() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_slope() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_slope_data*) malloc(sizeof(struct regr_slope_data))))
|
||||
{
|
||||
@ -505,6 +538,11 @@ extern "C"
|
||||
strcpy(message,"regr_intercept() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_intercept() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_intercept_data*) malloc(sizeof(struct regr_intercept_data))))
|
||||
{
|
||||
@ -619,6 +657,11 @@ extern "C"
|
||||
strcpy(message,"regr_r2() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_r2() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_r2_data*) malloc(sizeof(struct regr_r2_data))))
|
||||
{
|
||||
@ -748,6 +791,11 @@ extern "C"
|
||||
strcpy(message,"corr() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"corr() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct corr_data*) malloc(sizeof(struct corr_data))))
|
||||
{
|
||||
@ -874,6 +922,11 @@ extern "C"
|
||||
strcpy(message,"regr_sxx() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_avgx() with a non-numeric independant (second) argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_sxx_data*) malloc(sizeof(struct regr_sxx_data))))
|
||||
{
|
||||
@ -970,6 +1023,11 @@ extern "C"
|
||||
strcpy(message,"regr_syy() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0])))
|
||||
{
|
||||
strcpy(message,"regr_syy() with a non-numeric dependant (first) argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_syy_data*) malloc(sizeof(struct regr_syy_data))))
|
||||
{
|
||||
@ -1068,6 +1126,11 @@ extern "C"
|
||||
strcpy(message,"regr_sxy() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"regr_sxy() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct regr_sxy_data*) malloc(sizeof(struct regr_sxy_data))))
|
||||
{
|
||||
@ -1171,6 +1234,11 @@ extern "C"
|
||||
strcpy(message,"covar_pop() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"covar_pop() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct covar_pop_data*) malloc(sizeof(struct covar_pop_data))))
|
||||
{
|
||||
@ -1273,6 +1341,11 @@ extern "C"
|
||||
strcpy(message,"covar_samp() requires two arguments");
|
||||
return 1;
|
||||
}
|
||||
if (!(isNumeric(args->arg_type[0], args->attributes[0]) && isNumeric(args->arg_type[1], args->attributes[1])))
|
||||
{
|
||||
strcpy(message,"covar_samp() with non-numeric arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct covar_samp_data*) malloc(sizeof(struct covar_samp_data))))
|
||||
{
|
||||
|
@ -976,7 +976,7 @@ inline mcsv1_UDAF::ReturnCode mcsv1_UDAF::createUserData(UserData*& userData, in
|
||||
template<typename T>
|
||||
inline T mcsv1_UDAF::convertAnyTo(static_any::any& valIn)
|
||||
{
|
||||
T val;
|
||||
T val = 0;
|
||||
if (valIn.compatible(longTypeId))
|
||||
{
|
||||
val = valIn.cast<long>();
|
||||
|
@ -84,7 +84,6 @@ void WF_udaf::resetData()
|
||||
getContext().getFunction()->reset(&getContext());
|
||||
fDistinctMap.clear();
|
||||
WindowFunctionType::resetData();
|
||||
fValOut.reset();
|
||||
}
|
||||
|
||||
void WF_udaf::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
@ -714,6 +713,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
fValOut.reset();
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
|
Reference in New Issue
Block a user