Github user dawidwys commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4418#discussion_r130816980
  
    --- Diff: 
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/operator/AbstractKeyedCEPPatternOperator.java
 ---
    @@ -257,7 +289,32 @@ public void onEventTime(InternalTimer<KEY, 
VoidNamespace> timer) throws Exceptio
     
        @Override
        public void onProcessingTime(InternalTimer<KEY, VoidNamespace> timer) 
throws Exception {
    -           // not used
    +           NFA<IN> nfa = getNFA();
    +
    +           // emit the events in order
    +           for (IN event : sort(bufferedEvents.get())) {
    +                   processEvent(nfa, event, 
getProcessingTimeService().getCurrentProcessingTime());
    +           }
    +
    +           // remove all buffered rows
    +           bufferedEvents.clear();
    +
    +           updateNFA(nfa);
    +   }
    +
    +   private Iterable<IN> sort(Iterable<IN> iter) {
    +           if (comparator == null) {
    +                   return iter;
    +           } else {
    +                   // insert all events into the sort buffer
    +                   List<IN> sortBuffer = new ArrayList<>();
    --- End diff --
    
    As we dropped support of Java 7, we could use `Stream` here. That way we 
won't need to create the temporary buffer.
    
    Sth like:
    
        private Stream<IN> sort(Iterable<IN> iter) {
                Stream<IN> stream = StreamSupport.stream(iter.spliterator(), 
false);
                if (comparator == null) {
                        return stream;
                } else {
                        return stream.sorted(comparator);
        }
    
    And use it like this:
    
        sort(bufferedEvents.get()).forEachOrdered(
                event -> processEvent(nfa, event, 
getProcessingTimeService().getCurrentProcessingTime())
        );
    
    What do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to