自定义PatternProcessFunction编译出错,type erasure相关。

classic Classic list List threaded Threaded
1 message Options
lgs
Reply | Threaded
Open this post in threaded view
|

自定义PatternProcessFunction编译出错,type erasure相关。

lgs
Hi,

我定义了一个PatternProcessFunction,

  public static class MyPatternProcessFunction<ObjectNode, String> extends
PatternProcessFunction<ObjectNode, String> implements
TimedOutPartialMatchHandler<ObjectNode> {
    @Override
    public void processMatch(Map<String, List&lt;ObjectNode>> pattern,
PatternProcessFunction.Context ctx, Collector<String> out) {
      System.out.println ("pattern found");
      for (String key: pattern.keySet())         //iteration over keys  
      {  
        //returns the value to which specified key is mapped  
        ObjectNode event=pattern.get(key).get(0);  
        // out.collect(event.get("value").get("flow_name").asText() + ", "
        //  + event.get("value").get("component").asText() + ", "
        //  + event.get("value").get("event_time").asText() + ", "
        //  + event.get("value").get("filename").asText());  
        // out.collect(key);
      }
    }

    @Override
    public void processTimedOutMatch(Map<String, List&lt;ObjectNode>>
pattern, PatternProcessFunction.Context ctx) {
      System.out.println ("pattern found");
      for (String key: pattern.keySet())         //iteration over keys  
      {  
        //returns the value to which specified key is mapped  
        ObjectNode event=pattern.get(key).get(0);  
        // ctx.output(event.get("value").get("flow_name").asText() + ", "
        //  + event.get("value").get("component").asText() + ", "
        //  + event.get("value").get("event_time").asText() + ", "
        //  + event.get("value").get("filename").asText());  
        // out.collect(key);
      }
    }
  }

编译出错:

[ERROR]
/home/sysadmin/cepmonitor/src/main/java/org/apache/cepmonitor/StreamingJob.java:[451,17]
org.apache.flink.cepmonitor.StreamingJob.MyPatternProcessFunction is not
abstract and does not override abstract method
processMatch(java.util.Map<java.lang.String,java.util.List&lt;ObjectNode>>,org.apache.flink.cep.functions.PatternProcessFunction.Context,org.apache.flink.util.Collector<String>)
in org.apache.flink.cep.functions.PatternProcessFunction
[ERROR]
/home/sysadmin/cepmonitor/src/main/java/org/apache/cepmonitor/StreamingJob.java:[453,17]
name clash:
processMatch(java.util.Map<String,java.util.List&lt;ObjectNode>>,org.apache.flink.cep.functions.PatternProcessFunction.Context,org.apache.flink.util.Collector<String>)
in org.apache.flink.cepmonitor.StreamingJob.MyPatternProcessFunction and
processMatch(java.util.Map<java.lang.String,java.util.List&lt;IN>>,org.apache.flink.cep.functions.PatternProcessFunction.Context,org.apache.flink.util.Collector<OUT>)
in org.apache.flink.cep.functions.PatternProcessFunction have the same
erasure, yet neither overrides the other
[ERROR]
/home/sysadmin/cepmonitor/src/main/java/org/apache/cepmonitor/StreamingJob.java:[452,5]
method does not override or implement a method from a supertype

请问要怎么解决。我如果把processMatch改成processMatch(Map<java.lang.String,
List&lt;ObjectNode>> pattern,... ), 运行flink job的时候又会报错:

Type of TypeVariable 'String' in 'class
org.apache.flink.cepmonitor.StreamingJob$MyPatternProcessFunction' could not
be determined. This is most likely a type erasure problem. The type
extraction currently supports types with generic variables only in cases
where all variables in the return type can be deduced from the input
type(s). Otherwise the type has to be specified explicitly using type
information.



--
Sent from: http://apache-flink.147419.n8.nabble.com/