Map output:
The key value
112008 zhang computer information engineering 1
Computer information engineering 1
181678 Shen Yu Japanese foreign language 2
Japanese foreign language 2
112009 zhang computer economic management 3
Economic management computer 3
(the value of the value of the intermediate with a whitespace-delimited)
the Reduce processing :
Incorporating the same Key value, there are only two computer Key values are the same, the other has become a Key oneself, traverse the same Key value,
1
such as computer and information engineeringEconomic management 3
According to the space separated each valuelist, such as information engineering assignment to the split [0] 1 assignment to the split [1], and then directly to the output, then the same, the economic management assigned to the split [0] 3 assignment to the split [1], and then directly to the output, the back of the original program and steps but later found that this one is wrong,, so I want to ask everybody to help see ~
My Reduce part is as follows:
Public static class YCLReducer extends Reducer
//private LongWritable result=new LongWritable ();
Private Text a1=new Text ();
Private Text b1=new Text ();
Public void the reduce (Text key Iterable
The Context Context
) throws IOException, InterruptedException {
String a;
String b;
The Iterator ite=values. The Iterator ();
While (ite. HasNext ())
{
String record=ite. Next (). The toString ();
String [] lineSplit=record. The split (" ");
A1. The set (lineSplit [0]);
B1. The set (lineSplit [1]);
The context. Write (a1, b1);
}
/*
For (int m=0; m
Jlh1. Set (jiluhao. Get (m));
Jlh2. Set (jiluhao. Get (m));
The context. Write (jlh1 jlh2);
}
*/
/* for (int n=m + 1; N
If (ziduan. Get (m)!=ziduan. Get (n))
{
Jlh1. Set (jiluhao. Get (m));
Jlh2. Set (jiluhao. Get (n));
The context. Write (jlh1 jlh2);
}
}
*/
}
}
Detailed code is as follows:
Data: 1 112008 zhangfeng jisuanji xinxigongcheng
import java.io.IOException;
Import org, apache hadoop. Conf. Configured;
Import org, apache hadoop. Conf. Configuration;
Import org, apache hadoop. Fs. The Path;
Import org, apache hadoop. IO. *;
Import org, apache hadoop. IO. IntWritable;
Import org, apache hadoop. IO. Text;
Import org, apache hadoop. Graphs. *;
Import org, apache hadoop. Graphs. The Job;
Import org, apache hadoop. Graphs. Mapper;
Import org, apache hadoop. Graphs. Reducer;
Import org, apache hadoop. Graphs. Lib. Input. FileInputFormat;
Import org, apache hadoop. Graphs. Lib. Output. FileOutputFormat;
Import org, apache hadoop. Graphs. Lib. Output. TextOutputFormat;
Import org, apache hadoop. Util. Tool;
Import org, apache hadoop. Util. ToolRunner;
Import org, apache hadoop. Util. GenericOptionsParser;
import java.util.ArrayList;
Import the Java. Util. Iterator;
import java.util.List;
Import the Java. Util. StringTokenizer;
Public class YCLyilai extends Configured implements Tool
{
Enum Counter
{
LINESKIP,//chu cuo DE hang
}
Public static class YCLMapper extends Mapper
{
//private final static LongWritable one=new LongWritable (1);
Private Text zhuma=new Text ();
Private Text out=new Text ();
Public void map (LongWritable key, the Text value, Context Context) throws IOException, InterruptedException
{
String linevalue=(https://bbs.csdn.net/topics/value.toString);
String [] relateSplit="1 2 3 4 p and 4 p", the split (" ");
StringTokenizer StringTokenizer=new StringTokenizer (linevalue);
Try
{
String [] lineSplit=linevalue. Split (" ");
String t=null;
String s="";
For (int m=0; m
if(! RelateSplit [m]. Equals (" p "))
{
S +=lineSplit [Integer parseInt (relateSplit) [m]] + "";
}
The else
{
String [] partSplit=s.s plit (" ");
Zhuma. Set (partSplit [1]);
String s1="";
For (int j=2; J
S1 +=partSplit [j];
}
Out. The set (s1 + "" + lineSplit [0]).
The context. Write (zhuma, out);
S="";
}
}
}
The catch (Java. Lang. ArrayIndexOutOfBoundsException e)
{
The context. GetCounter (Counter. LINESKIP). Increment (1);
return;
}
}
}
Public static class YCLReducer extends Reducer
//private LongWritable result=new LongWritable ();
Private Text a1=new Text ();
Private Text b1=new Text ();
Public void the reduce (Text key Iterable
The Context Context
) throws IOException, InterruptedException {
String a;
String b;
The Iterator ite=values. The Iterator ();
While (ite. HasNext ())
{
String record=ite. Next (). The toString ();
String [] lineSplit=record. The split (" ");
A1. The set (lineSplit [0]);
B1. The set (lineSplit [1]);
The context. Write (a1, b1);
}
/*
For (int m=0; m