Fw:how are user defined function arguments passed ?
lsidir at gmail.com
Wed Jul 10 10:13:33 CEST 2013
The str *ret is you return value as described in the MAL signature
the ra1 is the name of a str variable in MAL, which is mapped to the
str *src variable of the UDF. Naming here plays no role, just the
types and the order of definition. Similarly, the :str end of the mal
signature reverse(ra1:str):str means that it returns a str type, which
in turn is mapped to the str *ret variable of the UDF signature.
Naming plays no role again, just that the first variable of the
signature in the udf is the return variable. Ofcourse it does not need
to be always a str, it depends on the definition of the mal signature.
On Wed, Jul 10, 2013 at 9:59 AM, integrity <357416268 at qq.com> wrote:
> Could anyone explain this question to me, please?
> I am still wondering on it....
> ------------------ 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 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;
> UDFreverse(str *ret, str *src)
> if (*src == 0 || strcmp(*src, str_nil) == 0)
> *ret = GDKstrdup(str_nil);
> *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?
> users-list mailing list
> users-list at monetdb.org
More information about the users-list