You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
clang format apply
This commit is contained in:
@ -10,30 +10,23 @@ namespace
|
||||
{
|
||||
inline double cvtArgToDouble(int t, const char* v)
|
||||
{
|
||||
double d = 0.0;
|
||||
double d = 0.0;
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case INT_RESULT:
|
||||
d = (double)(*((long long*)v));
|
||||
break;
|
||||
switch (t)
|
||||
{
|
||||
case INT_RESULT: d = (double)(*((long long*)v)); break;
|
||||
|
||||
case REAL_RESULT:
|
||||
d = *((double*)v);
|
||||
break;
|
||||
case REAL_RESULT: d = *((double*)v); break;
|
||||
|
||||
case DECIMAL_RESULT:
|
||||
case STRING_RESULT:
|
||||
d = strtod(v, 0);
|
||||
break;
|
||||
case DECIMAL_RESULT:
|
||||
case STRING_RESULT: d = strtod(v, 0); break;
|
||||
|
||||
case ROW_RESULT:
|
||||
break;
|
||||
}
|
||||
case ROW_RESULT: break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/****************************************************************************
|
||||
* UDF function interface for MariaDB connector to recognize is defined in
|
||||
@ -59,510 +52,487 @@ inline double cvtArgToDouble(int t, const char* v)
|
||||
*/
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* MCS_ADD connector stub
|
||||
*/
|
||||
/**
|
||||
* MCS_ADD connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool mcs_add_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
my_bool mcs_add_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 2)
|
||||
{
|
||||
if (args->arg_count != 2)
|
||||
{
|
||||
strcpy(message, "mcs_add() requires two argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
strcpy(message, "mcs_add() requires two argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void mcs_add_deinit(UDF_INIT* initid)
|
||||
{
|
||||
}
|
||||
void mcs_add_deinit(UDF_INIT* initid)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
double mcs_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error)
|
||||
{
|
||||
double op1, op2;
|
||||
double mcs_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error)
|
||||
{
|
||||
double op1, op2;
|
||||
|
||||
op1 = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
op2 = cvtArgToDouble(args->arg_type[1], args->args[1]);
|
||||
op1 = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
op2 = cvtArgToDouble(args->arg_type[1], args->args[1]);
|
||||
|
||||
return op1 + op2;
|
||||
}
|
||||
return op1 + op2;
|
||||
}
|
||||
|
||||
/**
|
||||
* MCS_ISNULL connector stub
|
||||
*/
|
||||
/**
|
||||
* MCS_ISNULL connector stub
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool mcs_isnull_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
my_bool mcs_isnull_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "mcs_isnull() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
strcpy(message, "mcs_isnull() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void mcs_isnull_deinit(UDF_INIT* initid)
|
||||
{
|
||||
}
|
||||
void mcs_isnull_deinit(UDF_INIT* initid)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long mcs_isnull(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
long long mcs_isnull(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ALLNULL connector stub
|
||||
*/
|
||||
struct allnull_data
|
||||
{
|
||||
ulonglong totalQuantity;
|
||||
ulonglong totalNulls;
|
||||
};
|
||||
/**
|
||||
* ALLNULL connector stub
|
||||
*/
|
||||
struct allnull_data
|
||||
{
|
||||
ulonglong totalQuantity;
|
||||
ulonglong totalNulls;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool allnull_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
my_bool allnull_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct allnull_data* data;
|
||||
// if (args->arg_count != 1)
|
||||
// {
|
||||
// strcpy(message,"allnull() requires one argument");
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (!(data = (struct allnull_data*)malloc(sizeof(struct allnull_data))))
|
||||
{
|
||||
struct allnull_data* data;
|
||||
// if (args->arg_count != 1)
|
||||
// {
|
||||
// strcpy(message,"allnull() requires one argument");
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (!(data = (struct allnull_data*) malloc(sizeof(struct allnull_data))))
|
||||
{
|
||||
strmov(message, "Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
|
||||
return 0;
|
||||
strmov(message, "Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void allnull_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
void allnull_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long allnull(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
return data->totalQuantity > 0 && data->totalNulls == data->totalQuantity;
|
||||
}
|
||||
long long allnull(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
return data->totalQuantity > 0 && data->totalNulls == data->totalQuantity;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
allnull_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
}
|
||||
void allnull_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
allnull_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
const char* word = args->args[0];
|
||||
data->totalQuantity++;
|
||||
void allnull_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
const char* word = args->args[0];
|
||||
data->totalQuantity++;
|
||||
|
||||
if (!word)
|
||||
{
|
||||
data->totalNulls++;
|
||||
}
|
||||
if (!word)
|
||||
{
|
||||
data->totalNulls++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SSQ connector stub
|
||||
*/
|
||||
struct ssq_data
|
||||
{
|
||||
double sumsq;
|
||||
};
|
||||
/**
|
||||
* SSQ connector stub
|
||||
*/
|
||||
struct ssq_data
|
||||
{
|
||||
double sumsq;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool ssq_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
my_bool ssq_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct ssq_data* data;
|
||||
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
struct ssq_data* data;
|
||||
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "ssq() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message, "Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
return 0;
|
||||
strcpy(message, "ssq() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct ssq_data*)malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message, "Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void ssq_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
void ssq_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
ssq_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
data->sumsq = 0;
|
||||
}
|
||||
void ssq_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
ssq_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
data->sumsq = val * val;
|
||||
}
|
||||
void ssq_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
data->sumsq = val * val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long ssq(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
return data->sumsq;
|
||||
}
|
||||
long long ssq(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
return data->sumsq;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* MEDIAN connector stub
|
||||
*/
|
||||
/**
|
||||
* MEDIAN connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool median_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
my_bool median_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "median() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
*/
|
||||
return 0;
|
||||
strcpy(message, "median() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void median_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
median_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
median_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
// data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long median(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// return data->sumsq;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* avg_mode connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool avg_mode_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "avg_mode() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avg_mode_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
avg_mode_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
avg_mode_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
// data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long avg_mode(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// return data->sumsq;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* avgx connector stub. Exactly the same functionality as the
|
||||
* built in avg() function. Use to test the performance of the
|
||||
* API
|
||||
*/
|
||||
struct avgx_data
|
||||
{
|
||||
double sumx;
|
||||
int64_t cnt;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool avgx_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct avgx_data* data;
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message,"avgx() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct avgx_data*) malloc(sizeof(struct avgx_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumx = 0;
|
||||
data->cnt = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avgx_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
avgx_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
data->sumx = 0;
|
||||
data->cnt = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
avgx_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// TODO test for NULL in x and y
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
double xval = cvtArgToDouble(args->arg_type[1], args->args[0]);
|
||||
++data->cnt;
|
||||
data->sumx += xval;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long avgx(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
return data->sumx / data->cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* distinct_count connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool distinct_count_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message,"distinct_count() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void distinct_count_deinit(UDF_INIT* initid)
|
||||
{
|
||||
void median_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void median_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void median_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
// data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long median(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// return data->sumsq;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* avg_mode connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool avg_mode_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "avg_mode() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
distinct_count_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
/*
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avg_mode_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avg_mode_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avg_mode_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
// data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long avg_mode(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// return data->sumsq;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* avgx connector stub. Exactly the same functionality as the
|
||||
* built in avg() function. Use to test the performance of the
|
||||
* API
|
||||
*/
|
||||
struct avgx_data
|
||||
{
|
||||
double sumx;
|
||||
int64_t cnt;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool avgx_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct avgx_data* data;
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "avgx() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
distinct_count_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
if (!(data = (struct avgx_data*)malloc(sizeof(struct avgx_data))))
|
||||
{
|
||||
strmov(message, "Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumx = 0;
|
||||
data->cnt = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avgx_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avgx_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
data->sumx = 0;
|
||||
data->cnt = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void avgx_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message __attribute__((unused)))
|
||||
{
|
||||
// TODO test for NULL in x and y
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
double xval = cvtArgToDouble(args->arg_type[1], args->args[0]);
|
||||
++data->cnt;
|
||||
data->sumx += xval;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long avgx(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
struct avgx_data* data = (struct avgx_data*)initid->ptr;
|
||||
return data->sumx / data->cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* distinct_count connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool distinct_count_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message, "distinct_count() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long distinct_count(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void distinct_count_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void distinct_count_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void distinct_count_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long distinct_count(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null,
|
||||
char* error __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// vim:ts=4 sw=4:
|
||||
|
||||
|
Reference in New Issue
Block a user