Striim 3.9.4 / 3.9.5 documentation

Developing single-row functions

Single row functions are the simplest types of Striim functions. Start by defining your Java methods inside the custom abstract class you created (see Setting up packages and classes). A best practice is to use techniques that operate on a row of values by iterating on them without storing them, thereby reducing memory requirements and increasing performance.

For example, the following function iterates through a row of values and keeps track of the highest value. Once its loop has reached the termination condition by reaching the end of the row of values, it returns the highest value of that row:

public static double maxSingleRow(double... n) {
  int    i=0;
  double runningmax = n[i];
 
  // Iterate through the row and continually update runningmax to the highest value
  while (++i < n.length)
    if (n[i] > runningmax)
      runningmax = n[i];
 
  return runningmax;
}

Generate your custom JAR and deploy it to your Striim environment (see Setting up packages and classes).

Now you can import your static custom class into TQL and use the newly created custom function:

USE StriimWindows_NS2;
DROP APPLICATION StriimWindows2 CASCADE;
 
IMPORT STATIC com.mycompany.custom.packagename.MyCustomFunctions.*;
 
CREATE APPLICATION StriimWindows2;
 
CREATE OR REPLACE CQ myStream_CQ
INSERT INTO myStream_ST
SELECT
      maxSingleRow( field1, field2, field3, field4 )
FROM
      inputStream_ST;

Here are a few other single row functions you can include by defining the following methods in the same abstract class:

  • minSingleRow iterates through a row of values and keeps track of the lowest value

  • rangeSingleRow calculates the range of values in the row by using the previously created minSingleRow and maxSingleRow functions

  • avgSingleRow iterates through a row of values and calculates the average by maintaining a running total and dividing by the length

	public static double minSingleRow(double... n) {
	    int i = 0;
	    double runningmin = n[i];
	    while (++i < n.length)
	        if (n[i] < runningmin)
	        	runningmin = n[i];
	    return runningmin;
	}	
	
	public static double rangeSingleRow(double... n) {
	    double dRange = maxSingleRow( n ) - minSingleRow( n );
    	return dRange;
	}	

	public static double avgSingleRow(double... n) {
	    int i = 0;
	    double runningsum = 0;
	    while (i < n.length) {
	        runningsum += n[i];
	        i++;
	    }
	    return ( runningsum / i );
	}