Github user dianfu commented on a diff in the pull request: https://github.com/apache/flink/pull/4331#discussion_r130266394 --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java --- @@ -551,18 +579,47 @@ private boolean isSelfIgnore(final StateTransition<T> edge) { nextVersion, startTimestamp); } + + switch (skipStrategy.getStrategy()) { + case SKIP_PAST_LAST_EVENT: + if (nextState.isFinal()) { + resultingComputationStates.add(createStartComputationState(computationState, event)); + } + break; + case SKIP_TO_FIRST: + if (nextState.getName().equals(skipStrategy.getPatternName()) && + !nextState.getName().equals(currentState.getName())) { + ComputationState<T> startComputationState = createStartComputationState(computationState, event); + if (callLevel > 0) { + throw new RuntimeException("infinite loop! Will abort the match process, please rewrite your pattern query"); + } + // feed current matched event to the state. + Collection<ComputationState<T>> computationStates = computeNextStates(startComputationState, event, timestamp, callLevel++); + resultingComputationStates.addAll(computationStates); + } else if (previousState == null && currentState.getName().equals(skipStrategy.getPatternName())) { + throw new RuntimeException("infinite loop! Will abort the match process, please rewrite your pattern query"); + } + break; + case SKIP_TO_LAST: + if (currentState.getName().equals(skipStrategy.getPatternName()) && + !nextState.getName().equals(currentState.getName())) { + ComputationState<T> startComputationState = createStartComputationState(computationState, event); + if (callLevel > 0) { + throw new RuntimeException("infinite loop! Will abort the match process, please rewrite your pattern query"); + } + // feed current matched event to the state. + Collection<ComputationState<T>> computationStates = computeNextStates(startComputationState, event, timestamp, callLevel++); + resultingComputationStates.addAll(computationStates); + } + break; + } break; } } - if (computationState.isStartState()) { - int totalBranches = calculateIncreasingSelfState( - outgoingEdges.getTotalIgnoreBranches(), - outgoingEdges.getTotalTakeBranches()); - - DeweyNumber startVersion = computationState.getVersion().increase(totalBranches); - ComputationState<T> startState = ComputationState.createStartState(this, computationState.getState(), startVersion); - resultingComputationStates.add(startState); + if (computationState.isStartState() && + skipStrategy.getStrategy() == AfterMatchSkipStrategy.SkipStrategy.SKIP_TO_NEXT_EVENT) { --- End diff -- If the skip strategy is @**SKIP_PAST_LAST_EVENT**, for pattern **a nextby b** and inputs **a1 c a2 b2**, the output should be **a2 b2**, but per the current implementation, I'm afraid there will be no output as after **a1** is processed, the start ComputationState will be consumed, but there is no chance to add the start ComputationState later and so **a2 b2** can not be matched. Right? For other skip strategy, I'm afraid there may be also such issues.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---