Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
MapReduce, mail # user - Re: Get dynamic values in a user defined class from reducer.


Copy link to this message
-
Re: Get dynamic values in a user defined class from reducer.
Robert Dyer 2013-12-18, 17:39
Generally speaking, static fields are not useful in Hadoop.

The issue you are seeing is that the reducer is running in a separate VM
(possibly on a different node!) and thus the static value you are reading
inside of Mid is actually a separate instantiation of that class and field.

If you have an integer you need to set and read from the driver/mid, you
can use a counter.  E.g.:

http://www.philippeadjiman.com/blog/2010/01/07/hadoop-tutorial-series-issue-3-counters-in-action/

- Robert

On Wed, Dec 18, 2013 at 4:02 AM, unmesha sreeveni <[EMAIL PROTECTED]>wrote:

> Can any one pls suggest a good way
> My scenario:
> i hav
> 1.Driver class
> 2.Mapper class
> 3.reducer class
> 4.Mid class
> After completing mapper it goes to reduce. From reducer it will be going
> to Driver and from driver to Mid class
>
> so i need to get a data from reducer class to Mid class
>  So for that i declared a static variable in reduce and tried to access
> that variable in Mid class.But while executing i am only getting the 0
> value. How to overcome this.
>
>
> Reducer.java
> --------------------
> public  class Reduce extends MapReduceBase
> implements Reducer<Text, IntWritable, Text, IntWritable> {
>  int ig;
> public void reduce(Text key, Iterator<IntWritable> values,
>  OutputCollector<Text, IntWritable> output,
> Reporter reporter) throws IOException {
>                               ig = 9;
> }
> }
> Driver.java
>        gainObj.getcount();
>
>
> Mid.java
> public class Mid{
> public void getcount(String args) throws IOException
> {
>                    //WANT TO GET THE IG VALUE IE "9" HERE So i did like
> this
>                         Reduce r = new Reduce();
>  System.out.println("red "+ r.ig);
> }
> }
> But my result is "0". Not 9.
> How to solve this?
>
>
>
>
> --
> *Thanks & Regards*
>
> Unmesha Sreeveni U.B
>
> *Junior Developer*
>
>
>