我需要读取两个包含以下数据的文件:file1.txt是
2 3
3 2
4 1
5 1
1 1
而file2.txt是
1 2
3 4
5 1
2 4
4 5
2 5
2 3
3 2
现在我想要输出为
1 1:2
2 3:3,4,5
3 2:2,4
4 1:5
5 1:1
我的制图员如下:
public static class OutDegreeMapper1
extends Mapper<Object, Text, Text, Text>
{
private Text word = new Text();
private Text word2 = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException
{
String oneLine = value.toString();
String[] parts = oneLine.split(" ");
word.set(parts[1]);
word2.set(parts[2]);
context.write(word, word2);
}
}
public static class OutDegreeMapper2
extends Mapper<Object, Text, Text, Text>
{
private Text word = new Text();
private Text word2 = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException
{
String oneLine = value.toString();
String[] parts = oneLine.split("\t");
word.set(parts[0]);
word2.set(parts[1]);
context.write(word, word2);
}
}
我的减速机是
public static class OutDegreeReducer
extends Reducer<Text,Text,Text,Text>
{
//private IntWritable result = new IntWritable();
private Text word = new Text();
String merge ="";
public void reduce(Text key, Iterable<Text> values,
Context context
) throws IOException, InterruptedException
{
int i =0;
for(Text value:values)
{
if(i == 0){
merge = value.toString()+":";
}
else{
merge += value.toString();
}
i++;
}
word.set(merge);
context.write(key, word);
}
}
现在的问题是,我没有按预期顺序获得数据。有人好心地告诉我们如何得到想要的输出
电流输出,不连续,错误
暂无答案!
目前还没有任何答案,快来回答吧!