gpt4 book ai didi

java - Hadoop mapreduce 中的奇怪输出

转载 作者:可可西里 更新时间:2023-11-01 14:59:33 24 4
gpt4 key购买 nike

这是来自输入文件的示例:

1,name1,name2 
2,name3,name4
3,name5,name6

这是我的 map 方法:

public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
{
String line = value.toString();
StringTokenizer tk = new StringTokenizer( line, ",");
String keyValue = tk.nextToken();
String s1Value = tk.nextToken();
String s2Value = tk.nextToken();
String valueString = s1Value+","+s2Value;
output.collect( new Text(keyValue), new Text(valueString) );
}

这是我的 reduce 函数:

public static class Reduce extends MapReduceBase implements Reducer<Text, Text, Text, Text> 
{
public void reduce(Text key, Iterator<Text> values,
OutputCollector<Text, Text> output, Reporter reporter) throws IOException
{
String item="";
Text tmp= new Text();
while ( values.hasNext() )
{
tmp = values.next();
}
item = tmp.toString();

StringTokenizer tk = new StringTokenizer( item, ",");

String s1="";
String s2="";
boolean entered = false;
try
{
while ( tk.hasMoreTokens() && !entered )
{
s1 = tk.nextToken();
s2 = tk.nextToken();
entered = true;
}
}
catch (Exception e )
{
System.out.println("PROBLEM:"+item);
}
double result = compare(s1,s2);
String result2 = s1+" & "+s2+"="+result;
output.collect( key, new Text(result2) );
}
}

所以我希望输出是(例如):

name1 & name2=1.0  

但我得到的是:

name1 & name2=1.0  &  =0.0

看起来总是有两个空字符串进行比较!!为什么总是有空字符串?

最佳答案

应该关心“compare(s1,s2)”的代码;请粘贴比较功能的代码。

关于java - Hadoop mapreduce 中的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12780812/

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