[MDEV-27527] UDF (user defined function) plugin SDK model(dll) not working properly(for aggregated function) Created: 2022-01-17  Updated: 2022-02-07  Resolved: 2022-02-07

Status: Closed
Project: MariaDB Server
Component/s: Documentation
Affects Version/s: 10.6.5
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Mitchell Lee Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows11 64bit, visual studio 2022, MariaDB 10.6\bin\mysql.exe Ver 15.1 Distrib 10.6.5-MariaDB, for Win64 (AMD64), source revision 109fc67d4da46d52d2a96528eaea3b0ef6275692



 Description   

For the UDF aggregate model that calling 'x_init > x_clear > x_add > xxx > x_deinit' as the guide said,
but actually not calls 'x_clear > x_add' both on windows platform
only rest of functions(x_init > xxx > x_deinit) are called. but above two. So that canNOT implement aggregated plugin.
How to fix it?
(sample code at https://github.com/mysqludf/lib_mysqludf_ta/blob/master/src/ta_tr_win.c)

reference doc : https://mariadb.com/kb/en/creating-user-defined-functions/



 Comments   
Comment by Sergei Golubchik [ 2022-01-17 ]

are you installing it with CREATE AGGREGATE FUNCTION ?
please, show the complete SQL script that together with the sample code reproduces the bug.

generally aggregate UDF functions work on Windows, there's an aggregate UDF in the udf_example.c and it's tested in our test suite which is run regularly in our CI, also on Windows (e.g. here)

Comment by Mitchell Lee [ 2022-01-17 ]

CREATE FUNCTION ta_ema RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_max RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_min RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_previous RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_rsi RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_sma RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_stddevp RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_sum RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_tr RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_sma_win RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_rsi_win RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_atr_win RETURNS REAL SONAME 'lib_mysqludf_ta.dll';
CREATE FUNCTION ta_tr_win RETURNS REAL SONAME 'lib_mysqludf_ta.dll';

DROP FUNCTION IF EXISTS ta_ema;
DROP FUNCTION IF EXISTS ta_max;
DROP FUNCTION IF EXISTS ta_min;
DROP FUNCTION IF EXISTS ta_previous;
DROP FUNCTION IF EXISTS ta_rsi;
DROP FUNCTION IF EXISTS ta_sma;
DROP FUNCTION IF EXISTS ta_stddevp;
DROP FUNCTION IF EXISTS ta_sum;
DROP FUNCTION IF EXISTS ta_tr;
DROP FUNCTION IF EXISTS ta_sma_win;
DROP FUNCTION IF EXISTS ta_rsi_win;
DROP FUNCTION IF EXISTS ta_atr_win;
DROP FUNCTION IF EXISTS ta_tr_win;

possibly, the MariaDB not fully compatible with standard dll build/entry point.
please provide windows compilable source code with visual studio. not your half made lansi based code.

Comment by Anel Husakovic [ 2022-01-17 ]

Can you please paste result of mysql.func table?

Comment by Mitchell Lee [ 2022-01-17 ]

"name" "ret" "dl" "type"
"ta_ema" "1" "lib_mysqludf_ta.dll" "function"
"ta_max" "1" "lib_mysqludf_ta.dll" "function"
"ta_min" "1" "lib_mysqludf_ta.dll" "function"
"ta_previous" "1" "lib_mysqludf_ta.dll" "function"
"ta_rsi" "1" "lib_mysqludf_ta.dll" "function"
"ta_sma" "1" "lib_mysqludf_ta.dll" "function"
"ta_stddevp" "1" "lib_mysqludf_ta.dll" "function"
"ta_sum" "1" "lib_mysqludf_ta.dll" "function"
"ta_tr" "1" "lib_mysqludf_ta.dll" "function"
"ta_sma_win" "1" "lib_mysqludf_ta.dll" "function"
"ta_rsi_win" "1" "lib_mysqludf_ta.dll" "function"
"ta_atr_win" "1" "lib_mysqludf_ta.dll" "function"
"ta_tr_win" "1" "lib_mysqludf_ta.dll" "function"

Comment by Mitchell Lee [ 2022-01-17 ]

does not '__declspec(dllexport) void ta_tr_win_clear(UDF_INIT *initid, char *is_null, char *error)' this prototype of dll entry not working with the server?

    • again, the normal simple series udf working great.
Comment by Sergei Golubchik [ 2022-01-17 ]

npdmailing@gmail.com, that's what I said in my first comment, you must use

CREATE AGGREGATE FUNCTION ta_tr_win RETURNS REAL SONAME 'lib_mysqludf_ta.dll';

note the keyword AGGREGATE

Comment by Mitchell Lee [ 2022-01-17 ]

Shame me. Thanks.
issue resolved.
by the way,
where the location that keyword mentioned that mariaDb documents?

Comment by Anel Husakovic [ 2022-01-17 ]

In CREATE FUNCTION statement

Comment by Mitchell Lee [ 2022-01-17 ]

Holy....that isn't fair
cannot imagin/map that the normal function's option can be UDF things to applicate.
You guy must improve the udf section for aggregate keyword
to prevent spending whole daytime with pain without gain.

thanks.

cheers.

Generated at Thu Feb 08 09:53:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.