From 2b9f54d682f13e93e5d91c7ec159945dca671a8c Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 23 Apr 2019 15:41:20 -0500 Subject: [PATCH] MCOL-1985 Server set decimal count for UDF based on both parameters. This doesn't work for regr_avgx and regr_avgy, which only care about one of them. Do our best to handle it reasonably. Still gives unlimited decimals for InnoDB when the unused parameter is not numeric. --- utils/regr/corr.h | 3 +-- utils/regr/covar_pop.h | 3 +-- utils/regr/covar_samp.h | 3 +-- utils/regr/regr_avgx.cpp | 7 ------- utils/regr/regr_avgx.h | 3 +-- utils/regr/regr_avgy.cpp | 9 +-------- utils/regr/regr_avgy.h | 3 +-- utils/regr/regr_count.h | 3 +-- utils/regr/regr_intercept.h | 3 +-- utils/regr/regr_r2.h | 3 +-- utils/regr/regr_slope.h | 3 +-- utils/regr/regr_sxx.h | 3 +-- utils/regr/regr_sxy.h | 3 +-- utils/regr/regr_syy.h | 3 +-- utils/regr/regrmysql.cpp | 17 ++++++++++++----- 15 files changed, 25 insertions(+), 44 deletions(-) diff --git a/utils/regr/corr.h b/utils/regr/corr.h index eba7597eb..d1b5f55ac 100644 --- a/utils/regr/corr.h +++ b/utils/regr/corr.h @@ -25,8 +25,7 @@ * Columnstore interface for for the corr function * * - * CREATE AGGREGATE FUNCTION corr returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION corr returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_corr diff --git a/utils/regr/covar_pop.h b/utils/regr/covar_pop.h index fc47d4497..dda396fb9 100644 --- a/utils/regr/covar_pop.h +++ b/utils/regr/covar_pop.h @@ -25,8 +25,7 @@ * Columnstore interface for for the covar_pop function * * - * CREATE AGGREGATE FUNCTION covar_pop returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION covar_pop returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_covar_pop diff --git a/utils/regr/covar_samp.h b/utils/regr/covar_samp.h index 6aba65054..a65625520 100644 --- a/utils/regr/covar_samp.h +++ b/utils/regr/covar_samp.h @@ -25,8 +25,7 @@ * Columnstore interface for for the covar_samp function * * - * CREATE AGGREGATE FUNCTION covar_samp returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION covar_samp returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_covar_samp diff --git a/utils/regr/regr_avgx.cpp b/utils/regr/regr_avgx.cpp index bf010e648..8e4314d01 100644 --- a/utils/regr/regr_avgx.cpp +++ b/utils/regr/regr_avgx.cpp @@ -63,13 +63,6 @@ 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_avgx.h b/utils/regr/regr_avgx.h index 75791f769..960a6a892 100644 --- a/utils/regr/regr_avgx.h +++ b/utils/regr/regr_avgx.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_avgx function * * - * CREATE AGGREGATE FUNCTION regr_avgx returns REAL soname - * 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_avgx returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_avgx diff --git a/utils/regr/regr_avgy.cpp b/utils/regr/regr_avgy.cpp index 7325d991f..3d49e96b4 100644 --- a/utils/regr/regr_avgy.cpp +++ b/utils/regr/regr_avgy.cpp @@ -60,14 +60,7 @@ mcsv1_UDAF::ReturnCode regr_avgy::init(mcsv1Context* context, { // The error message will be prepended with // "The storage engine for the table doesn't support " - 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"); + context->setErrorMessage("regr_avgy() with a non-numeric y argument"); return mcsv1_UDAF::ERROR; } diff --git a/utils/regr/regr_avgy.h b/utils/regr/regr_avgy.h index c99021f9f..c2a3020da 100644 --- a/utils/regr/regr_avgy.h +++ b/utils/regr/regr_avgy.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_avgy function * * - * CREATE AGGREGATE FUNCTION regr_avgy returns REAL soname - * 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_avgy returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_avgy diff --git a/utils/regr/regr_count.h b/utils/regr/regr_count.h index 4f4fc558e..25cde7898 100644 --- a/utils/regr/regr_count.h +++ b/utils/regr/regr_count.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_count function * * - * CREATE AGGREGATE FUNCTION regr_count returns INTEGER - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_count returns INTEGER soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_count diff --git a/utils/regr/regr_intercept.h b/utils/regr/regr_intercept.h index ed82477cd..ef8dc6de5 100644 --- a/utils/regr/regr_intercept.h +++ b/utils/regr/regr_intercept.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_intercept function * * - * CREATE AGGREGATE FUNCTION regr_intercept returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_intercept returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_intercept diff --git a/utils/regr/regr_r2.h b/utils/regr/regr_r2.h index d440ad5a1..968814067 100644 --- a/utils/regr/regr_r2.h +++ b/utils/regr/regr_r2.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_r2 function * * - * CREATE AGGREGATE FUNCTION regr_r2 returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_r2 returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_r2 diff --git a/utils/regr/regr_slope.h b/utils/regr/regr_slope.h index 9c148d895..8a20494c1 100644 --- a/utils/regr/regr_slope.h +++ b/utils/regr/regr_slope.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_slope function * * - * CREATE AGGREGATE FUNCTION regr_slope returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_slope returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_slope diff --git a/utils/regr/regr_sxx.h b/utils/regr/regr_sxx.h index 14d82bd55..53c771b6f 100644 --- a/utils/regr/regr_sxx.h +++ b/utils/regr/regr_sxx.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_sxx function * * - * CREATE AGGREGATE FUNCTION regr_sxx returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_sxx returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_sxx diff --git a/utils/regr/regr_sxy.h b/utils/regr/regr_sxy.h index 25aa34145..6371c6fed 100644 --- a/utils/regr/regr_sxy.h +++ b/utils/regr/regr_sxy.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_sxy function * * - * CREATE AGGREGATE FUNCTION regr_sxy returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_sxy returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_sxy diff --git a/utils/regr/regr_syy.h b/utils/regr/regr_syy.h index a837fab13..d1a582f4d 100644 --- a/utils/regr/regr_syy.h +++ b/utils/regr/regr_syy.h @@ -25,8 +25,7 @@ * Columnstore interface for for the regr_syy function * * - * CREATE AGGREGATE FUNCTION regr_syy returns REAL - * soname 'libregr_mysql.so'; + * CREATE AGGREGATE FUNCTION regr_syy returns REAL soname 'libregr_mysql.so'; * */ #ifndef HEADER_regr_syy diff --git a/utils/regr/regrmysql.cpp b/utils/regr/regrmysql.cpp index 32cd41209..2570163f1 100644 --- a/utils/regr/regrmysql.cpp +++ b/utils/regr/regrmysql.cpp @@ -167,10 +167,13 @@ extern "C" strcpy(message,"regr_avgx() with a non-numeric independant (second) argument"); return 1; } - - if (initid->decimals != DECIMAL_NOT_SPECIFIED) + if (args->arg_type[1] == DECIMAL_RESULT && initid->decimals != DECIMAL_NOT_SPECIFIED) { - initid->decimals +=4; + initid->decimals += 4; + } + else + { + initid->decimals = DECIMAL_NOT_SPECIFIED; } if (!(data = (struct regr_avgx_data*) malloc(sizeof(struct regr_avgx_data)))) @@ -272,9 +275,13 @@ extern "C" return 1; } - if (initid->decimals != DECIMAL_NOT_SPECIFIED) + if (args->arg_type[0] == DECIMAL_RESULT && initid->decimals != DECIMAL_NOT_SPECIFIED) { - initid->decimals +=4; + initid->decimals += 4; + } + else + { + initid->decimals = DECIMAL_NOT_SPECIFIED; } if (!(data = (struct regr_avgy_data*) malloc(sizeof(struct regr_avgy_data))))