I'm having problems to load udf_median.so.
Here the steps i tried:
Compiling against MySQL 4.1.3-beta-max-log with:
gcc -I /usr/local/mysql/include -I /usr/local/include -o udf_median.o
-c udf_median.cc
Create UDF with:
ld -shared /usr/lib/udf_median.so udf_median.o
Loading it:
mysql> CREATE AGGREGATE FUNCTION median RETURNS REAL
SONAME 'udf_median.so';
ERROR 1126 (HY000): Can't open shared library 'udf_median.so'
(errno: 22 /usr/lib/udf_median.so: undefined symbol: _Znwj)
Do you have any idea what could be wrong?
Logged In: YES
user_id=1079727
I did not try to link the UDF against 4.1.3-beta, but I think there'll be
problems when linking it to 4.1.1 or later. Seems that MySQL AB has
changed the API for aggregate functions a litte.
So, if you want to link the udf against 4.1.1 or later, it seems the
[udfname]_clear() function has to be implemented in the udf
additionally. This is yet not the case in my udf as I don't have 4.1.1 or
later and can't test it.
The MySQL manual says (chapter "extending MySQL"):
"...The following function is only required by MySQL 4.1.1 and above:
char *xxx_clear(UDF_INIT *initid, char *is_null, char *error);
This function is called when MySQL needs to reset the summary
results. This will be called at the beginning for each new group but
can also be called to reset the values for a query where there was
no matching rows. is_null will be set to point to CHAR(0) before
calling xxx_clear()..."
As I said before, I am currently not able to test this with 4.1.1 or
later and so I can't supply a path. But the src folder of MySQL
distributions always contain a file named "udf_example.cc" which
shows you what to do. It should implement an aggregate function
using the xxx_clear() function too. So basically I think it will be
about kicking out the xxx_reset() function from the udf and
implementing the xxx_clear() thing.
Please let me know if this works!
Best regards
Jansen
Logged In: NO
I added a median_clear() funtion to udf_median.cc and finally I was able to
compile it like this:
gcc -shared -lstdc++ -I /usr/include -I /usr/local/include -I /usr/local/
mysql/include/mysql -o udf_median.so udf_median.cc
Loading and using of median() im MySQL 4.1.3 works now.
Here the diff udf_median.cc.orig udf_median.cc:
49a50
> void median_clear( UDF_INIT* initid, char* is_null, char *error );
154a156,176
> /* This is needed to get things to work in MySQL 4.1.1 and above */
>
> void
> median_clear(UDF_INIT* initid, char* is_null, char* message)
> {
> median_data *buffer = (median_data*)initid->ptr;
> buffer->count = 0;
> buffer->abscount=0;
> buffer->pages = 1;
> *is_null = 0;
>
> if (buffer->values != NULL)
> {
> free(buffer->values);
> buffer->values=NULL;
> }
>
> buffer->values=(double *) malloc(BUFFERSIZE*sizeof(double));
> }
>
>
This is just a hack since I'm not a C-programmer!
You can contact me at bernhard (at) fuersten (dot) info.
Bernhard
Logged In: YES
user_id=390604
I noticed the following compiler warning (gcc 3.2):
/usr/include/asm/atomic.h:40:2: warning: #warning Using
kernel header in userland program. BAD!
Then I had the same problem with loading the object.
ERROR 1126: Can't open shared library 'udf_correlation.so'
(errno: 22 /usr/lib/udf_correlation.so: undefined symbol:
_Znwj)
I compiled the code on another box (gcc 2.95), did not get
the warning and could load the object on this box. Hope this
helps.
Logged In: YES
user_id=390604
This was on MySQL 4.0.16 max, though.
Logged In: YES
user_id=1075753
Originator: NO
Hello, I've found that the code will not work with newer versions of mysql. I will submit updates that I have made.
Logged In: YES
user_id=1079727
Originator: NO
The UDFs are known to not work with MySQL 4.1.* as MySQL changed the API for UDFs between 4.0 and 4.1.
The website states that:
"Important: It seems that MySQL AB changed the UDF API in MySQL version 4.1.1. The UDFs provided here should work with the 4.0-branch of MySQL (at least on my box they do). I am not sure if they will still work with the 4.1.x-branches. Update: it seems that the non-aggregate functions will still work in MySQL 4.1.1+, but the aggregate functions need some additional hook-in to work (the xxx_clear procedure). I will fix this when I have some spare time."
I didn't do anything with the UDFs since 2004 so I didn't change the code be to 4.1-complying.
Best regards
Jan