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

Switch to Plain View
MapReduce >> mail # user >> Text Iterable modifying other variable


+
Steven Willis 2012-03-14, 21:34
+
Steven Willis 2012-03-14, 23:49
Copy link to this message
-
Re: Text Iterable modifying other variable
Writable's are reused.  You need to deep copy the "value" into "lastValue".

On Wed, Mar 14, 2012 at 6:49 PM, Steven Willis <[EMAIL PROTECTED]> wrote:
> I seem to have made a few typos in the code. This is how it should read:
>
> /*****************/
> public class MyReducer extends Reducer<Text, Text, Text, Text> {
>    @Override
>    public void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
>        Text value = new Text();
>        Text lastValue = new Text();
>        Iterator<Text> valuesIterator = values.iterator();
>
>        while(valuesIterator.hasNext()) {
>            value = valuesIterator.next();
>            if(!value.equals(lastValue)){
>                context.write(key, value);
>                lastValue = value;
>            }
>        }
>    }
> }
> /*****************/
>
> My description of the problem stands.
>
> -Steven Willis

--
Apache MRUnit - Unit testing MapReduce - http://incubator.apache.org/mrunit/
+
Harsh J 2012-03-16, 07:32
+
Steven Willis 2012-03-16, 14:54