To prepare a Java function for use in SQL-MapReduce, compile it into a class file (build it on your workstation) and install it in an Aster instance using the ACT client’s \install command. Be sure to also install any other classes that your function depends on, as we will explain below.
The examples directory provided in SQL-MapReduce SDK bundle (ncluster-sqlmr-sdk.zip) contains a Makefile that builds and packages the example functions when you run make.
You must package your SQL-MapReduce functions in one of the following ways:
- as a single .class file for the function,
- as a .jar file containing the function class and other classes, or
- as a .zip file containing the function's .jar file and other (possibly third-party) .jar files.
The name of the file must match the name of the function. For example, a function named foo must be compiled as Foo.class, and you can install the class on its own or as part of foo.jar, or, finally, as part of foo.zip which contains foo.jar with its Foo.class.
The advantage of a .zip-packaged function is that you can include external .jar files unmodified. For example, you might write a .zip-packaged function with the following structure:
In this example, the primary SQL-MapReduce function we care about is "foo," so we package it in an archive called foo.zip, which in turn must containfoo.jar, which in turn must somewhere contain a file Foo.class (path and case is not significant). By using a .zip file, we can contain other classes that our foo function relies on. In this case, the package also contains another class in foo.jar (OtherClass.class) and also another, third-party .jar file (otherjar.jar) with a class that foo relies on, Useful.class.
After you have packaged your functions, install them in your database as shown in Install and Use a Sample Function.