0

I am using Apache Flink 1.16.0 version. I am trying to do a simple CEP by printing the elements to the console For any reason, there is nothing printed to the console, even the process finished with exit code 0.

Here is the code:

import org.apache.flink.cep.*;
import org.apache.flink.cep.functions.PatternProcessFunction;
import org.apache.flink.cep.pattern.Pattern;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStream<String> input = env.fromElements("adrian", "cincu", "diana", "sichitiu");

        Pattern<String, ?> pattern = Pattern.begin("start");

        PatternStream<String> patternStream = CEP.pattern(input, pattern);

        DataStream<String> matches = patternStream.process(new PatternProcessFunction<String, String>() {
            @Override
            public void processMatch(Map<String, List<String>> map,
                                     Context context,
                                     Collector<String> collector) throws Exception {
                collector.collect(map.get("start").toString());
            }
        });

        matches.print();
        env.execute("myjob");
    }
}

Any clue?

f_puras
  • 2,521
  • 4
  • 33
  • 38
Adrian Cincu
  • 17
  • 1
  • 6

1 Answers1

0

I think the issue in this case is that Your pattern doesn't make sense. It will just start matching events, but there is no actual requirement for events to match the pattern, so every event (String in Your case) will match the same Pattern, this will cause the Pattern to stay open forever and never emit any actual data.

You may want to add some kind of requirements to make sure that pattern actually gets closed.

There is some info about how to define Patterns in the [docs].1

Dominik Wosiński
  • 3,769
  • 1
  • 8
  • 22