Return-Path: X-Original-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B4C6799A0 for ; Tue, 17 Apr 2012 03:03:31 +0000 (UTC) Received: (qmail 84631 invoked by uid 500); 17 Apr 2012 03:03:30 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 84575 invoked by uid 500); 17 Apr 2012 03:03:29 -0000 Mailing-List: contact mapreduce-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mapreduce-user@hadoop.apache.org Delivered-To: mailing list mapreduce-user@hadoop.apache.org Received: (qmail 84548 invoked by uid 99); 17 Apr 2012 03:03:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Apr 2012 03:03:28 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bejoy.hadoop@gmail.com designates 209.85.210.176 as permitted sender) Received: from [209.85.210.176] (HELO mail-iy0-f176.google.com) (209.85.210.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Apr 2012 03:03:22 +0000 Received: by iagw33 with SMTP id w33so11248605iag.35 for ; Mon, 16 Apr 2012 20:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=0NI7j23Sb+Ks7lqaOUaXaHtsCUcxXit3QFfoyALr9Vw=; b=pc8sk8fA9pEA9oC0PXzBbk2ZY/Oz7Rcy9Sc198KpL1m63jDKuP1WaVFF9JZeclb2pv yjD+4WuUf3S5u1a1dGc+taWTMVNUQR8Guc5mwpHRVHcOJXu8klae7sSjt1qyoslZRENQ wTVXs9jB3XZE5LD503JWtZTtzwNhx9JJgffNLJ6EO4aC7fmYzXpKQOoB/vI0hVLs7Maa 0kkkCCD6n43dbFbQrLNRuucIepIkIhM/rHwzIn903UXv/qh58s0m+bybOJORGk/ZKrft eggei+GvkjM8G21QN6TI4ggjUZ4tpvetgrRw3unz1RcuvL0voMUlxwtiHRmbug48lLEa jcsA== MIME-Version: 1.0 Received: by 10.50.158.227 with SMTP id wx3mr3780983igb.31.1334631781550; Mon, 16 Apr 2012 20:03:01 -0700 (PDT) Received: by 10.64.143.66 with HTTP; Mon, 16 Apr 2012 20:03:01 -0700 (PDT) In-Reply-To: References: Date: Tue, 17 Apr 2012 08:33:01 +0530 Message-ID: Subject: Re: map and reduce with different value classes From: Bejoy Ks To: mapreduce-user@hadoop.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org HI Bryan =A0 =A0 =A0You can set=A0different=A0key and value types with the following= steps - ensure that the map output key value type is the reducer input key value = type - specify it on your Driver Class as //set map output key value types job.setMapOutputKeyClass(theClass) =A0 job.setMapOutputValueClass(theClass) //set final/reduce output key value types =A0 =A0 =A0 =A0 job.setOutputKeyClass(Text.class); =A0 =A0 =A0 =A0 job.setOutputValueClass(IntWritable.class) If both map output and reduce output key value types are the same you just need to specify the final output types. Regards Bejoy KS On Tue, Apr 17, 2012 at 7:14 AM, Bryan Yeung wrote: > > Hello Everyone, > > I'm relatively new to hadoop mapreduce and I'm trying to get this > simple modification to the WordCount example to work. > > I'm using hadoop-1.0.2, and I've included both a convenient diff and > also attached my new WordCount.java file. > > The thing I am trying to achieve is to have the value class that is > output by the map phase be different than the value class output by > the reduce phase. > > Any help would be greatly appreciated! > > Thanks, > > Bryan > > diff --git a/WordCount.java.orig b/WordCount.java > index 81a6c21..6a768f7 100644 > --- a/WordCount.java.orig > +++ b/WordCount.java > @@ -33,8 +33,8 @@ public class WordCount { > =A0 } > > =A0 public static class IntSumReducer > - =A0 =A0 =A0 extends Reducer { > - =A0 =A0private IntWritable result =3D new IntWritable(); > + =A0 =A0 =A0 extends Reducer { > + =A0 =A0private Text result =3D new Text(); > > =A0 =A0 public void reduce(Text key, Iterable values, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Context context > @@ -43,7 +43,7 @@ public class WordCount { > =A0 =A0 =A0 for (IntWritable val : values) { > =A0 =A0 =A0 =A0 sum +=3D val.get(); > =A0 =A0 =A0 } > - =A0 =A0 =A0result.set(sum); > + =A0 =A0 =A0result.set("" + sum); > =A0 =A0 =A0 context.write(key, result); > =A0 =A0 } > =A0 } > @@ -58,10 +58,11 @@ public class WordCount { > =A0 =A0 Job job =3D new Job(conf, "word count"); > =A0 =A0 job.setJarByClass(WordCount.class); > =A0 =A0 job.setMapperClass(TokenizerMapper.class); > + =A0 =A0 =A0 job.setMapOutputValueClass(IntWritable.class); > =A0 =A0 job.setCombinerClass(IntSumReducer.class); > =A0 =A0 job.setReducerClass(IntSumReducer.class); > =A0 =A0 job.setOutputKeyClass(Text.class); > - =A0 =A0job.setOutputValueClass(IntWritable.class); > + =A0 =A0job.setOutputValueClass(Text.class); > =A0 =A0 FileInputFormat.addInputPath(job, new Path(otherArgs[0])); > =A0 =A0 FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); > =A0 =A0 System.exit(job.waitForCompletion(true) ? 0 : 1);