MEP functions can be used to perform arbitrary things with your data (e.g., mathematic operations, string operations, etc.). These functions can be used in different operators like Map, Select, or Join. To implement a MEP function, ones has to extend the AbstractFunction class. To implement your own MEP function you have to implement 4 methods, namely the getSymbol that returns the unique name of the function, the getArity, getAcceptedTypes, and getReturnType that describe the parameters and result of you function, and the getValue method which includes the processing of your function.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public class MyFunction extends AbstractFunction<Double> { public static final SDFDatatype[][] accTypes = new SDFDatatype[][] {{ SDFDatatype.DOUBLE }, { SDFDatatype.DOUBLE }}; @Override public String getSymbol() { return "myFunction"; } @Override public Double getValue() { double a = (double) this.getInputValue(0); double b = this.getNumericalInputValue(1); return a +b; } @Override public SDFDatatype getReturnType() { return SDFDatatype.DOUBLE; } @Override public int getArity() { return 2; } @Override public SDFDatatype[] getAcceptedTypes(int argPos) { if (argPos < 0) { throw new IllegalArgumentException( "negative argument index not allowed"); } if (argPos > this.getArity()) { throw new IllegalArgumentException(this.getSymbol() + " has only " + this.getArity() + " arguments: Two double values."); } return accTypes[argPos]; } } |
...