[ https://issues.apache.org/jira/browse/FLINK-7169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16119859#comment-16119859 ]
ASF GitHub Bot commented on FLINK-7169: --------------------------------------- Github user dawidwys commented on a diff in the pull request: https://github.com/apache/flink/pull/4331#discussion_r132134129 --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/AfterMatchSkipStrategy.java --- @@ -0,0 +1,276 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.cep.nfa; + +import org.apache.flink.api.common.typeutils.CompatibilityResult; +import org.apache.flink.api.common.typeutils.CompatibilityUtil; +import org.apache.flink.api.common.typeutils.CompositeTypeSerializerConfigSnapshot; +import org.apache.flink.api.common.typeutils.TypeDeserializerAdapter; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.api.common.typeutils.TypeSerializerConfigSnapshot; +import org.apache.flink.api.common.typeutils.UnloadableDummyTypeSerializer; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataInputViewStreamWrapper; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.core.memory.DataOutputViewStreamWrapper; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.List; + + +/** + * Indicate the skip strategy after a match process. + * <p>There're four kinds of strategies: + * SKIP_PAST_LAST_EVENT, + * SKIP_TO_NEXT_EVENT, + * SKIP_TO_FIRST_<code>PATTERN</code> and + * SKIP_TO_LAST_<code>PATTERN</code> + * </p> + */ +public class AfterMatchSkipStrategy implements Serializable { + + // default strategy + SkipStrategy strategy = SkipStrategy.SKIP_TO_NEXT_EVENT; + + // fields + String patternName = null; + + public AfterMatchSkipStrategy(){ + this(SkipStrategy.SKIP_TO_NEXT_EVENT, null); + } + + public AfterMatchSkipStrategy(SkipStrategy strategy) { + this(strategy, null); + } + + public AfterMatchSkipStrategy(SkipStrategy strategy, String patternName) { + if (patternName == null && (strategy == SkipStrategy.SKIP_TO_FIRST || strategy == SkipStrategy.SKIP_TO_LAST)) { + throw new IllegalArgumentException("the patternName field can not be empty when SkipStrategy is " + strategy); + } + this.strategy = strategy; + this.patternName = patternName; + } + + public SkipStrategy getStrategy() { + return strategy; + } + + public String getPatternName() { + return patternName; + } + + @Override + public String toString() { + return "AfterMatchStrategy{" + + "strategy=" + strategy + + ", patternName=" + patternName + + '}'; + } + + /** + * Skip Strategy Enum. + */ + public enum SkipStrategy{ + SKIP_TO_NEXT_EVENT, + SKIP_PAST_LAST_EVENT, + SKIP_TO_FIRST, + SKIP_TO_LAST + } + + /** + * The {@link TypeSerializerConfigSnapshot} serializer configuration to be stored with the managed state. + */ + public static class AfterMatchSkipStrategyConfigSnapshot extends CompositeTypeSerializerConfigSnapshot { + + private static final int VERSION = 1; + + /** + * This empty constructor is required for deserializing the configuration. + */ + public AfterMatchSkipStrategyConfigSnapshot() { + } + + public AfterMatchSkipStrategyConfigSnapshot( + TypeSerializer<SkipStrategy> enumSerializer, + TypeSerializer<String> stringSerializer) { + + super(enumSerializer, stringSerializer); + } + + @Override + public int getVersion() { + return VERSION; + } + } + + /** + * A {@link TypeSerializer} for the {@link AfterMatchSkipStrategy}. + */ + public static class AfterMatchSkipStrategySerializer extends TypeSerializer<AfterMatchSkipStrategy> { + + private final TypeSerializer<SkipStrategy> enumSerializer; + private final TypeSerializer<String> stringSerializer; + + public AfterMatchSkipStrategySerializer(TypeSerializer<SkipStrategy> enumSerializer, TypeSerializer<String> stringSerializer) { + this.enumSerializer = enumSerializer; + this.stringSerializer = stringSerializer; + } + + @Override + public boolean isImmutableType() { + return false; + } + + @Override + public TypeSerializer<AfterMatchSkipStrategy> duplicate() { + return new AfterMatchSkipStrategySerializer(enumSerializer, stringSerializer); + } + + @Override + public AfterMatchSkipStrategy createInstance() { + return new AfterMatchSkipStrategy(); + } + + @Override + public AfterMatchSkipStrategy copy(AfterMatchSkipStrategy from) { + try { --- End diff -- Why not just: new AfterMatchSkipStrategy(from.strategy, from.patternName) No need to serialize/deserialize. > Support AFTER MATCH SKIP function in CEP library API > ---------------------------------------------------- > > Key: FLINK-7169 > URL: https://issues.apache.org/jira/browse/FLINK-7169 > Project: Flink > Issue Type: Sub-task > Components: CEP > Reporter: Yueting Chen > Assignee: Yueting Chen > Fix For: 1.4.0 > > > In order to support Oracle's MATCH_RECOGNIZE on top of the CEP library, we > need to support AFTER MATCH SKIP function in CEP API. > There're four options in AFTER MATCH SKIP, listed as follows: > 1. AFTER MATCH SKIP TO NEXT ROW: resume pattern matching at the row after the > first row of the current match. > 2. AFTER MATCH SKIP PAST LAST ROW: resume pattern matching at the next row > after the last row of the current match. > 3. AFTER MATCH SKIP TO FIST *RPV*: resume pattern matching at the first row > that is mapped to the row pattern variable RPV. > 4. AFTER MATCH SKIP TO LAST *RPV*: resume pattern matching at the last row > that is mapped to the row pattern variable RPV. > I think we can introduce a new function to `CEP` class, which takes a new > parameter as AfterMatchSKipStrategy. > The new API may looks like this > {code} > public static <T> PatternStream<T> pattern(DataStream<T> input, Pattern<T, ?> > pattern, AfterMatchSkipStrategy afterMatchSkipStrategy) > {code} > We can also make `SKIP TO NEXT ROW` as the default option, because that's > what CEP library behaves currently. -- This message was sent by Atlassian JIRA (v6.4.14#64029)