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 3FFD6F8D4 for ; Tue, 2 Apr 2013 04:07:11 +0000 (UTC) Received: (qmail 82520 invoked by uid 500); 2 Apr 2013 04:07:06 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 82286 invoked by uid 500); 2 Apr 2013 04:07:05 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 82258 invoked by uid 99); 2 Apr 2013 04:07:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Apr 2013 04:07:04 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of azuryyyu@gmail.com designates 209.85.210.180 as permitted sender) Received: from [209.85.210.180] (HELO mail-ia0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Apr 2013 04:06:58 +0000 Received: by mail-ia0-f180.google.com with SMTP id f27so3036iae.39 for ; Mon, 01 Apr 2013 21:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=u2/4Y5p26SrcRLh2YoF76jLoIaCbdQ0Ypj/Fb5GljD8=; b=qAsEHqIlI8jtcKHcuYsHIzh98+sSCr+xtxtPH/t3E9EVIJCewBJjyxbxkuK6iJDABF Uu56FB0dIoCJ0QXUIuUy1SUUAsUlAG+BFLX5vESpc08LlMuWJxgDKefRKQsokKftyPwJ 58W6jXFfpmTxCRFNbzSWI9ysRVbcy9HF+0ppXgafush8x2RvOEH31IpmCh+mvKEEwjVu QJzTLrLzuVm0sTHxIfohIdkhONI9COjoHIGLDt4HRRbK7blLGaQbwTnJMLRAx6WxJj8V 7lW5FuqLCp6QB+rQSNSuVcGbZmrUUXoJmjIJP7Ib/aP8+p66yJBk8i8YCh5uffyYWOD4 g0zg== MIME-Version: 1.0 X-Received: by 10.50.216.231 with SMTP id ot7mr4656115igc.84.1364875597335; Mon, 01 Apr 2013 21:06:37 -0700 (PDT) Received: by 10.64.26.70 with HTTP; Mon, 1 Apr 2013 21:06:37 -0700 (PDT) In-Reply-To: References: <515A56BF.8050704@gmail.com> Date: Tue, 2 Apr 2013 12:06:37 +0800 Message-ID: Subject: Re: Provide context to map function From: Azuryy Yu To: user@hadoop.apache.org Content-Type: multipart/alternative; boundary=14dae93406cd24609e04d958dd5a X-Virus-Checked: Checked by ClamAV on apache.org --14dae93406cd24609e04d958dd5a Content-Type: text/plain; charset=ISO-8859-1 I supposed your input splits are FileSplit, if not, you need to: InputSplit split = context.getInputSplit(); if (split instanceof FileSplit){ Path path = ((FileSplit)split).getPath(); } On Tue, Apr 2, 2013 at 12:02 PM, Azuryy Yu wrote: > In your map function add following: > > Path currentInput = ((FileSplit)context.getInputSplit()).getPath(); > > then: > > if (currentInput is first ){ > ................ > } > else{ > .................. > } > > > > > On Tue, Apr 2, 2013 at 11:55 AM, Abhinav M Kulkarni < > abhinavkulkarni@gmail.com> wrote: > >> Hi, >> >> I have a following scenario: >> >> >> - Two mappers (acting on two different files) and one reducer >> - The mapper code for two different files is the same, except for >> minor change which depends on which file is being read >> - Essentially assume there is an if statement - if first file is >> being read do this else do this >> >> So how do I provide this context to map function i.e. file name or say a >> boolean flag variable indicating the file being read? >> >> Thanks, >> Abhinav >> > > --14dae93406cd24609e04d958dd5a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I supposed your input splits are FileSplit,= if not, you need to:

InputSplit split =3D context.getInputSpl= it();

if (split instanceof FileSplit){
=A0 Path path = =3D ((FileSplit)split).getPath();
}




On Tue, Apr 2, 2013 at 12:02 PM, Azuryy Yu &l= t;azuryyyu@gmail.co= m> wrote:
In your map funct= ion add following:

Path currentInput =3D ((FileSplit)context.getInpu= tSplit()).getPath();

then:

if (currentInput is first ){
.........= .......
}
else{
..................
}




On Tue, Apr 2, 2013 at 11:55 AM, Abhinav M Kulkarni <abhinavkulkarni@gmail.com> wrote:
=20 =20 =20
Hi,

I have a following scenario:

  • Two mappers (acting on two different files) and one reducer
  • The mapper code for two different files is the same, except for minor change which depends on which file is being read
  • Essentially assume there is an if statement - if first file is being read do this else do this
So how do I provide this context to map function i.e. file name or say a boolean flag variable indicating the file being read?

Thanks,
Abhinav


--14dae93406cd24609e04d958dd5a--