diff --git a/utils/regr/corr.cpp b/utils/regr/corr.cpp index 9d12680ea..13efbe897 100644 --- a/utils/regr/corr.cpp +++ b/utils/regr/corr.cpp @@ -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); diff --git a/utils/regr/covar_pop.cpp b/utils/regr/covar_pop.cpp index 51d9a036f..6313e49d2 100644 --- a/utils/regr/covar_pop.cpp +++ b/utils/regr/covar_pop.cpp @@ -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); diff --git a/utils/regr/covar_samp.cpp b/utils/regr/covar_samp.cpp index b0ebb168b..0a79ff31a 100644 --- a/utils/regr/covar_samp.cpp +++ b/utils/regr/covar_samp.cpp @@ -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); diff --git a/utils/regr/regr_avgx.cpp b/utils/regr/regr_avgx.cpp index c366f4e5a..e601b4172 100644 --- a/utils/regr/regr_avgx.cpp +++ b/utils/regr/regr_avgx.cpp @@ -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); diff --git a/utils/regr/regr_avgy.cpp b/utils/regr/regr_avgy.cpp index 87a729263..0d0cc58dd 100644 --- a/utils/regr/regr_avgy.cpp +++ b/utils/regr/regr_avgy.cpp @@ -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); diff --git a/utils/regr/regr_intercept.cpp b/utils/regr/regr_intercept.cpp index 011488d9d..d46d3117c 100644 --- a/utils/regr/regr_intercept.cpp +++ b/utils/regr/regr_intercept.cpp @@ -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); diff --git a/utils/regr/regr_r2.cpp b/utils/regr/regr_r2.cpp index 96b0ada18..f159d834a 100644 --- a/utils/regr/regr_r2.cpp +++ b/utils/regr/regr_r2.cpp @@ -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); diff --git a/utils/regr/regr_slope.cpp b/utils/regr/regr_slope.cpp index fdb94795a..6790e223e 100644 --- a/utils/regr/regr_slope.cpp +++ b/utils/regr/regr_slope.cpp @@ -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); diff --git a/utils/regr/regr_sxx.cpp b/utils/regr/regr_sxx.cpp index 3f06af61b..b4c467fc3 100644 --- a/utils/regr/regr_sxx.cpp +++ b/utils/regr/regr_sxx.cpp @@ -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); diff --git a/utils/regr/regr_sxy.cpp b/utils/regr/regr_sxy.cpp index e6d005597..9cdbffb6a 100644 --- a/utils/regr/regr_sxy.cpp +++ b/utils/regr/regr_sxy.cpp @@ -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); diff --git a/utils/regr/regr_syy.cpp b/utils/regr/regr_syy.cpp index d0841f723..98e614a8e 100644 --- a/utils/regr/regr_syy.cpp +++ b/utils/regr/regr_syy.cpp @@ -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); diff --git a/utils/regr/regrmysql.cpp b/utils/regr/regrmysql.cpp index 08f46bb11..4980108e3 100644 --- a/utils/regr/regrmysql.cpp +++ b/utils/regr/regrmysql.cpp @@ -2,12 +2,30 @@ #include #include #include +#include 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,7 +162,12 @@ 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)))) { strmov(message,"Couldn't allocate memory"); @@ -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)))) { diff --git a/utils/udfsdk/mcsv1_udaf.h b/utils/udfsdk/mcsv1_udaf.h index ec0d0cb79..d6ba04483 100644 --- a/utils/udfsdk/mcsv1_udaf.h +++ b/utils/udfsdk/mcsv1_udaf.h @@ -976,7 +976,7 @@ inline mcsv1_UDAF::ReturnCode mcsv1_UDAF::createUserData(UserData*& userData, in template inline T mcsv1_UDAF::convertAnyTo(static_any::any& valIn) { - T val; + T val = 0; if (valIn.compatible(longTypeId)) { val = valIn.cast();