如何从Combiner / Reducer / Aggregator函数返回包含多个字段的元组?

问题描述 投票:0回答:1

Here Storm Documentation声明:CombinerAggregator返回一个单个元组作为输出。

如何从Combiner函数返回包含多个字段的元组?

我正在创建一个聚合函数,并希望从输入元组聚合两个或多个值,并将这两个或多个字段作为输出发送。

我还想在输出中有一些输入元组的字段。如何使用组合器功能获得所需的输出?

输入组合到组合器聚合器功能:

("a", "b", "c" , "d")

必需的输出元组:

("a", "b", "newValue1", "newValue2", "newValue3")

在过去,我尝试在元组的字段中使用CombinerAggregator的init()方法创建模型,并将其作为输出从CombinerAggregator返回。但我觉得这不是正确的解决方案。 chainedAgg()功能是否适用于这种情况?

任何帮助将不胜感激。

apache spring-boot apache-storm trident apache-storm-topology
1个回答
0
投票

我想你可能想要使用更通用的Aggregator界面。

从您发布的链接:

执行聚合的最通用接口是Aggregator,如下所示:

public interface Aggregator<T> extends Operation {
    T init(Object batchId, TridentCollector collector);
    void aggregate(T state, TridentTuple tuple, TridentCollector collector);
    void complete(T state, TridentCollector collector);
}

聚合器可以发出任意数量的具有任意数量字段的元组。

© www.soinside.com 2019 - 2024. All rights reserved.