Construct and Initialize the Window Analytic Function Class

This example, MySumWindowFunction.java is available in the sample user-defined functions package at <MashZone NextGen installation>/raql-udfs/SampleRaqlLib.

Your window analytic function class imports the RAQL UDF annotation class, com.jackbe.jbp.raql.udx.loader.RaqlFunc, various classes in the MashZone NextGen RAQL User Defined Function API and implements the UserDefinedWindowFunctionAdapter interface:

package com.raql.samples;

import com.jackbe.jbp.raql.udx.loader.RaqlFunc;

import de.rtm.push.adapters.Adapters;

import de.rtm.push.adapters.windowfunctions.UserDefinedWindowFunctionAdapter;

import de.rtm.push.adapters.windowfunctions.WindowFrame;

import de.rtm.push.adapters.windowfunctions.WindowFrameSpecification;

import de.rtm.push.adapters.windowfunctions.WindowFunctionResult;

import de.rtm.util.exception.IncompatibleWindowSpecificationException;

/**

* This window function adapter computes the sum of a window.

*/

@RaqlFunc(name="mySumFunction")

public class WindowSum implements UserDefinedWindowFunctionAdapter

<Double, Double> {

protected final Type[] parameterTypes;

public WindowSum(Type[] parameterTypes) {

this.parameterTypes = parameterTypes;

}

/**

* Returns the type of the result, which is simply always Double.

*/

@Override public Type getReturnType() {

return Type.DOUBLE;

}

/**

* Returns the types of the input parameters.

*/

@Override public Type[] getParameterTypes() {

return parameterTypes;

}

/**

* Creates the initial state of the window sum, which is 0.

*/

@Override

public Double createInitialState() {

return 0d;

}

}

This example overrides the default implementation for createInitialState to reset the sum to zero.