userFunction(name,
signature,
doc,
returntype=' double precision ' ,
unit='
' ,
ucd='
' )
| source code
|
a decorator adding some metadata to python functions to make
them suitable as ADQL user defined functions.
name is the name the function will be visible under in ADQL; signature is a
signature not including the name of the form '(parName1 type1, parName1
type2) -> resulttype'; doc is preformatted ASCII documentation. The
indentation of the second line will be removed from all lines.
returntype is the SQL return type, which defaults to double
precision. While ADQL 2.0 appears to say that UDFs must be
numeric, in practice nobody cares; so, return whatever you see fit.
unit and ucd are optional for when you actually have a good guess what's
coming back from your ufunc. They can also be callable; in that
case, they'll be passed the (annotated) arguments, and whatever
they return will be the unit/ucd.
The python function receives an array of arguments; this will in
general be ADQL expression trees. It must return either
* a string that will go literally into the eventual serialised SQL
string (so take care to quote; in general, you will use
nodes.flatten(arg) to flatten individual args);
* or they may return None, in which case the expression tree
remains unchanged. This is for when the actual implementation is
in the database.
* or they may return a nodes.ADQLNode instance, which then replaces
the user defined function in the parse tree and will be annotated
as usual.
If you receive bad arguments or something else goes awry, raise
a UfuncError.
|