Lets see how to emit double arrays from mapper and process them in reducer
DoubleArrayWritable class
public static class DoubleArrayWritable extends ArrayWritable { public DoubleArrayWritable() { super(DoubleWritable.class); } }
Driver()
job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(DoubleArrayWritable.class); job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(DoubleArrayWritable.class);
map()
import mywritable.DoubleArrayWritable;
public class MyMapper extends
Mapper<Object, Text, IntWritable, DoubleArrayWritable> {
public void map(Object key, Text value, Context context)
{
//Do something............
double[] arr = new double[size];
DoubleArrayWritable arrWritable = new DoubleArrayWritable();
DoubleWritable[] data = new DoubleWritable[size];
for (int k = 0; k < size; k++) {
data[k] = new DoubleWritable(arr[k]);
}
arrWritable.set(data);
context.write(mykey, arrWritable);
}
}
reduce()
import mywritable.DoubleArrayWritable;
public class MyReducer extends
Reducer<IntWritable, DoubleArrayWritable, NullWritable, Text> {
public void reduce(IntWritable key,
Iterable<DoubleArrayWritable> values, Context context){
double[] sum = new double[size];
for (DoubleArrayWritable c : values) {
Writable[] temp = new DoubleWritable[size];
temp = (c.get());
for (int i = 0; i < size; i++) {
sum[i] += Double.parseDouble(temp[i].toString());
}
//Do something and emit values ..................
context.write(out, new Text(emit));
}
}
}
Happy Hadooping.......
Grateful to check out your website, I seem to be ahead to more excellent sites and I wish that you wrote more informative post for us. Well done work.
ReplyDeleteSEO Company in Chennai
it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information.
ReplyDeleteHadoop Training in Hyderabad
Java Training in Hyderabad
Really useful post about hadoop, i have to some information about hadoop online training institute in india.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletehi ,
ReplyDeleteyour post on hadoop doublearraywritables was very useful in my codings do keep posting blogs... Hadoop Training in Velachery | Hadoop Training .
Hadoop Training in Chennai | Hadoop .
Bigdata and hadoop training in hyderabad. thank u a lot for sharing these posts.
ReplyDeletehttp://www.rstrainings.com/hadoop-online-training.html
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteapple service center chennai | ipod service center in chennai | apple iphone service center in chennai | apple service center chennai
Nice blog Content.It is very informative and helpful. Please share more content.
ReplyDeleteBig Data Training in Delhi
Big Data Course in Delhi
Big Data Training institute in Delhi
Its a wonderful post and very helpful, thanks for all this information.
ReplyDeleteHadoop Training in Gurgaon
nice post.salesforce training
ReplyDeletesalesforce online training
salesforce online course