Java 在IDEA的本地计算机上和集群上的hadoop中运行mapreduce时的不同输出
问题是它在描述中说了什么。我有一些密码 这是减速器Java 在IDEA的本地计算机上和集群上的hadoop中运行mapreduce时的不同输出,java,hadoop,mapreduce,composite-key,Java,Hadoop,Mapreduce,Composite Key,问题是它在描述中说了什么。我有一些密码 这是减速器 public class RTopLoc extends Reducer<CompositeKey, IntWritable, Text, Text> { private static int number = 0; private static CompositeKey lastCK = new CompositeKey(); private static Text lastLac = new Text()
public class RTopLoc extends Reducer<CompositeKey, IntWritable, Text, Text> {
private static int number = 0;
private static CompositeKey lastCK = new CompositeKey();
private static Text lastLac = new Text();
@Override
public void reduce(CompositeKey key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = sumValues(values);
String str = Integer.toString(sum);
String str2 = Integer.toString(number);
String str3 = key.getSecond().toString();
context.write(key.getFirst(), new Text(str3 + " " + str2 + " " + str));
if(number == 0){
number = sum;
lastCK = key;
context.write(new Text("1"), new Text("1"));
}
else if(lastCK.getFirst().equals(key.getFirst()) && sum > number){
lastCK = key;
context.write(new Text("2"), new Text("2"));
}
else if(!lastCK.getFirst().equals(key.getFirst())){
// context.write(lastCK.getFirst(), lastCK.getSecond());
context.write(new Text("3"), new Text("3"));
number = sum;
lastCK = key;
}
}
在我打包代码(我使用maven)并在hadoop(Linux)上运行它之后,我得到了
我用这个来运行代码
hadoop jar Project.jar inputPath outputPath
这种差异似乎是由于比较部分存储密钥(lastCK)和当前密钥时出现问题造成的 我想改变这一行:
lastCK=key代码>
键和值在Hadoop中被重用,因此当它在真实集群上运行时,您的键将是相同的,因为lastCK
和key
都是相同的对象
您需要正确地将key
复制到lastCK
,可能需要使用.set()
方法(您编写的并且是hadoop中的常见模式),或者使用接受CompositeKey
的构造函数创建一个新的I将每个lastCK=key更改为lastCK.setFirst(key.getFirst());setSecond(key.getSecond());它不起作用,然后我将它改为lastCK=newcompositekey(key.getFirst(),key.getSecond());在这两种情况下,结果都与开始时相同。getFirst()
返回什么类型的对象,以及您的setFirst()
方法是如何工作的?例如,如果它是一个文本,而您的set方法没有=
,那么它也有相同的问题。
0000000000 44137 0 2
1 1
902996760100000 44137 2 6
2 2
9029967602 44137 2 8
2 2
90299676030000 44137 2 1
9029967604 44137 2 5
2 2
905000 38704 2 1
9050000001 38702 2 24
2 2
9050000001 38704 2 14
2 2
9050000001 38705 2 12
2 2
9050000001 38706 2 13
2 2
9050000001 38714 2 24
2 2
9050000002 38704 2 12
2 2
9050000002 38706 2 12
2 2
9050000011 38704 2 6
2 2
9050000011 38706 2 12
2 2
9050000021 38702 2 12
2 2
9050000031 38704 2 6
2 2
9050000031 38705 2 6
2 2
9050000031 38714 2 12
2 2
hadoop jar Project.jar inputPath outputPath