Integrate Software AG Products Using Digital Event Services : MashZone NextGen Help : Appendix : Legacy Presto components : MashZone NextGen Analytics : RAQL Queries : Create and Add User-Defined Functions for RAQL Queries : Write Plain Functions for RAQL
Write Plain Functions for RAQL
Effective in version 3.8, plain functions implement the UserDefinedFunctionAdapter interface in the de.rtm.push.adapters package of theMashZone NextGenRAQL User Defined Function API. If functions need to support multiple signatures, you can also implement the UserDefinedFunctionAdapterFactory interface.
Note:  
These interfaces are not backwards compatible with the UDF API from MashZone NextGen 3.7 or earlier.
You can implement plain functions more simply as Java classes and let RAQL automatically derive the methods required by the interface. Thus at a minimum plain functions must:
*Import the com.jackbe.jbp.raql.udx.loader.RaqlFunc annotation interface.
*Include annotations to identify which methods are RAQL functions.
*Be implemented as public static class methods that return primitive types.
This example contains two plain functions, replace and capitalize:
package com.jackbe.jbp.raql.samplelib.annotated.udf;

/*
* Sample class in a library of plain user-defined functions for RAQL
*/

import com.jackbe.jbp.raql.udx.loader.RaqlFunc;
public class StringFunctions {

@RaqlFunc
public static String replace(String val, String oldStr, String newStr) {
if (val == null || oldStr == null || newStr == null)
return null;

return val.replace(oldStr, newStr);
}

@RaqlFunc(name="capitalize")
public static String upper(String val) {
return val == null ? null : val.toUpperCase();
}

}
The @RaqlFunc annotation identifies which methods should be associated with RAQL functions. If you omit the name parameter, the name of the method becomes the name of the RAQL function within this UDF library. Use (name="alias") to use a different name for the function from the method name.
Also, plain user-defined functions may be annotated using the @RaqlFunc annotation. If within one single class multiple static methods with distinct signatures are annotated with the @RaqlFunc annotation and are given the same name, they will all be registered under that name and the engine will choose the most suitable signature for a particular call.
Tip:  
Using annotations to configure the methods for user-define functions in RAQL is a best practice. However, you can skip the annotations in your Java classes and instead provide configuration that maps methods to user-defined functions in the lib.json configuration file for your UDF libraries. See External UDF Library Deployment Folder for more information.
With plan functions, you can annotate several static methods with different signatures in a single class using the same function name. All of the methods are registered under that single function name. At runtime, the method with the appropriate signature is used.
Copyright © 2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback