diff --git a/README.md b/README.md index 5c93c2c..8c85d22 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ Aggregate Functions Get the median of a set ``` -double median(double n); +double med(double n); -mysql> SELECT median(weight) from t1; +mysql> SELECT med(weight) from t1; ``` @@ -129,18 +129,18 @@ mysql> SELECT lessavg(double m) from t1; Calculate continuous percentile. Returns the value at a relative position specified by the fraction, interpolating between input values if needed. ``` -double percentile_cont(double x, double fraction); +double percentile_contin(double x, double fraction); -mysql> SELECT percentile_cont(x, 0.5) from t1; +mysql> SELECT percentile_contin(x, 0.5) from t1; ``` Calculate discrete percentile. Returns the first input value whose relative position is greater than or equal to the specified fraction. ``` -double percentile_disc(double x, double fraction); +double percentile_discr(double x, double fraction); -mysql> SELECT percentile_disc(x, 0.5) from t1; +mysql> SELECT percentile_discr(x, 0.5) from t1; ``` diff --git a/load.sql.sh b/load.sql.sh index 2f2efed..49a409f 100644 --- a/load.sql.sh +++ b/load.sql.sh @@ -38,12 +38,12 @@ if_enable "kurtosis" && create_agg_function "kurtosis" "real" if_enable "lessavg" && create_agg_function "lessavg" "integer" if_enable "lesspartpct" && create_agg_function "lesspartpct" "integer" if_enable "lesspart" && create_agg_function "lesspart" "integer" -if_enable "median" && create_agg_function "median" "real" +if_enable "med" && create_agg_function "med" "real" if_enable "stats_mode" && create_agg_function "stats_mode" "real" if_enable "ngram" && create_function "ngram" "string" if_enable "noverk" && create_function "noverk" "integer" -if_enable "percentile_cont" && create_agg_function "percentile_cont" "real" -if_enable "percentile_disc" && create_agg_function "percentile_disc" "real" +if_enable "percentile_contin" && create_agg_function "percentile_contin" "real" +if_enable "percentile_discr" && create_agg_function "percentile_discr" "real" if_enable "rotbit" && create_function "rotbit" "integer" if_enable "rotint" && create_function "rotint" "integer" if_enable "rsumd" && create_function "rsumd" "real" diff --git a/load.win.sql b/load.win.sql index e1c7124..9159704 100644 --- a/load.win.sql +++ b/load.win.sql @@ -15,12 +15,12 @@ DROP FUNCTION IF EXISTS kurtosis; DROP FUNCTION IF EXISTS lessavg; DROP FUNCTION IF EXISTS lesspartpct; DROP FUNCTION IF EXISTS lesspart; -DROP FUNCTION IF EXISTS median; +DROP FUNCTION IF EXISTS med; DROP FUNCTION IF EXISTS stats_mode; DROP FUNCTION IF EXISTS ngram; DROP FUNCTION IF EXISTS noverk; -DROP FUNCTION IF EXISTS percentile_cont; -DROP FUNCTION IF EXISTS percentile_disc; +DROP FUNCTION IF EXISTS percentile_contin; +DROP FUNCTION IF EXISTS percentile_discr; DROP FUNCTION IF EXISTS rotbit; DROP FUNCTION IF EXISTS rotint; DROP FUNCTION IF EXISTS rsumd; @@ -46,12 +46,12 @@ CREATE AGGREGATE FUNCTION kurtosis RETURNS real SONAME 'udf_infusion.dll'; CREATE AGGREGATE FUNCTION lessavg RETURNS integer SONAME 'udf_infusion.dll'; CREATE AGGREGATE FUNCTION lesspartpct RETURNS integer SONAME 'udf_infusion.dll'; CREATE AGGREGATE FUNCTION lesspart RETURNS integer SONAME 'udf_infusion.dll'; -CREATE AGGREGATE FUNCTION median RETURNS real SONAME 'udf_infusion.dll'; +CREATE AGGREGATE FUNCTION med RETURNS real SONAME 'udf_infusion.dll'; CREATE AGGREGATE FUNCTION stats_mode RETURNS real SONAME 'udf_infusion.dll'; CREATE FUNCTION ngram RETURNS string SONAME 'udf_infusion.dll'; CREATE FUNCTION noverk RETURNS integer SONAME 'udf_infusion.dll'; -CREATE AGGREGATE FUNCTION percentile_cont RETURNS real SONAME 'udf_infusion.dll'; -CREATE AGGREGATE FUNCTION percentile_disc RETURNS real SONAME 'udf_infusion.dll'; +CREATE AGGREGATE FUNCTION percentile_contin RETURNS real SONAME 'udf_infusion.dll'; +CREATE AGGREGATE FUNCTION percentile_discr RETURNS real SONAME 'udf_infusion.dll'; CREATE FUNCTION rotbit RETURNS integer SONAME 'udf_infusion.dll'; CREATE FUNCTION rotint RETURNS integer SONAME 'udf_infusion.dll'; CREATE FUNCTION rsumd RETURNS real SONAME 'udf_infusion.dll'; diff --git a/src/median.c b/src/median.c index 92fc877..6468047 100644 --- a/src/median.c +++ b/src/median.c @@ -5,12 +5,12 @@ struct Buffer { struct array values; }; -DLLEXPORT my_bool median_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { +DLLEXPORT my_bool med_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { struct Buffer *data; if (1 != args->arg_count) { snprintf(message, MYSQL_ERRMSG_SIZE, - "median must have exactly one argument"); + "med must have exactly one argument"); return 1; } @@ -34,12 +34,12 @@ DLLEXPORT my_bool median_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { return 0; } -DLLEXPORT void median_clear(UDF_INIT* initid, char* is_null, char *error) { +DLLEXPORT void med_clear(UDF_INIT* initid, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; array_truncate(&data->values); } -DLLEXPORT void median_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { +DLLEXPORT void med_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; if (NULL == args->args[0]) @@ -51,7 +51,7 @@ DLLEXPORT void median_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char } } -DLLEXPORT void median_deinit(UDF_INIT *initid) { +DLLEXPORT void med_deinit(UDF_INIT *initid) { struct Buffer *data = (struct Buffer *) initid->ptr; if (NULL != data) { array_free(&data->values); @@ -60,7 +60,7 @@ DLLEXPORT void median_deinit(UDF_INIT *initid) { } } -DLLEXPORT double median(UDF_INIT *initid, UDF_ARGS *args, +DLLEXPORT double med(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error __attribute__((unused))) { struct Buffer *data = (struct Buffer *) initid->ptr; diff --git a/src/percentile_cont.c b/src/percentile_cont.c index 7e54076..dd45320 100644 --- a/src/percentile_cont.c +++ b/src/percentile_cont.c @@ -6,12 +6,12 @@ struct Buffer { double percentile; }; -DLLEXPORT my_bool percentile_cont_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { +DLLEXPORT my_bool percentile_contin_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { struct Buffer *data; if (2 != args->arg_count) { snprintf(message, MYSQL_ERRMSG_SIZE, - "percentile_cont must have exactly two arguments"); + "percentile_contin must have exactly two arguments"); return 1; } @@ -36,12 +36,12 @@ DLLEXPORT my_bool percentile_cont_init(UDF_INIT *initid, UDF_ARGS *args, char *m return 0; } -DLLEXPORT void percentile_cont_clear(UDF_INIT* initid, char* is_null, char *error) { +DLLEXPORT void percentile_contin_clear(UDF_INIT* initid, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; array_truncate(&data->values); } -DLLEXPORT void percentile_cont_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { +DLLEXPORT void percentile_contin_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; double percentile = *((double *) args->args[1]); @@ -60,7 +60,7 @@ DLLEXPORT void percentile_cont_add(UDF_INIT* initid, UDF_ARGS* args, char* is_nu } } -DLLEXPORT void percentile_cont_deinit(UDF_INIT *initid) { +DLLEXPORT void percentile_contin_deinit(UDF_INIT *initid) { struct Buffer *data = (struct Buffer *) initid->ptr; if (NULL != data) { array_free(&data->values); @@ -69,7 +69,7 @@ DLLEXPORT void percentile_cont_deinit(UDF_INIT *initid) { } } -DLLEXPORT double percentile_cont(UDF_INIT *initid, UDF_ARGS *args, +DLLEXPORT double percentile_contin(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error __attribute__((unused))) { struct Buffer *data = (struct Buffer *) initid->ptr; diff --git a/src/percentile_disc.c b/src/percentile_disc.c index 7a4899b..8cbb78a 100644 --- a/src/percentile_disc.c +++ b/src/percentile_disc.c @@ -6,12 +6,12 @@ struct Buffer { double percentile; }; -DLLEXPORT my_bool percentile_disc_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { +DLLEXPORT my_bool percentile_discr_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { struct Buffer *data; if (2 != args->arg_count) { snprintf(message, MYSQL_ERRMSG_SIZE, - "percentile_disc must have exactly two arguments"); + "percentile_discr must have exactly two arguments"); return 1; } @@ -36,12 +36,12 @@ DLLEXPORT my_bool percentile_disc_init(UDF_INIT *initid, UDF_ARGS *args, char *m return 0; } -DLLEXPORT void percentile_disc_clear(UDF_INIT* initid, char* is_null, char *error) { +DLLEXPORT void percentile_discr_clear(UDF_INIT* initid, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; array_truncate(&data->values); } -DLLEXPORT void percentile_disc_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { +DLLEXPORT void percentile_discr_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) { struct Buffer *data = (struct Buffer *) initid->ptr; double percentile = *((double *) args->args[1]); @@ -60,7 +60,7 @@ DLLEXPORT void percentile_disc_add(UDF_INIT* initid, UDF_ARGS* args, char* is_nu } } -DLLEXPORT void percentile_disc_deinit(UDF_INIT *initid) { +DLLEXPORT void percentile_discr_deinit(UDF_INIT *initid) { struct Buffer *data = (struct Buffer *) initid->ptr; if (NULL != data) { array_free(&data->values); @@ -69,7 +69,7 @@ DLLEXPORT void percentile_disc_deinit(UDF_INIT *initid) { } } -DLLEXPORT double percentile_disc(UDF_INIT *initid, UDF_ARGS *args, +DLLEXPORT double percentile_discr(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error __attribute__((unused))) { struct Buffer *data = (struct Buffer *) initid->ptr; diff --git a/test/median.test b/test/median.test index cc354b5..937b8da 100644 --- a/test/median.test +++ b/test/median.test @@ -2,42 +2,42 @@ disable_abort_on_error; use udf_infusion_test; -select median(); -# ERROR HY000: Can't initialize function 'median'; median must have exactly one argument +select med(); +# ERROR HY000: Can't initialize function 'med'; med must have exactly one argument -select median(1, 2); -# ERROR HY000: Can't initialize function 'median'; median must have exactly one argument +select med(1, 2); +# ERROR HY000: Can't initialize function 'med'; med must have exactly one argument -select median(NULL); -# median(NULL) +select med(NULL); +# med(NULL) # NULL -select median(x) from empty_table; -# median(x) +select med(x) from empty_table; +# med(x) # NULL -select median(x) from null_table; -# median(x) +select med(x) from null_table; +# med(x) # NULL -select median(x) from small_table; -# median(x) +select med(x) from small_table; +# med(x) # 4.5 -select median(x) from (select x from small_table where x is not null order by x limit 7) as t; -# median(x) +select med(x) from (select x from small_table where x is not null order by x limit 7) as t; +# med(x) # 4 -select g, median(x) from small_table group by g; -# g median(x) +select g, med(x) from small_table group by g; +# g med(x) # 1 1.5 # 2 4 # 3 7 -select round(median(x), 12) as `median(x)` from example_table; -# median(x) -# >>> print '%.12f' % ma.median(example_table()[:,0]) +select round(med(x), 12) as `med(x)` from example_table; +# med(x) +# >>> print '%.12f' % ma.med(example_table()[:,0]) -select round(median(y), 12) as `median(y)` from example_table; -# median(y) -# >>> print '%.12f' % ma.median(example_table()[:,1]) +select round(med(y), 12) as `med(y)` from example_table; +# med(y) +# >>> print '%.12f' % ma.med(example_table()[:,1]) diff --git a/test/percentile_cont.test b/test/percentile_cont.test index cbdd133..8cf64c2 100644 --- a/test/percentile_cont.test +++ b/test/percentile_cont.test @@ -2,58 +2,58 @@ disable_abort_on_error; use udf_infusion_test; -select percentile_cont(); -# ERROR HY000: Can't initialize function 'percentile_cont'; percentile_cont must have exactly two arguments +select percentile_contin(); +# ERROR HY000: Can't initialize function 'percentile_contin'; percentile_contin must have exactly two arguments -select percentile_cont(1, 2, 3); -# ERROR HY000: Can't initialize function 'percentile_cont'; percentile_cont must have exactly two arguments +select percentile_contin(1, 2, 3); +# ERROR HY000: Can't initialize function 'percentile_contin'; percentile_contin must have exactly two arguments -select percentile_cont(NULL, 0.5); -# percentile_cont(NULL, 0.5) +select percentile_contin(NULL, 0.5); +# percentile_contin(NULL, 0.5) # NULL -select percentile_cont(x, 0.5) from empty_table; -# percentile_cont(x, 0.5) +select percentile_contin(x, 0.5) from empty_table; +# percentile_contin(x, 0.5) # NULL -select percentile_cont(x, 0.5) from null_table; -# percentile_cont(x, 0.5) +select percentile_contin(x, 0.5) from null_table; +# percentile_contin(x, 0.5) # NULL -select percentile_cont(x, 0.5) from small_table; -# percentile_cont(x, 0.5) +select percentile_contin(x, 0.5) from small_table; +# percentile_contin(x, 0.5) # 4.5 -select percentile_cont(x, 0) from small_table; -# percentile_cont(x, 0) +select percentile_contin(x, 0) from small_table; +# percentile_contin(x, 0) # 1 -select percentile_cont(x, 1) from small_table; -# percentile_cont(x, 1) +select percentile_contin(x, 1) from small_table; +# percentile_contin(x, 1) # 8 -select percentile_cont(x, 0.001) from small_table; -# percentile_cont(x, 0.001) +select percentile_contin(x, 0.001) from small_table; +# percentile_contin(x, 0.001) # 1.007 -select percentile_cont(x, 0.999) from small_table; -# percentile_cont(x, 0.999) +select percentile_contin(x, 0.999) from small_table; +# percentile_contin(x, 0.999) # 7.993 -select percentile_cont(x, 0.6) from small_table; -# percentile_cont(x, 0.6) +select percentile_contin(x, 0.6) from small_table; +# percentile_contin(x, 0.6) # 5.2 -select g, percentile_cont(x, 0.7) from small_table group by g; -# g percentile_cont(x, 0.7) +select g, percentile_contin(x, 0.7) from small_table group by g; +# g percentile_contin(x, 0.7) # 1 1.7 # 2 4.4 # 3 7.4 -select round(percentile_cont(x, 0.7), 12) as `percentile_cont(x, 0.7)` from example_table; -# percentile_cont(x, 0.7) +select round(percentile_contin(x, 0.7), 12) as `percentile_contin(x, 0.7)` from example_table; +# percentile_contin(x, 0.7) # >>> print '%.12f' % np.percentile(example_table()[:,0].compressed(), 70) -select round(percentile_cont(y, 0.7), 12) as `percentile_cont(y, 0.7)` from example_table; -# percentile_cont(y, 0.7) +select round(percentile_contin(y, 0.7), 12) as `percentile_contin(y, 0.7)` from example_table; +# percentile_contin(y, 0.7) # >>> print '%.12f' % np.percentile(example_table()[:,1].compressed(), 70) diff --git a/test/percentile_disc.test b/test/percentile_disc.test index 90f0230..da283a9 100644 --- a/test/percentile_disc.test +++ b/test/percentile_disc.test @@ -2,50 +2,50 @@ disable_abort_on_error; use udf_infusion_test; -select percentile_disc(); -# ERROR HY000: Can't initialize function 'percentile_disc'; percentile_disc must have exactly two arguments +select percentile_discr(); +# ERROR HY000: Can't initialize function 'percentile_discr'; percentile_discr must have exactly two arguments -select percentile_disc(1, 2, 3); -# ERROR HY000: Can't initialize function 'percentile_disc'; percentile_disc must have exactly two arguments +select percentile_discr(1, 2, 3); +# ERROR HY000: Can't initialize function 'percentile_discr'; percentile_discr must have exactly two arguments -select percentile_disc(NULL, 0.5); -# percentile_disc(NULL, 0.5) +select percentile_discr(NULL, 0.5); +# percentile_discr(NULL, 0.5) # NULL -select percentile_disc(x, 0.5) from empty_table; -# percentile_disc(x, 0.5) +select percentile_discr(x, 0.5) from empty_table; +# percentile_discr(x, 0.5) # NULL -select percentile_disc(x, 0.5) from null_table; -# percentile_disc(x, 0.5) +select percentile_discr(x, 0.5) from null_table; +# percentile_discr(x, 0.5) # NULL -select percentile_disc(x, 0.5) from small_table; -# percentile_disc(x, 0.5) +select percentile_discr(x, 0.5) from small_table; +# percentile_discr(x, 0.5) # 4 -select percentile_disc(x, 0) from small_table; -# percentile_disc(x, 0) +select percentile_discr(x, 0) from small_table; +# percentile_discr(x, 0) # 1 -select percentile_disc(x, 1) from small_table; -# percentile_disc(x, 1) +select percentile_discr(x, 1) from small_table; +# percentile_discr(x, 1) # 8 -select percentile_disc(x, 0.001) from small_table; -# percentile_disc(x, 0.001) +select percentile_discr(x, 0.001) from small_table; +# percentile_discr(x, 0.001) # 1 -select percentile_disc(x, 0.999) from small_table; -# percentile_disc(x, 0.999) +select percentile_discr(x, 0.999) from small_table; +# percentile_discr(x, 0.999) # 8 -select percentile_disc(x, 0.501) from small_table; -# percentile_disc(x, 0.501) +select percentile_discr(x, 0.501) from small_table; +# percentile_discr(x, 0.501) # 5 -select g, percentile_disc(x, 0.7) from small_table group by g; -# g percentile_disc(x, 0.7) +select g, percentile_discr(x, 0.7) from small_table group by g; +# g percentile_discr(x, 0.7) # 1 2 # 2 5 # 3 8 diff --git a/unload.sql.sh b/unload.sql.sh index d9e2b5e..864db61 100644 --- a/unload.sql.sh +++ b/unload.sql.sh @@ -32,12 +32,12 @@ if_enable "kurtosis" && drop_function "kurtosis" if_enable "lessavg" && drop_function "lessavg" if_enable "lesspartpct" && drop_function "lesspartpct" if_enable "lesspart" && drop_function "lesspart" -if_enable "median" && drop_function "median" +if_enable "med" && drop_function "med" if_enable "stats_mode" && drop_function "stats_mode" if_enable "ngram" && drop_function "ngram" if_enable "noverk" && drop_function "noverk" -if_enable "percentile_cont" && drop_function "percentile_cont" -if_enable "percentile_disc" && drop_function "percentile_disc" +if_enable "percentile_contin" && drop_function "percentile_contin" +if_enable "percentile_discr" && drop_function "percentile_discr" if_enable "rotbit" && drop_function "rotbit" if_enable "rotint" && drop_function "rotint" if_enable "rsumd" && drop_function "rsumd" diff --git a/unload.win.sql b/unload.win.sql index 17dd9ed..92764f3 100644 --- a/unload.win.sql +++ b/unload.win.sql @@ -15,12 +15,12 @@ DROP FUNCTION IF EXISTS kurtosis; DROP FUNCTION IF EXISTS lessavg; DROP FUNCTION IF EXISTS lesspartpct; DROP FUNCTION IF EXISTS lesspart; -DROP FUNCTION IF EXISTS median; +DROP FUNCTION IF EXISTS med; DROP FUNCTION IF EXISTS stats_mode; DROP FUNCTION IF EXISTS ngram; DROP FUNCTION IF EXISTS noverk; -DROP FUNCTION IF EXISTS percentile_cont; -DROP FUNCTION IF EXISTS percentile_disc; +DROP FUNCTION IF EXISTS percentile_contin; +DROP FUNCTION IF EXISTS percentile_discr; DROP FUNCTION IF EXISTS rotbit; DROP FUNCTION IF EXISTS rotint; DROP FUNCTION IF EXISTS rsumd;