public class Patent {
public static class Map extends
Mapper<LongWritable, Text, Text, Text> {
//Mapper
/*
*This method takes the input as text data type and and tokenizes input
* by taking whitespace as delimiter. Now key value pair is made and this key
* value pair is passed to reducer.
* @method_arguments key, value, output, reporter
* @return void
*/
//Defining a local variable K of type Text
Text k= new Text();
//Defining a local variable v of type Text
Text v= new Text();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
//Converting the record (single line) to String and storing it in a String variable line
String line = value.toString();
//StringTokenizer is breaking the record (line) according to the delimiter whitespace
StringTokenizer tokenizer = new StringTokenizer(line," ");
//Iterating through all the tokens and forming the key value pair
while (tokenizer.hasMoreTokens()) {
/*
* The first token is going in jiten, second token in jiten1, third token in jiten,
* fourth token in jiten1 and so on.
*/
String jiten= tokenizer.nextToken();
k.set(jiten);
String jiten1= tokenizer.nextToken();
v.set(jiten1);
//Sending to output collector which inturn passes the same to reducer
context.write(k,v);
}
}
}
/*Reducer
*
* Reduce class is static and extends MapReduceBase and implements Reducer
* interface having four hadoop generics type Text, Text, Text, IntWritable.
*/
public static class Reduce extends Reducer<Text, Text, Text, IntWritable> {
@Override
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
//Defining a local variable sum of type int
int sum = 0;
/*
* Iterates through all the values available with a key and add them together
* and give the final result as the key and sum of its values
*/
for(Text x : values)
{
sum++;
}
//Dumping the output in context object
context.write(key, new IntWritable(sum));
}
}
To keep you update visit: www.facebook.com/coebda
public static class Map extends
Mapper<LongWritable, Text, Text, Text> {
//Mapper
/*
*This method takes the input as text data type and and tokenizes input
* by taking whitespace as delimiter. Now key value pair is made and this key
* value pair is passed to reducer.
* @method_arguments key, value, output, reporter
* @return void
*/
//Defining a local variable K of type Text
Text k= new Text();
//Defining a local variable v of type Text
Text v= new Text();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
//Converting the record (single line) to String and storing it in a String variable line
String line = value.toString();
//StringTokenizer is breaking the record (line) according to the delimiter whitespace
StringTokenizer tokenizer = new StringTokenizer(line," ");
//Iterating through all the tokens and forming the key value pair
while (tokenizer.hasMoreTokens()) {
/*
* The first token is going in jiten, second token in jiten1, third token in jiten,
* fourth token in jiten1 and so on.
*/
String jiten= tokenizer.nextToken();
k.set(jiten);
String jiten1= tokenizer.nextToken();
v.set(jiten1);
//Sending to output collector which inturn passes the same to reducer
context.write(k,v);
}
}
}
/*Reducer
*
* Reduce class is static and extends MapReduceBase and implements Reducer
* interface having four hadoop generics type Text, Text, Text, IntWritable.
*/
public static class Reduce extends Reducer<Text, Text, Text, IntWritable> {
@Override
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
//Defining a local variable sum of type int
int sum = 0;
/*
* Iterates through all the values available with a key and add them together
* and give the final result as the key and sum of its values
*/
for(Text x : values)
{
sum++;
}
//Dumping the output in context object
context.write(key, new IntWritable(sum));
}
}
To keep you update visit: www.facebook.com/coebda
No comments:
Post a Comment