59 my_bool
corr_init(UDF_INIT *initid, UDF_ARGS *args,
char *message) {
62 if (args->arg_count < 2 || args->arg_count > 3) {
63 strcpy(message,
"corr() requires two or three arguments");
66 args->arg_type[0] = REAL_RESULT;
67 args->arg_type[1] = REAL_RESULT;
68 if (args->arg_count > 2) {
69 args->arg_type[2] = REAL_RESULT;
74 strcpy(message,
"Couldn't allocate memory");
77 data->
argc = args->arg_count;
79 initid->maybe_null = 1;
81 initid->max_length = 13 + initid->decimals;
82 initid->ptr = (
char *) data;
83 initid->const_item = 0;
99 void corr_reset(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
101 corr_add(initid, args, is_null, error);
113 void corr_clear(UDF_INIT *initid,
char *is_null,
char *error) {
134 void corr_add(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
140 if (!args->args[0] || !args->args[1]) {
144 if (data->
argc > 2) {
145 if (!args->args[2]) {
148 w = *((
double*) args->args[2]);
152 x = *((
double*) args->args[0]);
153 y = *((
double*) args->args[1]);
157 data->
sumXX += w * x * x;
158 data->
sumXY += w * x * y;
160 data->
sumYY += w * y * y;
172 double corr(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
183 if (nx <= 0 || ny <= 0) {
Definition of functions for UDFs and plugins.
my_bool corr_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
Called before first usage of function.
double sumXY
Sum of x * y.
double corr(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
Retrieve correlation coefficient. Called at end of group.
#define NOT_FIXED_DEC
Maximum number of digits in double As defined in mysql/sql_string.h.
Storage for corr function.
void corr_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
Add a member of the group.
void corr_reset(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
Reset function and add first group member Calls clear and add.
int argc
number of arguments
void corr_deinit(UDF_INIT *initid)
Called after last access to function.
void corr_clear(UDF_INIT *initid, char *is_null, char *error)
Called at start of group.