首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能推断Flink ProcessWindowFunction中的类型变量R

不能推断Flink ProcessWindowFunction中的类型变量R
EN

Stack Overflow用户
提问于 2022-04-06 14:39:39
回答 2查看 140关注 0票数 0

我在解决Flink (1.11.0版)中的错误时遇到了问题:

代码语言:javascript
复制
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))

这就是我如何创建一个键控窗口流:

代码语言:javascript
复制
timestampedStreamElementDataStream
        .keyBy(StreamElement::getId)
        .window(SlidingEventTimeWindows.of(Time.seconds(600),Time.seconds(60)))
        .process(new ComputeFeatures());

下面是我的ComputeFeatures函数的样子:

代码语言:javascript
复制
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函数,但问题仍然是一样的。在指定类型时,自动生成的代码如下所示:

代码语言:javascript
复制
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 {

    }

当我省略类型规范时,就像这样:

代码语言:javascript
复制
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会显示这个信息框:

代码语言:javascript
复制
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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-04-07 08:47:30

呃,愚蠢的错误,代码工作正常,问题是IntelliJ导入了错误的ProcessWindowFunction ( Scala变体)。在改变了一切按预期运行之后

票数 1
EN

Stack Overflow用户

发布于 2022-04-07 07:50:17

我不知道出了什么问题,但在这种情况下,我通常通过让IntelliJ为我生成方法来调试类型不匹配--因此,在本例中,被覆盖的进程方法--这样我就可以看到它认为正在发生什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71768780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档