Analyzing the subset of data
To determine the highest and lowest trading price, you need to write the logic for determining those values. In addition, you need some local variables to track the highest and lowest price that is processed so far. You can use the Custom operator to accomplish these tasks. As shown, the input stream is only the IBM transactions; there is no output stream for the customized operator.

The SPL code for the Custom operator is shown.
Because the Custom operator does not produce an
output stream, specify "() as Sink
" before the equals
sign.
() as Sink = Custom(IBMTransactions) {
logic
state : {
mutable decimal64 highest = 0.0d, lowest = 999.99d;
}
onTuple IBMTransactions : {
if (price > highest)
highest = price;
if (price < lowest)
lowest = price;
}
onPunct IBMTransactions : {
if (currentPunct() == Sys.FinalMarker) {
printStringLn("highest = " + (rstring)highest);
printStringLn("lowest = " + (rstring)lowest);
}
}
}
In general, the Custom operator performs the statements
that are specified in the state
, onTuple
,
and onPunct
sections of the logic
clause.
Local variables are initialized in the state
section.
Logic to be performed for each tuple from the input stream is specified
in the onTuple
section. Logic to be performed for
punctuation from the input stream is specified in the onPunct
section.
A final punctuation marks the end of a stream.
In this example, the Custom operator performs the following steps:
- Initializes the local variables (
highest
andlowest
). - Receives a tuple from the input stream (
IBMTransactions
). - Checks whether the price is greater than the highest price. If so, sets the new highest price.
- Checks whether the price is less than the lowest price. If so, sets the new lowest price.
- Repeats Steps 2 to 4 until all the tuples from the input stream are processed.
- When the end of the input stream is reached, prints the highest and lowest prices.