Reputation: 2816
I am trying to filter all temp events that are > 10 in Flink using below pattern,
Pattern<MonitoringEvent, ?> warningPattern = Pattern.<MonitoringEvent>begin("first")
.subtype(TemperatureEvent.class)
.where(new FilterFunction<TemperatureEvent>() {
@Override
public boolean filter(TemperatureEvent temperatureEvent) throws Exception {
return temperatureEvent.getTemperature() > 50;
}
});
Input is a text file , which is parsed to stream by an input function, Contents of input file are:-
1,98
2,33
3,44
4,55
5,66
6,88
7,99
8,76
Here first value is Rack_id and second is Temperature
I have issued print() on both input-stream and WarnigsStream as shown below
inputEventStream.print();
warnings.print();
Now, comes the issue, The output of Flink CEP is shown below
08/10/2017 23:43:15 Job execution switched to status RUNNING.
08/10/2017 23:43:15 Source: Custom Source -> Sink: Unnamed(1/1) switched to SCHEDULED
08/10/2017 23:43:15 Source: Custom Source -> Sink: Unnamed(1/1) switched to DEPLOYING
08/10/2017 23:43:15 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to SCHEDULED
08/10/2017 23:43:15 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to DEPLOYING
08/10/2017 23:43:15 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to RUNNING
08/10/2017 23:43:15 Source: Custom Source -> Sink: Unnamed(1/1) switched to RUNNING
Rack id = 1 and temprature = 98.0)
Rack id = 2 and temprature = 33.0)
Rack id = 3 and temprature = 44.0)
Rack id = 4 and temprature = 55.0)
Rack id = 5 and temprature = 66.0)
Rack id = 6 and temprature = 88.0)
Rack id = 7 and temprature = 99.0)
Rack id = 8 and temprature = 76.0)
08/10/2017 23:43:16 Source: Custom Source -> Sink: Unnamed(1/1) switched to FINISHED
Rack id = 1 and temprature = 98.0)
Rack id = 8 and temprature = 76.0)
Rack id = 7 and temprature = 99.0)
Rack id = 6 and temprature = 88.0)
Rack id = 5 and temprature = 66.0)
Rack id = 4 and temprature = 55.0)
08/10/2017 23:43:16 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to FINISHED
08/10/2017 23:43:16 Job execution switched to status FINISHED.
Process finished with exit code 0
As we can see, the first Complex event(Rack id = 1 and temperature = 98.0)) is printed in same order, but after this, all the other complex events having temp > 50 are getting printed in opposite order with respect to the input stream.
My questions are :-
1. Any idea why events are getting printed in reverse order?
2. Is there a custom way to print values{w/o using warnings.print()} of
warning stream, like can I print only temperature, rather than rack-id ?
Thanks in Advance
Upvotes: 0
Views: 66
Reputation: 2816
This issue was solved by assigning Timestamps and Watermarks to inputStream shown as below
// Input stream of monitoring events
DataStream<MonitoringEvent> inputEventStream = env
.addSource(new InputStreamAGenerator()).assignTimestampsAndWatermarks(new IngestionTimeExtractor<>());
Output Generated is shown below
08/11/2017 00:45:09 Job execution switched to status RUNNING.
08/11/2017 00:45:09 Source: Custom Source -> Timestamps/Watermarks(1/1) switched to SCHEDULED
08/11/2017 00:45:09 Source: Custom Source -> Timestamps/Watermarks(1/1) switched to DEPLOYING
08/11/2017 00:45:09 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to SCHEDULED
08/11/2017 00:45:09 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to DEPLOYING
08/11/2017 00:45:09 Source: Custom Source -> Timestamps/Watermarks(1/1) switched to RUNNING
08/11/2017 00:45:09 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to RUNNING
Rack id = 1 and temprature = 98.0)
Rack id = 4 and temprature = 55.0)
Rack id = 5 and temprature = 66.0)
Rack id = 6 and temprature = 88.0)
Rack id = 7 and temprature = 99.0)
Rack id = 8 and temprature = 76.0)
08/11/2017 00:45:10 Source: Custom Source -> Timestamps/Watermarks(1/1) switched to FINISHED
08/11/2017 00:45:10 AbstractCEPPatternOperator -> Map -> Sink: Unnamed(1/1) switched to FINISHED
08/11/2017 00:45:10 Job execution switched to status FINISHED.
Upvotes: 1