我在解决Flink (1.11.0版)中的错误时遇到了问题:
java: no suitable method found for process(com.xyz.myPackage.operators.windowed.ComputeFeatures)
method org.apache.flink.streaming.api.datastream.WindowedStream.<R>process(org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction<com.xyz.myPackage.entities.StreamElement,R,java.lang.Long,org.apache.flink.streaming.api.windowing.windows.TimeWindow>) is not applicable
(cannot infer type-variable(s) R
(argument mismatch; com.xyz.myPackage.operators.windowed.ComputeFeatures cannot be converted to org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction<com.xyz.myPackage.entities.StreamElement,R,java.lang.Long,org.apache.flink.streaming.api.windowing.windows.TimeWindow>))
method org.apache.flink.streaming.api.datastream.WindowedStream.<R>process(org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction<com.xyz.myPackage.entities.StreamElement,R,java.lang.Long,org.apache.flink.streaming.api.windowing.windows.TimeWindow>,org.apache.flink.api.common.typeinfo.TypeInformation<R>) is not applicable
(cannot infer type-variable(s) R
(actual and formal argument lists differ in length))这就是我如何创建一个键控窗口流:
timestampedStreamElementDataStream
.keyBy(StreamElement::getId)
.window(SlidingEventTimeWindows.of(Time.seconds(600),Time.seconds(60)))
.process(new ComputeFeatures());下面是我的ComputeFeatures函数的样子:
public class ComputeFeatures extends ProcessWindowFunction<
StreamElement,
StreamElement,
Long,
TimeWindow> {
@Override
public void process(Long key,
Context context,
Iterable<StreamElement> elements,
Collector<StreamElement> out) throws Exception {
System.out.println("In windowed function");
}
}StreamElement::getId返回一个Long,因此有关类型的所有内容都应该是正确的,但是似乎Flink仍然难以推断一个类型。我正在寻找如何解决这一问题的想法。
注意:这个问题似乎是相关的,但它不适合我的问题:LINK
编辑1:正如大卫建议的那样,我尝试用process自动生成覆盖的IntelliJ函数,但问题仍然是一样的。在指定类型时,自动生成的代码如下所示:
public class ComputeFeatures extends ProcessWindowFunction<StreamElement,StreamElement,Long,TimeWindow> {
@Override
public void process(Long aLong,
ProcessWindowFunction<StreamElement, StreamElement, Long, TimeWindow>.Context context,
Iterable<StreamElement> elements,
Collector<StreamElement> out) throws Exception {
}当我省略类型规范时,就像这样:
public class ComputeFeatures extends ProcessWindowFunction {
@Override
public void process(Object o, Context context, Iterable elements, Collector out) throws Exception {
System.out.println("In windowed function");
}编辑2:可能相关:当我悬停在new ComputeFeatures()上时,IntelliJ会显示这个信息框:
Required type:
ProcessWindowFunction
<com.xyz.myPackage.entities.StreamElement,
R,
java.lang.Long,
org.apache.flink.streaming.api.windowing.windows.TimeWindow>
Provided:
ComputeFeatures
reason: no instance(s) of type variable(s) R exist so that ComputeFeatures conforms to ProcessWindowFunction<StreamElement, R, Long, TimeWindow>发布于 2022-04-07 08:47:30
呃,愚蠢的错误,代码工作正常,问题是IntelliJ导入了错误的ProcessWindowFunction ( Scala变体)。在改变了一切按预期运行之后
发布于 2022-04-07 07:50:17
我不知道出了什么问题,但在这种情况下,我通常通过让IntelliJ为我生成方法来调试类型不匹配--因此,在本例中,被覆盖的进程方法--这样我就可以看到它认为正在发生什么。
https://stackoverflow.com/questions/71768780
复制相似问题