Question

I am trying to evaluate the performance of MonetDB for an analytical workload that contains a large amount of floating point calculations which are used in an aggregation.

I am trying to implement a C based UDF in MonetDB to achieve this and am running into an error. I am unsure of how to implement the function correctly based on my required signature which is

double f(double,double);

Firstly, I am using MonetDB-11.15.17 built from source on Ubuntu 13.04.

I have added to the following files in the ./sql/backends/monet5/UDF directory as shown:

udf.c:

str UDFtest(flt *ret,flt *_p1,flt *_p2)
{
    *ret = *_p1+*_p2;
    return MAL_SUCCEED;
}

udf.h:

udf_export str UDFtest(flt *,flt*,flt*);

udf.mal:

module udf;
command calc_test(one:flt,two:flt):flt
address UDFtest
comment "udf floating point test";

80_udf.sql:

create function calc_test(one double,two double)
returns double external name udf.calc_test;

I then ran , bootstrap; make; sudo make install; and typed the following at the mclient prompt:

declare f1 float;
declare f2 float;
set f1=0.1;
set f2=0.2;
select calc_test(f1,f2);

This results in the following error:

TypeException:user.s1_1[6]:'udf.calc_test' undefined in: _9:any := udf.calc_test(_5:dbl, _8:dbl)
program contains errors

I've tried to piece together what I can from the documentation and source but am now stuck. Where have I gone wrong in this process?

Was it helpful?

Solution

I solved this. I mixed up my data types by presuming that the typedef flt was equivalent to double as float === double in SQL.

The flt type in C is equivalent to the "real" SQL type. It should look like this:

udf.c

str UDFtest(dbl *ret,dbl *_p1,dbl *_p2)
{
    *ret = *_p1+*_p2;
    return MAL_SUCCEED;
}

udf.h

udf_export str UDFtest(dbl *,dbl*,dbl*);

udf.mal

module udf;
command calc_test(one:dbl,two:dbl):dbl
address UDFtest
comment "udf floating point test";

80_udf.sql

create function calc_test(one double,two double)
returns double external name udf.calc_test;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top