[GitHub] dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches
dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches URL: https://github.com/apache/flink/pull/6781#discussion_r221640010 ## File path: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java ## @@ -74,6 +77,36 @@ } } + /** +* Verifies if the provided pattern can possibly generate empty match. Example of patterns that can possibly +* generate empty matches are: A*, A?, A* B? etc. +* +* @param pattern pattern to check +* @return true if empty match could potentially match the pattern, false otherwise +*/ + public static boolean canProduceEmptyMatches(final Pattern pattern) { + NFAFactoryCompiler compiler = new NFAFactoryCompiler<>(checkNotNull(pattern)); + compiler.compileFactory(); + State startState = compiler.getStates().stream().filter(State::isStart).findFirst().get(); + + final Stack> statesToCheck = new Stack<>(); + statesToCheck.push(startState); + while (!statesToCheck.isEmpty()) { + final State currentState = statesToCheck.pop(); + for (StateTransition transition : currentState.getStateTransitions()) { + if (transition.getAction() == StateTransitionAction.PROCEED) { + if (transition.getTargetState().isFinal()) { + return true; + } else { + statesToCheck.push(transition.getTargetState()); Review comment: Theoretically yes, practically compiler won't produce such graph as of now. Do you think I should be defensive though? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches
dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches URL: https://github.com/apache/flink/pull/6781#discussion_r221640962 ## File path: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java ## @@ -74,6 +77,36 @@ } } + /** +* Verifies if the provided pattern can possibly generate empty match. Example of patterns that can possibly +* generate empty matches are: A*, A?, A* B? etc. +* +* @param pattern pattern to check +* @return true if empty match could potentially match the pattern, false otherwise +*/ + public static boolean canProduceEmptyMatches(final Pattern pattern) { + NFAFactoryCompiler compiler = new NFAFactoryCompiler<>(checkNotNull(pattern)); + compiler.compileFactory(); + State startState = compiler.getStates().stream().filter(State::isStart).findFirst().get(); Review comment: Ok, will change it. In general though I am always torn in this situations, cause that would mean we have a bug in our compiler. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches
dawidwys commented on a change in pull request #6781: [FLINK-10470] Add method to check if pattern can produce empty matches URL: https://github.com/apache/flink/pull/6781#discussion_r221640962 ## File path: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java ## @@ -74,6 +77,36 @@ } } + /** +* Verifies if the provided pattern can possibly generate empty match. Example of patterns that can possibly +* generate empty matches are: A*, A?, A* B? etc. +* +* @param pattern pattern to check +* @return true if empty match could potentially match the pattern, false otherwise +*/ + public static boolean canProduceEmptyMatches(final Pattern pattern) { + NFAFactoryCompiler compiler = new NFAFactoryCompiler<>(checkNotNull(pattern)); + compiler.compileFactory(); + State startState = compiler.getStates().stream().filter(State::isStart).findFirst().get(); Review comment: Ok, will change it. In general though I am always torn in this situations, cause that would mean we have a bug in our compiler, so it is actually not an `IllegalState` This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services