hadoop - MapReduce program keep counter when reading a text file -


i trying implement map reduce program output diagonal of .txt file. for example, reading file

a***** *b**** **c*** ***d** ****e* *****f 

i'd output abcdef.

the mapper class ve written one:

public class mapperclass extends mapreducebase implements mapper<longwritable, text, text, text> { //hadoop supported data types private static final text t = new text(""); private text word = new text(); //private static int linenumber = 0;    public void map(longwritable key, text value, outputcollector<text, text> output, reporter reporter) throws ioexception   {         //taking 1 line @ time input file         string line = value.tostring();         int linenumber = 0;          word.set(character.tostring(line.charat(linenumber++)));         output.collect(word, t);    } } 

but output is

a * * * * * 

i tried put line-number out of map method still got same result. can help? need find way keep counter gets incremented when read next line file. p.s. think there no need of reducer here dont want sort intermediate results. correct me if wrong. thanks!

use longwritable key parameter provided map method , points line number in processed file.

typically, cannot keep track of linenumber in mapper, file may processed multiple mappers (especially if you're using textinputformat assumes regular text files splittable). kind of global state makes sense in counters.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -