You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

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. 

Remark: The MEP optimizer tries to determine if an expression is a constant and should not be evaluated each time. For this, the getValue method is called. This behaviour can be changed by implementing the method optimizeConstantParameter and returning false.

MEP Function stub
public class MyFunction extends AbstractFunction<Double> {

    public static final SDFDatatype[][] accTypes = new SDFDatatype[][] {{ SDFDatatype.DOUBLE },
                                                                        { SDFDatatype.DOUBLE }};

    public MyFunction() {
        super("myFunction", 2, accTypes, SDFDatatype.DOUBLE, 3, 5);
    }

    @Override
    public Double getValue() {
        double a = (double) this.getInputValue(0);
        double b = this.getNumericalInputValue(1);

        return a  +b;
    }

 }

 

Access to function attributes

To Access the attributes of the function you can use the getInputValue or the getNumericalInputValue methods. While the first method returns an object, the second already cast the input value to a double value. Both methods takes the position index of the attribute as an argument. The name of the function, the total number of attributes, and the datatype of the accepted attributes is set in the constructor. Thus, a MEP  function can handle multiple data types for each attribute.

Access to meta attributes

To access the meta attributes of an incoming streaming object you can use the getMetaAttribute function.

 

Access to additional content

To access the additional content of an incoming streaming object you can use the getAdditionalContents method to access all contents. If you only want to access a special field you can issue the getAdditionalContent(fieldName) method.

 

Support for optimization

To support the optimization of predicates, the time and space complexity can be set in the constructor as the last two parameters. Both values should be in the range between 0-9 depending on their average expected complexity. Depending on the value, the MEP function will be placed differently in the resulting optimized predicate. A rule of thumb should be, MEP functions with logarithmic complexity should have a value between 0-3,  linear complexity a value between 4-6, and exponential complexity a value between 7-9. However, this is just a first draft. The basic idea is to evaluate cheap functions first and avoid expensive functions if possible.

 

  • No labels