Object -
streams
:
Window
The Window
abstract objects is the base object for implementing windows in Ballerina streams. The process
function contains the logic of processing events when events are received. getCandidateEvents
function is used
inside the Select
object to return the events in the window to perform joining.
The window names in the window objects cannot be used in the queries. Always a function which returns the specific
window has to be used in streaing query.
E.g. If LengthWindow
has to be used in a streaming query, the function 'streams:length' has to be used for
streaming query without the module identifier streams
. An example is shown below.
from inputStream window length
(5)
select inputStream.name, inputStream.age, sum(inputStream.age) as sumAge, count() as count
group by inputStream.name => (TeacherOutput [] teachers) {
foreach var t in teachers {
outputStream.publish(t);
}
}
Methods
The process
function process the incoming events to the events and update the current state of the window.
Parameters
- streamEvents StreamEvent?[]
-
The array of stream events to be processed.
getCandidateEvents
(StreamEvent originEvent, function(map, map) returns (boolean)
conditionFunc, boolean isLHSTrigger)
Returns the events(State) which match with the where condition in the join clause for a given event.
Parameters
- originEvent StreamEvent
-
The event against which the state or the events being held by the window is matched.
-
conditionFunc
function(map, map) returns (boolean)
-
The function pointer to the lambda function which contain the condition logic in where clause.
- isLHSTrigger boolean (default true)
-
Specify if the join is triggered when the lhs stream received the events, if so it should be true. Most of the time it is true. In rare cases, where the join is triggered when the rhs stream receives events this should be false.
-
Return Type
([StreamEvent?, StreamEvent?][]) Returns an array of 2 element tuples of events. A tuple contains the matching events one from lhs stream and one from rhs stream.