Mapper Class
------------------
package mr;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class JSONMap extends Mapper<LongWritable,Text,Text,NullWritable>{
String Line="";
int lcnt=0;
int rcnt=0;
public void map(LongWritable k,Text v,Context con)throws IOException,InterruptedException{
String data=v.toString().trim();
Line=Line+data;
if(Line.matches("{"))
lcnt++;
if(Line.matches("}"))
rcnt++;
if(cnt==rcnt)
{
con.write(new Text(Line),NullWritable.get());
Line="";
lcnt=0;
rcnt=0;
}
}
}
Driver Class:
------------------
package mr;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class DriveXML {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Configuration c=new Configuration();
Job j=new Job(c,"xmld");
j.setJarByClass(DriveXML.class);
j.setMapperClass(JSONMap.class);
j.setNumReduceTasks(0);
Path ip=new Path(args[0]);
Path op=new Path(args[2]);
FileInputFormat.addInputPath(j,ip);
FileOutputFormat.setOutputPath(j, op);
System.exit(j.waitForCompletion(true)?0:1);
}
}
Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
ReplyDeletebig-data-hadoop-training-institute-in-bangalore
nice blog
ReplyDelete