gpt4 book ai didi

java - Flink 数据集 API : Is GroupBy is not working correctly?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:24 25 4
gpt4 key购买 nike

在我的 Flink Java 程序中,我使用了一个 GroupBy-Operator,如下所示:

dataSet.groupBy(new KeySelector<myObject, Tuple2<Tuple2<Integer, Integer>, Integer>>() {
private static final long serialVersionUID = 5L;
Tuple2<Tuple2<Integer, Integer>, Integer> groupingKey = new Tuple2<Tuple2<Integer, Integer>, Integer>();

public Tuple2<Tuple2<Integer, Integer>, Integer> getKey(myObject s) {
groupingKey.setField(s.getPosition(), 0);
groupingKey.setField(s.getBand(), 1);
return groupingKey;
}
})
.reduceGroup(reduceFunction);

getPosition()返回 Tuple2<Integer, Integer>getBand()返回 int .

我想根据这两个值对我的数据集进行分组。如果我有 6 个位置和 4 个波段,我想得到 24 个不同的组并使用 groupReduce - 为每个小组独立运作。但目前我的结果组似乎包含乐队和位置的各种值。我在 groupReduce 中检查过这个功能:

if (this.band == null) {
this.band = myObject.getBand();
}
if (this.band != myObject.getBand()) {
System.out.println("The band should be " + this.band + " but is: " + myObject.getBand());

此外,我的结果文件中还有一些值表明分组存在问题。分组是否有可能在我的情况下不起作用?或者这可能只是我的代码中另一个潜在错误的结果?

最佳答案

我认为您在 GroupReduceFunction 中的检查工作不正常。GroupReduceFunction.reduce() 可以针对不同的组调用多次。 this.band 是您的 GroupReduceFunction 的成员变量,我假设您没有在 的末尾重置 this.band reduce() 方法。

因此,this.band 仅在第一次调用 reduce() 时才会null。在第二次调用开始时,this.band 将被初始化,并且不会设置为当前组的频段。因此,下面的检查将失败。

关于java - Flink 数据集 API : Is GroupBy is not working correctly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34763284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com