Sybase CEP software requires the description of the UDF to be in an XML file, which is put in the plugins directory of both the server and Studio.
The file name should have the extension ".udf" so the server and Studio can find the file. For each UDF, the file lists:
The name of the function.
The name of the library file that contains the function.
The data types of each of the parameters to the function.
The data type of the return value of the function.
The Functions element of the XML file may describe an arbitrary number of functions. This allows for the grouping of related functions and/or library modules, and there may be an arbitrary number of function modules in a library. In the XML file, each function should be described inside its own "<Function> ... </Function>" element. For example:
<Functions> <Function Name="MyFunc" InitFunctionName="MyInit" ShutdownFunctionName="MyShutdown" Library="c8_udf_lib" CclName="MyFunc" IsAggregator="false"> ... <Input> <Parameter Name="var1" Type="C8Float"/> ... </Input> <Output> <Parameter Type="C8Long"/> </Output> </Function> <Function Name="bar" ...> ... </Function> </Functions>
The initial function element is always named "Function" and has six attributes:
The Name attribute provides the name of the function that will be called from the user-designated Library. This name is case-sensitive.
The optional InitFunctionName attribute identifies a function that will be called on initialization.
The optional ShutdownFunctionName attribute identifies a function that will be called on shutdown.
The Library attribute is the name of the .dll containing the function. For UNIX-like operating systems, this will be a .so library, and should not be prefaced with "lib". Note that the extension .dll or .so is NOT included as part of the library name in the xml file. You may use the same XML file for both UNIX-like operating systems and Microsoft Windows environments without changing the library name.
The CclName is the name that will be used in CCL queries (for example, "select FOO() ... from ..."). The CclName is case insensitive. The CCL name is usually the same as the function name, but this is not required.
The IsAggregator attribute should be true for aggregate functions and false for other functions.
The Input element inside each Function element must contain a list of all input parameters. Only one Input element is permitted per function.
Each Parameter element inside the Input element includes two attributes: the parameter "Name" and "Type". The Name is arbitrary, but for clarity it should reflect the parameter usage. The Name attribute is used for error reporting if there is a type mismatch for any parameters at runtime.
The "Type" parameter specifies the data type of the input parameter. If you are writing your UDF in C/C++, the types available map directly into C base types via these typedefs:
typedef int C8Bool; /* CCL "BOOLEAN" type */ typedef int32 C8Int; /* CCL "INTEGER" type */ typedef double C8Float; /* CCL "FLOAT" type. Note that * CCL FLOAT is NOT C "float"; * it's C "double". */ typedef char* C8CharPtr; /* CCL "STRING" type */ typedef char C8Char; typedef int64 C8Long; /* CCL "LONG" type */ typedef int64 C8Timestamp; /* CCL "TIMESTAMP" type */ typedef int64 C8Interval; /* CCL "INTERVAL type */ typedef void *C8BlobPtr; /* CCL "BLOB" type */ typedef void C8Blob; /* CCL "BLOB" type */
For example, if the first input parameter has a CCL data type of FLOAT, then you would specify C8Float in the .udf file. Only the above typedef names are supported in the "Type" attribute. Throughout the C code for your UDF, you should use the typedef'd names (for example, "C8Float") rather than the underlying C types (for example, "double"). The Sybase CEP software uses strong type checking to help ensure correctness of data at runtime.
The "output" element of the sample XML file contains only a single "Parameter" field and describes the function output in the same manner as input parameters. The "Name" attribute is optional. It is not currently possible to return more than a single value from a user defined function.