Fw:how are user defined function arguments passed ?

integrity 357416268 at qq.com
Wed Jul 10 09:59:55 CEST 2013


Could anyone explain this question to me, please?


I am still wondering on it....


Thanks!


Meng
------------------ Original ------------------
From:  "integrity"<357416268 at qq.com>;
Date:  Fri, Jul 5, 2013 03:42 PM
To:  "users-list"<users-list at monetdb.org>; 

Subject:  how are user defined function arguments passed ?



Hi everyone,


In http://www.monetdb.org/Documentation/Cookbooks/SQLrecipes/UserDefinedFunction
In thesection about how to extend SQL with a simple scalar function to reverse a string


step 3. Extension starts with a definitin of the MAL signatures. See the example given, or browse through the files in monetdb5/modules/mal/*.mal to get a glimpse on how to write them. The MonetDB kernel documentation provides more details.  The file contains the MAL snippet:
command reverse(ra1:str):str
address UDFreverse
comment "Reverse a string";

step 4. The signature says that it expects a command body implementation under the name UDFreverse, shown below. The C-signature is a direct mapping, where arguments are passed by reference and the return value(s)  references are the first in the arguments list. The body should return a (malloced) string to denote an exception being raised or MAL_SUCCEED upon access.
#include "udf.h"

static str
reverse(const char *src)
{
    size_t len;
    str ret, new;

    /* The scalar function returns the new space */
    len = strlen(src);
    ret = new = GDKmalloc(len + 1);
    if (new == NULL)
        return NULL;
    new[len] = 0;
    while (len > 0)
        *new++ = src[--len];
    return ret;
}

str
UDFreverse(str *ret, str *src)
{
    if (*src == 0 || strcmp(*src, str_nil) == 0)
        *ret = GDKstrdup(str_nil);
    else
        *ret = reverse(*src);
    return MAL_SUCCEED;
}




I don't know why the argument name of  "command reverse(ra1:str):str" different from function definition UDFreverse(str *ret, str *src)?

how does ret come from? is it according to the naming rules that the first argument is the result, must it be a string type?

Thanks!

Meng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.monetdb.org/pipermail/users-list/attachments/20130710/39712dcd/attachment.html>


More information about the users-list mailing list