Filtering rows using MapReduce (Map only)
we also offer , online and classroom trainings
we support in POC
author: Bharat (sree ram)
contact : 9640892992
_________________________________________________________________________________
author : halitics.blogspot.in (bharat)input file : emp.txt
_____________________
101,amar,m,20000,hyd
102,amala,f,30000,pune
103,siva,m,40000,hyd
104,sivani,f,50000,hyd
105,hari,m,40000,pune
____________________
output expected:
only female rows to be written into output file.
package my.map.red;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class RowFilter{
public static class Map1 extends Mapper<LongWritable,Text,Text,Text> {
public void map(LongWritable k, Text v, Context con) throws IOException, InterruptedException{
String line=v.toString();
String[] words=line.split(",");
String sex=words[3];
if(sex.matches("f"))
if(sex.matches("f"))
con.write(v, new Text());
}
}
public static void main(String[] args) throws Exception {
Configuration c=new Configuration();
String[] files=new GenericOptionsParser(c,args).getRemainingArgs();
Path p1=new Path(files[0]);
Path p2=new Path(files[1]);
Job j = new Job(c,"RowFilter");
j.setJarByClass(RowFilter.class);
j.setMapperClass(Map1.class);
j.setNumReduceTasks(0);
j.setOutputKeyClass(Text.class);
j.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(j,p1);
FileOutputFormat.setOutputPath(j, p2);
FileOutputFormat.setOutputPath(j, p2);
System.exit(j.waitForCompletion(true) ? 0:1);
}
}
Sir row Filter program is not writing the filtered row in output directory.
ReplyDelete