Configure, Compile, Deploy and Test User-Defined Functions

To compile and deploy user-defined functions

  1. Add a folder with the name of your library under the default external UDF library deployment folder <MashZone NextGen installation>/raql-udfs.

    Note: The folder for UDF library deployment is set in the system property -Dpresto.raql.udf.libsDir. This may be a different folder in clustered environments with a shared external configuration folder for MashZone NextGen.

    This new folder is the root deployment folder for your library. For example:
    /SoftwareAG/MashZoneNG/raql-udfs/MyOrgRaqlLib

  2. Complete configuration that identifies the Java packages for this library in a lib.json file. This file must reside in the root deployment folder for your library, created in the previous step.

    Note: You may also want to place a copy of this configuration in your library development folder to track in your source control system.

    This file uses the JSON format to identify packages that contain user-defined functions for a library. For example:

    {

    "exportedFuncs" : {

    "annotatedPackages" : [

    "com.jackbe.jbp.raql.samplelib.annotated.udf",

    "com.jackbe.jbp.raql.samplelib.annotated.uda",

    "com.jackbe.jbp.raql.samplelib.annotated.udw"

    ],

    "classes" : [

    {

    "name" : "com.jackbe.jbp.raql.samplelib.configured

    .MoreStringFunctions",

    "funcs" : [

    { "name" : "low", "method" : "lower" },

    { "method" : "hashCode" }

    ]

    },

    {

    "name" : "com.jackbe.jbp.raql.samplelib.configured.

    AverageAggregationFunctionFactory",

    "funcs" : [

    { "name" : "avg" }

    ]

    },

    {

    "name" : "com.jackbe.jbp.raql.samplelib.configured.

    LeadWindowFunction",

    "funcs" : [

    { "name" : "lead" }

    ]

    }

    ]

    }

    }

    This example identifies three packages for this library. The classes property must be present in configuration, but can be an empty array. The RAQL Engine will search each class within the identified packages for function annotations to find the functions to add.
    You can also optionally identify classes, functions and methods in this configuration. See UDF Library Configuration for more information on this method.

  3. Compile your Java class with user-defined functions, being sure to include the jackbe-presto-raql-version.jar and rtm-core-version.jar files and any third-party libraries you used in this class in the classpath.

    For Windows for example:

    %JAVA_HOME%/bin/javac -classpath c:\SoftwareAG\MashZoneNG\apache-tomcat\webapps\mashzone\WEB-INF\lib\jackbe-presto-raql-10.3.jar;c:\SoftwareAG\MashZoneNG\apache-tomcat\webapps\mashzone\WEB-INF\lib\rtm-core-10.3.jar -d classes src\com\MyOrg\raqlUdf\MyReplaceFunc.java

    For Linux, OS/X or UNIX for example:

    javac -classpath /SoftwareAG/MashZoneNG/apache-tomcat/webapps/mashzone/WEB-INF/lib/jackbe-presto-raql-10.3.jar,/SoftwareAG/MashZoneNG/apache-tomcat/webapps/mashzone/WEB-INF/lib/rtm-core-10.3.jar -d classes src/com/MyOrg/raqlUdf/MyStringFuncs.java

  4. This will add the compiled class to the classes folder in your development folder for this library.
  5. Deploy the classes and any third-party libraries for this library to the MashZone NextGen Server. Copy the following folders to the root deployment folder for your library:

    /classes folder and all contents

    /lib folder and all contents

    Important: If you have included either the RAQL or RTM JAR files in your library-name /lib folder, do not copy these JARs to the deployment folder for your library as this causes errors when functions in the library are used.

  6. Restart the MashZone NextGen Server. See Start and Stop the MashZone NextGen Server (page 389 → link to correct chapter) for instructions.
  7. Write RAQL queries that use these new user-defined functions to test them.
    You refer to user-defined functions in the form library-name.function-name([arg,...]) to identify both the library name and the function name.