AnsweredAssumed Answered

How to extract rows containing specific value using map-reduce?

Question asked by white on May 3, 2016
Latest reply on May 5, 2016 by Hao Zhu

P.S I'm new to developing map-reduce function and want to learn from not-so-typical examples. Can you help ?

Consider I have csv file containing four columns.

For example :

101,87,65,67

102,43,45,40

103,23,56,34

104,65,55,40

105,87,96,40

 

Now, if I want to retrieve "value in first column" of rows containing "40 in last column"

How could I do it using map-reduce  ?

Output of this eg. would be :

40 102

40 104

40 105

 

Please supply code if possible.

Thanks.

 

Edit 1 :

I'm using StringTokenizer. So, in MAPPER function should I use variable say "pos"

and loop through tokens as in

 

pos=0;

while (tokens.hasMoreTokens())

        {

            word.set(tokens.nextToken());

            pos=pos+1;

            if(pos == 1)

            {

                sale = word;

            }

            if(pos==4 && word.equals(40))

            {

                context.write(word, sale);

            }

        }

 

Would this work ?

P.S I have no idea how to traverse through tokens in each line.

Outcomes