You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by 王瑞军 <pu...@gmail.com> on 2012/04/26 10:57:30 UTC

Passing a value from main() to map()

hello everyone:
        i have a problem.we knew map() has it's own parameter such
as map(Object key, Text value, Context context).
the following is my structure.

public class aaa{
     public static class bbb {
               public void map() {
                         i want use the variable number here;
                         for example;
                         if(number==0) {print xxxxxx}
                    }
            }
    public static void main() {
          we receive a number from the keyboard,for example;
          Scanner input = new Scanner(System.in);
              number = input.nextInt();
    }
}

so how can i do?grateful!

Re: Passing a value from main() to map()

Posted by 王瑞军 <pu...@gmail.com>.
hi ,thank you for reply me.i don't know whether the Job configuration can
work,now i solve it in another way.

i want to pass a value from main to map because i want to do a judge in
map.now i write several map class and judge it in main().

在 2012年4月26日 下午5:58,Devaraj k <de...@huawei.com>写道:

> Hi Wang Ruijun,
>
>    You can do this way,
>
> 1. Set the value in Job configuration with some property name before
> submitting the job.
> 2. Get the value in map() function using the property name from the
> configuration and you can perform the business logic.
>
>
>
> Thanks
> Devaraj
>
> ________________________________________
> From: Ajay Srivastava [Ajay.Srivastava@guavus.com]
> Sent: Thursday, April 26, 2012 2:58 PM
> To: <co...@hadoop.apache.org>
> Subject: Re: Passing a value from main() to map()
>
> Hi,
> It seems that you are trying to code a hadoop job which takes input from
> stdin ?
> As far as I know it is not possible as hadoop job works on input coming in
> batches not on real time streams.
> Please wait for others response as well as I am a beginner and may be
> missing something here.
>
>
> Ajay Srivastava
>
> On 26-Apr-2012, at 2:27 PM, 王瑞军 wrote:
>
> > hello everyone:
> >        i have a problem.we knew map() has it's own parameter such
> > as map(Object key, Text value, Context context).
> > the following is my structure.
> >
> > public class aaa{
> >     public static class bbb {
> >               public void map() {
> >                         i want use the variable number here;
> >                         for example;
> >                         if(number==0) {print xxxxxx}
> >                    }
> >            }
> >    public static void main() {
> >          we receive a number from the keyboard,for example;
> >          Scanner input = new Scanner(System.in);
> >              number = input.nextInt();
> >    }
> > }
> >
> > so how can i do?grateful!
>

RE: Passing a value from main() to map()

Posted by Devaraj k <de...@huawei.com>.
Hi Wang Ruijun,

    You can do this way,

1. Set the value in Job configuration with some property name before submitting the job.
2. Get the value in map() function using the property name from the configuration and you can perform the business logic.



Thanks
Devaraj

________________________________________
From: Ajay Srivastava [Ajay.Srivastava@guavus.com]
Sent: Thursday, April 26, 2012 2:58 PM
To: <co...@hadoop.apache.org>
Subject: Re: Passing a value from main() to map()

Hi,
It seems that you are trying to code a hadoop job which takes input from stdin ?
As far as I know it is not possible as hadoop job works on input coming in batches not on real time streams.
Please wait for others response as well as I am a beginner and may be missing something here.


Ajay Srivastava

On 26-Apr-2012, at 2:27 PM, 王瑞军 wrote:

> hello everyone:
>        i have a problem.we knew map() has it's own parameter such
> as map(Object key, Text value, Context context).
> the following is my structure.
>
> public class aaa{
>     public static class bbb {
>               public void map() {
>                         i want use the variable number here;
>                         for example;
>                         if(number==0) {print xxxxxx}
>                    }
>            }
>    public static void main() {
>          we receive a number from the keyboard,for example;
>          Scanner input = new Scanner(System.in);
>              number = input.nextInt();
>    }
> }
>
> so how can i do?grateful!

Re: Passing a value from main() to map()

Posted by Ajay Srivastava <Aj...@guavus.com>.
Hi,
It seems that you are trying to code a hadoop job which takes input from stdin ?
As far as I know it is not possible as hadoop job works on input coming in batches not on real time streams.
Please wait for others response as well as I am a beginner and may be missing something here.


Ajay Srivastava   

On 26-Apr-2012, at 2:27 PM, 王瑞军 wrote:

> hello everyone:
>        i have a problem.we knew map() has it's own parameter such
> as map(Object key, Text value, Context context).
> the following is my structure.
> 
> public class aaa{
>     public static class bbb {
>               public void map() {
>                         i want use the variable number here;
>                         for example;
>                         if(number==0) {print xxxxxx}
>                    }
>            }
>    public static void main() {
>          we receive a number from the keyboard,for example;
>          Scanner input = new Scanner(System.in);
>              number = input.nextInt();
>    }
> }
> 
> so how can i do?grateful!