Return-Path: Delivered-To: apmail-hadoop-common-user-archive@www.apache.org Received: (qmail 22463 invoked from network); 2 Aug 2010 16:24:16 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Aug 2010 16:24:16 -0000 Received: (qmail 21975 invoked by uid 500); 2 Aug 2010 16:24:13 -0000 Delivered-To: apmail-hadoop-common-user-archive@hadoop.apache.org Received: (qmail 21938 invoked by uid 500); 2 Aug 2010 16:24:12 -0000 Mailing-List: contact common-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-user@hadoop.apache.org Delivered-To: mailing list common-user@hadoop.apache.org Received: (qmail 21930 invoked by uid 99); 2 Aug 2010 16:24:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Aug 2010 16:24:12 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of edlinuxguru@gmail.com designates 209.85.212.48 as permitted sender) Received: from [209.85.212.48] (HELO mail-vw0-f48.google.com) (209.85.212.48) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Aug 2010 16:24:06 +0000 Received: by vws2 with SMTP id 2so3124230vws.35 for ; Mon, 02 Aug 2010 09:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=6Qp2u3JV4YrOv8QttPv0t0WQue2PcOKSCFtMpISWrK8=; b=HuRnXji2LsbqdZc+oRH2BtSjq+oDXfymPZ8AH6opXQzU33zGvZQf1lmFwZWDhY5RWE 8lccdiTxk6zetZntQjiBy2f5W4S0HiD/Tcnb4OHMuqVQU5i8+Vi1v7aKA42X2gOkTDNB N40Q7UlG2hHEIrG8GdR/VHU/a+jyKvaGXgGCw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=FkdvS3nd7+Exx6fAsyuGjOCW/ggE6/kMhyfzIpSk7EU9MdJAFIiOBkseYaJlEyXalD HufJt0ghBX3ZpSoiakJyOIR98BDVdKhIj72JmAtxkQYa1kNZPPoDf0NjBlcqTmbFyn4N YzB59Gn6z8wdXXzQI0J9Ws6wW32uZbTKM47Dg= MIME-Version: 1.0 Received: by 10.220.58.138 with SMTP id g10mr4324649vch.270.1280766225436; Mon, 02 Aug 2010 09:23:45 -0700 (PDT) Received: by 10.220.171.193 with HTTP; Mon, 2 Aug 2010 09:23:45 -0700 (PDT) In-Reply-To: References: Date: Mon, 2 Aug 2010 12:23:45 -0400 Message-ID: Subject: Re: Set variables in mapper From: Edward Capriolo To: common-user@hadoop.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Aug 2, 2010 at 12:17 PM, Erik Test wrote: > Hi, > > I'm trying to set a variable in my mapper class by reading an argument fr= om > the command line and then passing the entry to the mapper from main. Is t= his > possible? > > =A0public static void main(String[] args) throws Exception > =A0{ > =A0 =A0JobConf conf =3D new JobConf(DistanceCalc2.class); > =A0 =A0conf.setJobName("Calculate Distances"); > > =A0 =A0conf.setOutputKeyClass(Text.class); > =A0 =A0conf.setOutputValueClass(DoubleWritable.class); > > =A0 =A0conf.setMapperClass(Map.class); > =A0 =A0//conf.setReducerClass(Reduce.class); > > =A0 =A0conf.setInputFormat(TextInputFormat.class); > =A0 =A0conf.setOutputFormat(TextOutputFormat.class); > > =A0 =A0FileInputFormat.setInputPaths(conf, new Path(args[0])); > =A0 =A0FileOutputFormat.setOutputPath(conf, new Path(args[1])); > > =A0 =A0Map.setN(args[2]); > > =A0 =A0JobClient.runJob(conf); > =A0}//main > > > =A0public static class Map extends MapReduceBase > =A0 =A0implements Mapper =A0 =A0 =A0Text, DoubleWritable> > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0 =A0 =A0 =A0 private static int N; > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 public void map(LongWritable key, Text value, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 OutputCollector out= put, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Reporter reporter) throws IOException > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.... > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dim =3D tokens.length / N; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0... > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 public static void setN(String newN) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0N =3D Integer.parseInt(newN); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0} > > I've tried the code above but I get an error saying that I'm dividing by > zero. Obviously, the argument I enter for N isn't being set as specified. > Erik > You can pass variables to the Job using the JobConf class. In your Driver class: jobConf.set("clone_path", clonePath); Then in your mapper / reducer override configure: private JobConf jobConf; public void configure(JobConf jobConf) { super.configure(jobConf); this.jobConf=3DjobConf; }