Query partition example with multiple inputs
The following query provides an example of partitioning with two inputs. This query operates on APNR (Automatic Plate Number Recognition) events and Accident events:
query DetectSpeedingAccidents {
inputs {
APNR() key road within(150.0);
Accident() key road within(10.0);
}
find APNR as checkpointA -> APNR as checkpointB -> Accident as accident
where checkpointA.plateNumber = checkpointB.plateNumber
and checkpointB.time - checkPointA.time < 100
// Which indicates the car was speeding
{
emit NotifyPolice(accident.road, checkpointA.plateNumber);
}
}
The road field in an APNR event must be the same type as the road field in an Accident event. Assuming that road is a string, each partition is identified by a unique value for that string.
Suppose the correlator processes the following events in top to bottom order and that road is the first field in each event:
Accident("M11")
APNR("A14", "FAB 1", ...)
APNR("A14", "BSG 75", ...)
APNR("M11", "ZC 158", ...)
APNR("A14", "BSG 75", ...)
APNR("M11", "ZC 158", ...)
APNR("A14", "FAB 1", ...)
Accident("A14")
The following table shows which events are in which partitions. Note that in each partition, the APNR events are in one window and the Accident events are in another window. Although the events are in separate windows, the correlator time-orders the events across all windows in a partition.
Events in Partition Identified by "M11" | Events in Partition Identified by "A14" |
Accident("M11") APNR("M11", "ZC 158", ...) APNR("M11", "ZC 158", ...) | APNR("A14", "FAB 1", ...) APNR("A14", "BSG 75", ...) APNR("A14", "BSG 75", ...) APNR("A14", "FAB 1", ...) Accident("A14") |
In each partition, the query evaluates the event pattern against the events in the windows in that partition. The query does this for each partition separately from every other partition. In this example, when the correlator adds the Accident("A14") event to the partition identified by "A14" the event pattern is triggered if the where clause in the find statement evaluates to true. The event pattern is not triggered in the partition identified by "M11".