Return-Path: Delivered-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Received: (qmail 53476 invoked from network); 13 Dec 2010 21:28:20 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Dec 2010 21:28:20 -0000 Received: (qmail 85561 invoked by uid 500); 13 Dec 2010 21:28:20 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 85505 invoked by uid 500); 13 Dec 2010 21:28:20 -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 85493 invoked by uid 99); 13 Dec 2010 21:28:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Dec 2010 21:28:20 +0000 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of shrijeet@rocketfuelinc.com designates 209.85.161.47 as permitted sender) Received: from [209.85.161.47] (HELO mail-fx0-f47.google.com) (209.85.161.47) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Dec 2010 21:28:12 +0000 Received: by fxm17 with SMTP id 17so6337786fxm.34 for ; Mon, 13 Dec 2010 13:27:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.87.13 with SMTP id u13mr4328234fal.1.1292275670110; Mon, 13 Dec 2010 13:27:50 -0800 (PST) Received: by 10.223.69.140 with HTTP; Mon, 13 Dec 2010 13:27:50 -0800 (PST) In-Reply-To: <1C091122-8196-42CF-A0D6-7A8B78B7D115@gmail.com> References: <1C091122-8196-42CF-A0D6-7A8B78B7D115@gmail.com> Date: Mon, 13 Dec 2010 13:27:50 -0800 Message-ID: Subject: Re: Passing configuration options to the Map class From: Shrijeet Paliwal To: mapreduce-user@hadoop.apache.org Content-Type: multipart/alternative; boundary=20cf30433e3a44d29d0497516009 X-Virus-Checked: Checked by ClamAV on apache.org --20cf30433e3a44d29d0497516009 Content-Type: text/plain; charset=ISO-8859-1 Hi, configure(JobConf conf)method in http://hadoop.apache.org/common/docs/r0.20.0/api/org/apache/hadoop/mapred/MapReduceBase.html is your friend. Try something like this, public class BobsMapper extends MapReduceBase implements Mapper { private Path out_path = null; /** * Use to configure map job. * Parameters from configure XML can be accessed here. * This will be called once before framework start calling map() iteratively for given input file */ public void configure(JobConf conf) { try { super.configure(conf); //get parameter values from configuration XML out_path = new Path(conf.get("outputPath")); } catch (Exception e) { _log.error("Problem configuring map job. " + e.getMessage()); } } /** the mapper should not be able to access out_path. public void map(...) { } } On Mon, Dec 13, 2010 at 12:54 PM, Eric wrote: > > Hi, > > I'm looking for a way to pass options to my Map class. More specifically, I want my mappers to write to sequence files in a path that I can specify on the command line. I tried setting a variable with: > > Jobconf conf = ........; > conf.set("outputPath", "/foo/bar"); > > (I'm using the deprecated libraries) > > I can not retrieve this setting in my mapper however. Is there another way, or am I doing something wrong? > > Best regards, > Eric --20cf30433e3a44d29d0497516009 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,=A0

configure(JobConf conf)method in=A0http://hadoop.apache.org/common/docs/r0.20.0/api/org= /apache/hadoop/mapred/MapReduceBase.html
is your=A0friend.=A0

Try something like this,=A0

=
public class BobsMapper extends MapReduceBase implements Mapper<Long= Writable, Text, Text, Text>=A0{
=A0=A0 =A0private Path out_path =3D n= ull;
=A0=A0 =A0/**
=A0=A0 =A0 * Use to configure map job.
=A0=A0 =A0 * Parameters from conf= igure XML can be accessed here.
=A0=A0 =A0 * This will be called once be= fore framework start calling map() iteratively for given input file
=A0= =A0 =A0 */
=A0=A0 =A0public void configure(JobConf conf)=A0{
=A0=A0 =A0 =A0 =A0try=A0{
=A0=A0 =A0 =A0 =A0 =A0 =A0super.configure(conf= );
=A0=A0 =A0 =A0 =A0 =A0 =A0//get parameter values from configuration X= ML
=A0=A0 =A0 =A0 =A0=A0=A0=A0 out_path =3D new Path(conf.get("outp= utPath"));
=A0=A0 =A0 =A0 =A0}
=A0=A0 =A0 =A0 =A0catch (Exceptio= n e)=A0{
=A0=A0 =A0 =A0 =A0 =A0 =A0_log.error("Problem configuring map job. &qu= ot; + e.getMessage());
=A0=A0 =A0 =A0 =A0}
=A0=A0 =A0}
=A0=A0
= =A0=A0 =A0/** the mapper should not be able to access=A0out_path.
=A0=A0= =A0public void map(...) {
=A0=A0 =A0}
}

On Mon, Dec 13, 2010 at 12:54 PM, Eric <eric.xkcd@gmail.com> wrote:
>
> Hi,
>
&g= t; I'm looking for a way to pass options to my Map class. More specific= ally, I want my mappers to write to sequence files in a path that I can spe= cify on the command line. I tried setting a variable with:
>
> Jobconf conf =3D ........;
> conf.set("outputPath&q= uot;, "/foo/bar");
>
> (I'm using the deprecated = libraries)
>
> I can not retrieve this setting in my mapper how= ever. Is there another way, or am I doing something wrong?
>
> Best regards,
> Eric
--20cf30433e3a44d29d0497516009--