gpt4 book ai didi

java - 从 reducer 中将列数据作为行发出

转载 作者:行者123 更新时间:2023-12-01 13:19:48 24 4
gpt4 key购买 nike

我正在尝试处理 csv 文件。在map()中,我将把每一列作为一个值发送给reducer。在reducer中,我将找到最小值和最大值并进一步处理。处理后,我需要上下文。写入值。但尝试以特定方式输出。

在reducer中,我正在处理每一列,但我需要输出整个即col1的值,col2的值,col3的值,col4的值。

reducer处理后的样本数据

in reducer
0.62
0.38
0.9
in reducer
0.24
0.59
0.1
in reducer
0.5
1.0
0.2
in reducer
0.0
0.0
0.3

预期输出

 0.62,0.24,0.5,0.5
0.38,0.59,1.0,0.0
0.9,0.1,0.2,0.3

是否可以在每次迭代中处理reducer中的每个不同键

key1value1,key2value1,key3value1
key1value2,key2value2,key3value2

任何建议

最佳答案

使用 MapReduce 链接,您可以执行此操作

使用文本类型在单行中写入 reducer 输出喜欢

0.62,0.38,0.9
0.24,0.59,0.1

再次对第一个MapReduce的输出文件执行mapreduce。

public void map(Text key, Text value,OutputCollector<Text, Text> output,
Reporter reporter) throws IOException {
String temp=new String(value);
String token[]=temp.split(",");
output.collect(new Text("max"),new text(token[0]));
output.collect(new Text("min"),new text(token[1]));
output.collect(new Text("result"),new text(token[2]));
}

public void reduce(Text key, Iterator<Text> values,
OutputCollector<Text, Text> output, Reporter reporter)
throws IOException {
StringBuffer sb=new StringBuffer();
while (values.hasNext())
sb.append(values.next().toString() + ",");
output.collect(new Text(""),new Text(sb.toString()))



}

关于java - 从 reducer 中将列数据作为行发出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22139285/

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