8.4. Declaring a User-Defined Function

Documentation

VoltDB Home » Documentation » Guide to Performance and Customization

8.4. Declaring a User-Defined Function

Once the Java class containing the method is loaded, you can declare the function itself. You declare scalar functions using the CREATE FUNCTION statement, specifying the name of the function and the associated Java class path and method name. For example, if you want to call the function associated with the scalar example US2METRIC, the CREATE FUNCTION statement looks like this:

CREATE FUNCTION US2METRIC FROM METHOD myapp.functions.Conversion.us2metric;

You declare aggregate functions using the CREATE AGGREGATE FUNCTION statement, specifying the name of the function and the associated Java class. For example, if you want to call the function associated with the aggregate example LONGEST_WORD, the CREATE AGGREGATE FUNCTION statement looks like this:

CREATE AGGREGATE FUNCTION LONGEST_WORD FROM CLASS myapp.functions.LongestWord;

Note that although the function names are not case sensitive, the class path and method names are and must be specified in the correct mix of upper and lower-case.