55 my_bool
avgw_init(UDF_INIT *initid, UDF_ARGS *args,
char *message) {
58 if (args->arg_count < 1 || args->arg_count > 2) {
59 strcpy(message,
"avgw() requires one or two arguments");
62 args->arg_type[0] = REAL_RESULT;
63 if (args->arg_count > 1) {
64 args->arg_type[1] = REAL_RESULT;
69 strcpy(message,
"Couldn't allocate memory");
72 data->
argc = args->arg_count;
74 initid->maybe_null = 1;
76 initid->max_length = 13 + initid->decimals;
77 initid->ptr = (
char *) data;
78 initid->const_item = 0;
94 void avgw_reset(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
96 avgw_add(initid, args, is_null, error);
108 void avgw_clear(UDF_INIT *initid,
char *is_null,
char *error) {
125 void avgw_add(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
130 if (!args->args[0]) {
134 if (data->
argc > 1) {
135 if (!args->args[1]) {
138 w = *((
double*) args->args[1]);
142 x = *((
double*) args->args[0]);
157 double avgw(UDF_INIT *initid, UDF_ARGS *args,
char *is_null,
char *error) {
Definition of functions for UDFs and plugins.
void avgw_deinit(UDF_INIT *initid)
Called after last access to function.
#define NOT_FIXED_DEC
Maximum number of digits in double As defined in mysql/sql_string.h.
void avgw_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 avgw_clear(UDF_INIT *initid, char *is_null, char *error)
Called at start of group.
my_bool avgw_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
Called before first usage of function.
Storage for weighted average.
double weight
Sum of weight.
double avgw(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
Retrieve weighted average. Called at end of group.
void avgw_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
Add a member of the group.