Statistics for MySQL  0.9
Classes | Functions
avgw.c File Reference

Weighted average. More...

#include "sqlstat.h"
Include dependency graph for avgw.c:

Go to the source code of this file.

Classes

struct  avgw_storage
 Storage for weighted average. More...

Functions

my_bool avgw_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
 Called before first usage of function.
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.
void avgw_clear (UDF_INIT *initid, char *is_null, char *error)
 Called at start of group.
void avgw_add (UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 Add a member of the group.
double avgw (UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 Retrieve weighted average. Called at end of group.
void avgw_deinit (UDF_INIT *initid)
 Called after last access to function.

Detailed Description

Weighted average.

CREATE AGGREGATE FUNCTION avgw RETURNS REAL SONAME 'libsqlstat.so'; SELECT avgw(x, w) FROM mytab; DROP FUNCTION avgw;

Definition in file avgw.c.


Function Documentation

double avgw ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  is_null,
char *  error 
)

Retrieve weighted average. Called at end of group.

Parameters:
initidfunction description
argsargument values
is_nullresult is NULL
errorerror message
Returns:
weighted average

Definition at line 155 of file avgw.c.

void avgw_add ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  is_null,
char *  error 
)

Add a member of the group.

The sums are updated

Parameters:
initidfunction description
argsargument values
is_null
errorerror message

Definition at line 123 of file avgw.c.

Here is the caller graph for this function:

void avgw_clear ( UDF_INIT *  initid,
char *  is_null,
char *  error 
)

Called at start of group.

void avgw_clear(UDF_INIT *initid, char *is_null, char *error) The sums are cleared.

Parameters:
initidfunction description
is_null
errorerror message

Definition at line 106 of file avgw.c.

Here is the caller graph for this function:

void avgw_deinit ( UDF_INIT *  initid)

Called after last access to function.

Deallocate memory for counter and sums.

Parameters:
initid

Definition at line 175 of file avgw.c.

my_bool avgw_init ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  message 
)

Called before first usage of function.

Check parameters.
Indicate type of return value.
Allocate memory for sums.

Parameters:
initidfunction description
argsparameters
messageerror message
Returns:
success = 0

Definition at line 53 of file avgw.c.

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.

Parameters:
initidfunction description
argsargument values
is_null
errorerror message
Deprecated:
Reset is only called by MySQL 4.0 and below. It is implemented for backwards compatibility.

Definition at line 92 of file avgw.c.

Here is the call graph for this function:

 All Classes Files Functions Variables Typedefs Defines