Is there a manual for making UDF?


#1

I would like to make an UDF to calculate MAX(attribute1, attribute2)/attribute3 in an array.
I was trying to look for a manual of UDF but I couldn’t.

How can I make the UDF for above calculation?


#2

Well …

  1. There are a number of example UDFs in the examples directory. But there is a small problem. The existing UDF dispatch mechanism is very strongly typed, so there’s no way to write a generic MAX ( type, type ) -> type UDF.

  2. I think a function named “MAX” will collide pretty badly with the aggregate. aggregate ( Array, MAX ( type ) ) is a query form we support, and I suspect the parser might get confused, especially in AQL, where you can say, SELECT MAX ( attribute ) FROM Array;. We don’t do it now, but we have plans to support aggregates that can take more than one argument: SELECT CORR ( attr1, attr2 ) FROM Array;. I would avoid “MAX()” as a name in general.

  3. What about “iif()”? Ie apply ( Array, result, ( iif ( attr1 > attr2, attr1, attr2 ) / attr3 ) )


#3

Thank you very much.

I didn’t know that iif can solve my problem easily.