它是由'pattern.within'函数触发的吗? [apache-flink]

时间:2019-06-21 14:53:52

标签: java apache-flink complex-event-processing

C:4,g:3,h:1,L:4数据每2秒发送一次。 h:1对我来说并不重要。重要的值是C:4,g:3和l:4。该过程开始时,您有五秒钟的“ pattern.within”。因此,我必须看到C:3,g:4,下一个值应该是L:4。在intelj上运行时,代码运行平稳。我的问题是转换为jar并在flink-1.3.2中运行时出现“过滤器功能”错误。我的代码,

data_list_remove_duplicate = ['C:4','g:3','l:4'];
Pattern<String,?> pattern = Pattern.<String>begin("start").where(
    new SimpleCondition<String>() {
      @Override
      public boolean filter(String value) throws Exception {
         flag = false;
         patern_start_time = new Date();
         if (patern_end_time.before(patern_start_time)){
           patern_end_time = DateUtils.addSeconds(patern_start_time, addMinuteTime); //add seconds
           found_list.clear();
         }
         if(!data_list_remove_duplicate.contains(value)){
             if(!found_list.contains(value))
               found_list.add(value);
               if(control_count == 2){
                  control_count =1;
                  flag = false;
               }
               else
                 flag = true;
              }
              return flag;
           }
       } ).followedBy("middle").optional().within(Time.seconds(addMinuteTime)).where(
        new SimpleCondition<String>() {
           @Override
           public boolean filter(String middle) throws Exception {
             flag = false;
             if(!data_list_remove_duplicate.contains(middle) && !found_list.contains(middle)){
                found_list.add(middle);
                flag = true;
              }
              return flag;
           }
        }
  ).followedBy("end").optional().within(Time.seconds(addMinuteTime)).where(
        new SimpleCondition<String>() {
           @Override
           public boolean filter(String end) throws Exception {
              flag = false;
              if(!data_list_remove_duplicate.contains(end) && !found_list.contains(end)){
                   found_list.add(end);
                   flag = true;
               }
               return flag;
             }
          }
        );
        patern_start_time = new Date();
        pattern.within(Time.seconds(addMinuteTime));
        patern_end_time = DateUtils.addSeconds(patern_start_time, addMinuteTime); //add minute
        System.out.println("current date and time: " + patern_start_time);
        System.out.println("current date and time: " + patern_end_time);
        PatternStream<String> patternStream = CEP.pattern(stream_itemset_categorized,pattern);

        DataStream<String> result = patternStream.select(
                new PatternSelectFunction<String, String>() {
                    @Override
                    public String select(Map<String, List<String>> map) throws Exception {
                        control_count = 2;
                        Integer found = 0;
                        String found_anomaly = "";
                        for (String alert_count: found_list){
                            String[] count = alert_count.split(":");
                            found_anomaly += alert_count + ",";
                            found += Integer.parseInt(count[1]);
                        }
                        if (found_list.size() == 3)
                            found_list.clear();
                        return found_anomaly;
                    }
                }
        );
        result.print();
    }

但是,如果我删除了代码的这一部分,则其余部分工作正常。函数运行时,pattern.within这一部分必须清除found_list。

patern_start_time = new Date();
                        if (patern_end_time.before(patern_start_time)){
                            patern_end_time = DateUtils.addSeconds(patern_start_time, addMinuteTime); //add seconds
                            found_list.clear();
                        }

是否可以使用“ pattern.within”功能触发某些内容?您可以提供其他方法吗?

0 个答案:

没有答案