esper.codehaus.org and espertech.comDocumentation
This section specifies the output of a subset of EPL continuous queries, for two purposes: First, to help application developers understand streaming engine output in response to incoming events and in response to time passing. Second, to document and standardize output for EPL queries in a testable and trackable fashion.
The section focuses on a subset of features, namely the time window, aggregation, grouping, and output rate limiting. The section does not currently provide examples for many of the other language features, thus there is no example for other data windows (the time window is used here), joins, sub-selects or named windows etc.
Rather then just describe syntax and output, this section provides detailed examples for each of the types of queries presented. The input for each type of query is always the same set of events, and the same timing. Each event has three properties: symbol, volume and price. The property types are string, long and double, respectively.
The chapters are organized by the type of query: The presence or absence of aggregation functions, as well as the presence or absence of a group by
clause change statement output as
described in Section 3.7.2, “Output for Aggregation and Group-By”.
You will notice that some queries utilize the order by
clause for sorting output. The reason is that when multiple output rows are produced at once, the output can be easier to read if it is sorted.
With output rate limiting, the engine invokes your listener even if there are no results to indicate when the output condition has been reached. Such is indicated as (empty result)
in the output result columns.
The output columns show both insert and remove stream events. Insert stream events are delivered as an array of EventBean
instances to listeners in the newData
parameter, while remove stream events are delivered to the oldData
parameter of listeners. Delivery to observers follows similar rules.
For the purpose of illustration and documentation, the example data set demonstrates input and remove streams based on a time window of a 5.5 second interval. The statement utilizing the time window could look as follows:
select symbol, volume, price from MarketData.win:time(5.5 sec)
We have picked a time window to demonstrate the output for events entering and leaving a data window with an expiration policy. The time window provides a simple expiration policy based on time: if an event resides in the time window more then 5.5 seconds, the engine expires the event from the time window.
The input events and their timing are below. The table should be read, starting from top, as "The time starts at 0.2 seconds. Event E1 arrives at 0.2 seconds with properties [S1, 100, 25]. At 0.8 second event E2 arrives with properties [S2, 5000, 9.0]" and so on.
Input ----------------------------------------------- Time Symbol Volume Price 0.2 S1 100 25.0 Event E1 arrives 0.8 S2 5000 9.0 Event E2 arrives 1.0 1.2 1.5 S1 150 24.0 Event E3 arrives S3 10000 1.0 Event E4 arrives 2.0 2.1 S1 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 3.5 S3 11000 2.0 Event E6 arrives 4.0 4.2 4.3 S1 150 22.0 Event E7 arrives 4.9 S3 11500 3.0 Event E8 arrives 5.0 5.2 5.7 Event E1 leaves the time window 5.9 S3 10500 1.0 Event E9 arrives 6.0 6.2 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2
The event data set assumes a time window of 5.5 seconds. Thus at time 5.7 seconds the first arriving event (E1) leaves the time window.
The data set as above shows times between 0.2 seconds and 7.2 seconds. Only a couple of time points have been picked for the table to keep the set of time points constant between statements, and thus make the test data and output easier to understand.
This chapter provides sample output for queries that do not have aggregation functions and do not have a group by
clause.
Without an output
clause, the engine dispatches to listeners as soon as events arrive, or as soon as time passes such that events leave data windows.
The statement for this sample reads:
select irstream symbol, volume, price from MarketData.win:time(5.5 sec)
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 100, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 5000, 9.0] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 150, 24.0] YAH 10000 1.0 Event E4 arrives [YAH, 10000, 1.0] 2.0 2.1 IBM 155 26.0 Event E5 arrives [IBM, 155, 26.0] 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 11000, 2.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 150, 22.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 11500, 3.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 100, 25.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 10500, 1.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 5000, 9.0] 7.0 Event E3 and E4 leave the time window [IBM, 150, 24.0] [YAH, 10000, 1.0] 7.2
With an output
clause, the engine dispatches to listeners when the output condition occurs. Here, the output condition is a 1-second time interval. The engine thus outputs every 1 second, starting from the first event, even if there are no new events or no expiring events to output.
The default (no keyword) and the ALL
keyword result in the same output.
The statement for this sample reads:
select irstream symbol, volume, price from MarketData.win:time(5.5 sec) output every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 11000, 2.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 150, 22.0] [YAH, 11500, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 10500, 1.0] [IBM, 100, 25.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0]
Using the LAST
keyword in the output
clause, the engine dispatches to listeners only the last event of each insert and remove stream.
The statement for this sample reads:
select irstream symbol, volume, price from MarketData.win:time(5.5 sec) output last every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 155, 26.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 11000, 2.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [YAH, 11500, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 10500, 1.0] [IBM, 100, 25.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [YAH, 10000, 1.0]
Using the FIRST
keyword in the output
clause, the engine dispatches to listeners only the first event of each insert or remove stream, and does not output further
events until the output condition is reached.
The statement for this sample reads:
select irstream symbol, volume, price from MarketData.win:time(5.5 sec) output first every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 100, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 150, 24.0] YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 11000, 2.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 150, 22.0] 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 100, 25.0] 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 5000, 9.0] 7.0 Event E3 and E4 leave the time window 7.2
Using the SNAPSHOT
keyword in the output
clause, the engine posts data window contents when the output condition is reached.
The statement for this sample reads:
select irstream symbol, volume, price from MarketData.win:time(5.5 sec) output snapshot every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] 2.5 3.0 3.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] [YAH, 11000, 2.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] [YAH, 11000, 2.0] [IBM, 150, 22.0] [YAH, 11500, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [MSFT, 5000, 9.0] [IBM, 150, 24.0] [YAH, 10000, 1.0] [IBM, 155, 26.0] [YAH, 11000, 2.0] [IBM, 150, 22.0] [YAH, 11500, 3.0] [YAH, 10500, 1.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 155, 26.0] [YAH, 11000, 2.0] [IBM, 150, 22.0] [YAH, 11500, 3.0] [YAH, 10500, 1.0]
This chapter provides sample output for queries that have aggregation functions, and that do not have a group by
clause, and in which all event properties are under aggregation.
The statement for this sample reads:
select irstream sum(price) from MarketData.win:time(5.5 sec)
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [25.0] [null] 0.8 MSFT 5000 9.0 Event E2 arrives [34.0] [25.0] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [58.0] [34.0] YAH 10000 1.0 Event E4 arrives [59.0] [58.0] 2.0 2.1 IBM 155 26.0 Event E5 arrives [85.0] [59.0] 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [87.0] [85.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [109.0] [87.0] 4.9 YAH 11500 3.0 Event E8 arrives [112.0] [109.0] 5.0 5.2 5.7 Event E1 leaves the time window [87.0] [112.0] 5.9 YAH 10500 1.0 Event E9 arrives [88.0] [87.0] 6.0 6.2 6.3 Event E2 leaves the time window [79.0] [88.0] 7.0 Event E3 and E4 leave the time window [54.0] [79.0] 7.2
Output occurs when the output condition is reached after each 1-second time interval. For each event arriving, the new aggregation value is output as part of the insert stream. As part of the remove stream, the prior aggregation value is output. This is useful for getting a delta-change for each event or group. If there is a having
clause, the filter expression applies to each row.
Here also the default (no keyword) and the ALL
keyword result in the same output.
The statement for this sample reads:
select irstream sum(price) from MarketData.win:time(5.5 sec) output every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [25.0] [null] [34.0] [25.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [58.0] [34.0] [59.0] [58.0] [85.0] [59.0] 2.5 3.0 3.2 [85.0] [85.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [87.0] [85.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [109.0] [87.0] [112.0] [109.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [87.0] [112.0] [88.0] [87.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [79.0] [88.0] [54.0] [79.0]
With the LAST
keyword, the insert stream carries one event that holds the last aggregation value, and the remove stream carries the prior aggregation value.
The statement for this sample reads:
select irstream sum(price) from MarketData.win:time(5.5 sec) output last every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [34.0] [null] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [85.0] [34.0] 2.5 3.0 3.2 [85.0] [85.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [87.0] [85.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [112.0] [87.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [88.0] [112.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [54.0] [88.0]
The statement for this sample reads:
select irstream sum(price) from MarketData.win:time(5.5 sec) output first every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [25.0] [null] 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [58.0] [34.0] YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 [85.0] [85.0] 3.5 YAH 11000 2.0 Event E6 arrives [87.0] [85.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [109.0] [87.0] 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 5.7 Event E1 leaves the time window [87.0] [112.0] 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 6.3 Event E2 leaves the time window [79.0] [88.0] 7.0 Event E3 and E4 leave the time window 7.2
The statement for this sample reads:
select irstream sum(price) from MarketData.win:time(5.5 sec) output snapshot every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [34.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [85.0] 2.5 3.0 3.2 [85.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [87.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [112.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [88.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [54.0]
This chapter provides sample output for queries that have aggregation functions, and that do not have a group by
clause, and in which there are event properties that are not under aggregation.
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec)
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 34.0] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 58.0] YAH 10000 1.0 Event E4 arrives [YAH, 59.0] 2.0 2.1 IBM 155 26.0 Event E5 arrives [IBM, 85.0] 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 87.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 109.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 112.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 87.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 88.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 79.0] 7.0 Event E3 and E4 leave the time window [IBM, 54.0] [YAH, 54.0] 7.2
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) output every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 25.0] [MSFT, 34.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 58.0] [YAH, 59.0] [IBM, 85.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 87.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 109.0] [YAH, 112.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 88.0] [IBM, 87.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [MSFT, 79.0] [IBM, 54.0] [YAH, 54.0]
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) output last every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [MSFT, 34.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 85.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 87.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [YAH, 112.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 88.0] [IBM, 87.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [YAH, 54.0]
The statement for this sample reads:
select symbol, sum(price) from MarketData.win:time(5.5 sec) output first every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 58.0] YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 87.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 109.0] 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 87.0] 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 79.0] 7.0 Event E3 and E4 leave the time window 7.2
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) output snapshot every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 34.0] [MSFT, 34.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 85.0] [MSFT, 85.0] [IBM, 85.0] [YAH, 85.0] [IBM, 85.0] 2.5 3.0 3.2 [IBM, 85.0] [MSFT, 85.0] [IBM, 85.0] [YAH, 85.0] [IBM, 85.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 87.0] [MSFT, 87.0] [IBM, 87.0] [YAH, 87.0] [IBM, 87.0] [YAH, 87.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 112.0] [MSFT, 112.0] [IBM, 112.0] [YAH, 112.0] [IBM, 112.0] [YAH, 112.0] [IBM, 112.0] [YAH, 112.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [MSFT, 88.0] [IBM, 88.0] [YAH, 88.0] [IBM, 88.0] [YAH, 88.0] [IBM, 88.0] [YAH, 88.0] [YAH, 88.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 54.0] [YAH, 54.0] [IBM, 54.0] [YAH, 54.0] [YAH, 54.0]
This chapter provides sample output for queries that have aggregation functions, and that have a group by
clause, and in which all event properties are under aggregation or appear in the group by
clause.
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 25.0] [IBM, null] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 9.0] [MSFT, null] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 49.0] [IBM, 25.0] YAH 10000 1.0 Event E4 arrives [YAH, 1.0] [YAH, null] 2.0 2.1 IBM 155 26.0 Event E5 arrives [IBM, 75.0] [IBM, 49.0] 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 3.0] [YAH, 1.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 97.0] [IBM, 75.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 6.0] [YAH, 3.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 72.0] [IBM, 97.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 7.0] [YAH, 6.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, null] [MSFT, 9.0] 7.0 Event E3 and E4 leave the time window [IBM, 48.0] [IBM, 72.0] [YAH, 6.0] [YAH, 7.0] 7.2
The default (no keyword) and the ALL
keyword do not result in the same output. The default generates an output row per input event, while the ALL
keyword
generates a row for all groups.
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol output every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 25.0] [IBM, null] [MSFT, 9.0] [MSFT, null] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 49.0] [IBM, 25.0] [YAH, 1.0] [YAH, null] [IBM, 75.0] [IBM, 49.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 3.0] [YAH, 1.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 97.0] [IBM, 75.0] [YAH, 6.0] [YAH, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [IBM, 72.0] [IBM, 97.0] [YAH, 7.0] [YAH, 6.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [MSFT, null] [MSFT, 9.0] [YAH, 6.0] [YAH, 7.0] [IBM, 48.0] [IBM, 72.0]
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol output all every 1 seconds order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 25.0] [IBM, null] [MSFT, 9.0] [MSFT, null] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 75.0] [IBM, 25.0] [MSFT, 9.0] [MSFT, 9.0] [YAH, 1.0] [YAH, null] 2.5 3.0 3.2 [IBM, 75.0] [IBM, 75.0] [MSFT, 9.0] [MSFT, 9.0] [YAH, 1.0] [YAH, 1.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 75.0] [IBM, 75.0] [MSFT, 9.0] [MSFT, 9.0] [YAH, 3.0] [YAH, 1.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 97.0] [IBM, 75.0] [MSFT, 9.0] [MSFT, 9.0] [YAH, 6.0] [YAH, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [IBM, 72.0] [IBM, 97.0] [MSFT, 9.0] [MSFT, 9.0] [YAH, 7.0] [YAH, 6.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 48.0] [IBM, 72.0] [MSFT, null] [MSFT, 9.0] [YAH, 6.0] [YAH, 7.0]
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol output last every 1 seconds order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 25.0] [IBM, null] [MSFT, 9.0] [MSFT, null] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 75.0] [IBM, 25.0] [YAH, 1.0] [YAH, null] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 3.0] [YAH, 1.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 97.0] [IBM, 75.0] [YAH, 6.0] [YAH, 3.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [IBM, 72.0] [IBM, 97.0] [YAH, 7.0] [YAH, 6.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 48.0] [IBM, 72.0] [MSFT, null] [MSFT, 9.0] [YAH, 6.0] [YAH, 7.0]
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol output first every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 25.0] [IBM, null] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 9.0] [MSFT, null] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 49.0] [IBM, 25.0] YAH 10000 1.0 Event E4 arrives [YAH, 1.0] [YAH, null] 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 3.0] [YAH, 1.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 97.0] [IBM, 75.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 6.0] [YAH, 3.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 72.0] [IBM, 97.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 7.0] [YAH, 6.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, null] [MSFT, 9.0] 7.0 Event E3 and E4 leave the time window [IBM, 48.0] [IBM, 72.0] [YAH, 6.0] [YAH, 7.0] 7.2
The statement for this sample reads:
select irstream symbol, sum(price) from MarketData.win:time(5.5 sec) group by symbol output snapshot every 1 seconds order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 25.0] [MSFT, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 75.0] [MSFT, 9.0] [YAH, 1.0] 2.5 3.0 3.2 [IBM, 75.0] [MSFT, 9.0] [YAH, 1.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 75.0] [MSFT, 9.0] [YAH, 3.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 97.0] [MSFT, 9.0] [YAH, 6.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [IBM, 72.0] [MSFT, 9.0] [YAH, 7.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 48.0] [YAH, 6.0]
This chapter provides sample output for queries that have aggregation functions, and that have a group by
clause, and in which some event properties are not under aggregation.
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 100, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 5000, 9.0] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 150, 49.0] YAH 10000 1.0 Event E4 arrives [YAH, 10000, 1.0] 2.0 2.1 IBM 155 26.0 Event E5 arrives [IBM, 155, 75.0] 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 11000, 3.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 150, 97.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 11500, 6.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 100, 72.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 10500, 7.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 5000, null] 7.0 Event E3 and E4 leave the time window [IBM, 150, 48.0] [YAH, 10000, 6.0] 7.2
The default (no keyword) and the ALL
keyword do not result in the same output. The default generates an output row per input event, while the ALL
keyword
generates a row for all groups based on the last new event for each group.
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol output every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 150, 49.0] [YAH, 10000, 1.0] [IBM, 155, 75.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 11000, 3.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 150, 97.0] [YAH, 11500, 6.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 10500, 7.0] [IBM, 100, 72.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [MSFT, 5000, null] [IBM, 150, 48.0] [YAH, 10000, 6.0]
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol output all every 1 seconds order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 150, 49.0] [IBM, 155, 75.0] [MSFT, 5000, 9.0] [YAH, 10000, 1.0] 2.5 3.0 3.2 [IBM, 155, 75.0] [MSFT, 5000, 9.0] [YAH, 10000, 1.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 155, 75.0] [MSFT, 5000, 9.0] [YAH, 11000, 3.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 150, 97.0] [MSFT, 5000, 9.0] [YAH, 11500, 6.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [IBM, 150, 72.0] [IBM, 100, 72.0] [MSFT, 5000, 9.0] [YAH, 10500, 7.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 150, 48.0] [IBM, 150, 48.0] [MSFT, 5000, null] [MSFT, 5000, null] [YAH, 10500, 6.0] [YAH, 10000, 6.0]
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol output last every 1 seconds order by symbol
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 155, 75.0] [YAH, 10000, 1.0] 2.5 3.0 3.2 (empty result) (empty result) 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [YAH, 11000, 3.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 150, 97.0] [YAH, 11500, 6.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [YAH, 10500, 7.0] [IBM, 100, 72.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 150, 48.0] [MSFT, 5000, null] [YAH, 10000, 6.0]
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol output first every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives [IBM, 100, 25.0] 0.8 MSFT 5000 9.0 Event E2 arrives [MSFT, 5000, 9.0] 1.0 1.2 1.5 IBM 150 24.0 Event E3 arrives [IBM, 150, 49.0] YAH 10000 1.0 Event E4 arrives [YAH, 10000, 1.0] 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 2.5 3.0 3.2 3.5 YAH 11000 2.0 Event E6 arrives [YAH, 11000, 3.0] 4.0 4.2 4.3 IBM 150 22.0 Event E7 arrives [IBM, 150, 97.0] 4.9 YAH 11500 3.0 Event E8 arrives [YAH, 11500, 6.0] 5.0 5.2 5.7 Event E1 leaves the time window [IBM, 100, 72.0] 5.9 YAH 10500 1.0 Event E9 arrives [YAH, 10500, 7.0] 6.0 6.2 6.3 Event E2 leaves the time window [MSFT, 5000, null] 7.0 Event E3 and E4 leave the time window [IBM, 150, 48.0] [YAH, 10000, 6.0] 7.2
The statement for this sample reads:
select irstream symbol, volume, sum(price) from MarketData.win:time(5.5 sec) group by symbol output snapshot every 1 seconds
The output is as follows:
Input Output Insert Stream Remove Stream ----------------------------------------------- ---------------------------------- Time Symbol Volume Price 0.2 IBM 100 25.0 Event E1 arrives 0.8 MSFT 5000 9.0 Event E2 arrives 1.0 1.2 [IBM, 100, 25.0] [MSFT, 5000, 9.0] 1.5 IBM 150 24.0 Event E3 arrives YAH 10000 1.0 Event E4 arrives 2.0 2.1 IBM 155 26.0 Event E5 arrives 2.2 [IBM, 100, 75.0] [MSFT, 5000, 9.0] [IBM, 150, 75.0] [YAH, 10000, 1.0] [IBM, 155, 75.0] 2.5 3.0 3.2 [IBM, 100, 75.0] [MSFT, 5000, 9.0] [IBM, 150, 75.0] [YAH, 10000, 1.0] [IBM, 155, 75.0] 3.5 YAH 11000 2.0 Event E6 arrives 4.0 4.2 [IBM, 100, 75.0] [MSFT, 5000, 9.0] [IBM, 150, 75.0] [YAH, 10000, 3.0] [IBM, 155, 75.0] [YAH, 11000, 3.0] 4.3 IBM 150 22.0 Event E7 arrives 4.9 YAH 11500 3.0 Event E8 arrives 5.0 5.2 [IBM, 100, 97.0] [MSFT, 5000, 9.0] [IBM, 150, 97.0] [YAH, 10000, 6.0] [IBM, 155, 97.0] [YAH, 11000, 6.0] [IBM, 150, 97.0] [YAH, 11500, 6.0] 5.7 Event E1 leaves the time window 5.9 YAH 10500 1.0 Event E9 arrives 6.0 6.2 [MSFT, 5000, 9.0] [IBM, 150, 72.0] [YAH, 10000, 7.0] [IBM, 155, 72.0] [YAH, 11000, 7.0] [IBM, 150, 72.0] [YAH, 11500, 7.0] [YAH, 10500, 7.0] 6.3 Event E2 leaves the time window 7.0 Event E3 and E4 leave the time window 7.2 [IBM, 155, 48.0] [YAH, 11000, 6.0] [IBM, 150, 48.0] [YAH, 11500, 6.0] [YAH, 10500, 6.0]