Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Queries | Partitioning queries | About keys that have more than one field
 
About keys that have more than one field
A key can be made up of several event fields. For example, a Transaction event might contain a field that indicates the transaction source account and another field that indicates the transaction destination account. You can specify that you want to partition Transaction events according to each unique source/destination combination:
query TransactionMonitor {
inputs {
Transaction() key source, dest within PERIOD;
}
...
}
In this example, there is a partition identified by the value of each source/dest combination. Each of the following events is added to a window in a different partition:
This Event
Is Added to the Window in the Partition Identified By
Transaction(1, 100, ...)
1, 100
Transaction(1, 102, ...)
1, 102
Transaction(2, 100, ...)
2, 100
Transaction(2, 102, ...)
2, 102
Regardless of the event pattern in the query, this query monitors the transfer of money from one specific account to another specific account. This query handles each transfer between the same two accounts separately from all other transactions.
Now suppose that there is an Acknowledgement event that acknowledges that a transaction has succeeded. It also has account source and account destination fields, but they are inverted when compared to the transaction event fields. That is, the source account for an acknowledgment is the destination account of the transaction. To ensure that the acknowledgments are added to the same partition as the corresponding transactions, the key definition specifies the as keyword:
inputs {
Transaction() key source as txSource, dest as txDest within PERIOD;
Acknowledgement() key dest as txSource, source as txDest within PERIOD
}
The query partitions events according to the combined values of the fields identified by txSource and txDest. The following table shows the partition that each event is added to.
This Event
Is Added to a Window in the Partition Identified By
Transaction(1, 100, ...)
1, 100
Acknowledgement(100, 1, ...)
1, 100
Transaction(1, 102, ...)
1, 102
Transaction(2, 100, ...)
2, 100
Acknowledgement(100, 2, ...)
2, 100
As you can see, a Transaction event and its Acknowledgement event are each added to a window in the same partition.