"To store information, the UDF calls getUDFProperties. This returns a Properties object which the UDF can record the information in or read the information from. To avoid name space conflicts UDFs are required to provide a signature when obtaining a Properties object. This can be done in two ways. The UDF can provide its Class object (via this.getClass()). In this case, every instantiation of the UDF will be given the same Properties object. The UDF can also provide its Class plus an array of Strings. The UDF can pass its constructor arguments, or some other identifying strings. This allows each instantiation of the UDF to have a different properties object thus avoiding name space collisions between instantiations of the UDF."
For example, if you need the object key
to persist and remain the same between different calls to the UDF, you can do the following:
UDFContext context = UDFContext.getUDFContext();
Properties properties = context.getUDFProperties(this.getClass());
if (properties.containsKey("key")) {
key = properties.get("key");
} else {
key = new generateKey();
properties.put("key", key);
}
You can also make this key
a class variable to the EvalFunc implementation class.