You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-user@hadoop.apache.org by web service <wb...@gmail.com> on 2010/10/17 20:31:51 UTC

Initialize Map class

I would want to initialize a Map class with some parameters. How do I do
that ?

-Muncher

Re: Initialize Map class

Posted by Martin Kuhn <ma...@affinitas.de>.
> I would want to initialize a Map class with some parameters. How do I do
> that ?

http://hadoop.apache.org/mapreduce/docs/current/api/org/apache/hadoop/mapreduce/Mapper.html

Re: Initialize Map class

Posted by Yin Lou <yi...@gmail.com>.
You can use this,
public class WordCount {

    public static class Map extends MapReduceBase implements
            Mapper<LongWritable, Text, Text, IntWritable> {

        public void configure(JobConf job) {
             // put your initialization here
        }

        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        private String filename;
        private boolean fopen=false;
        private FSDataOutputStream dos;
        public Map(String fname) {
        .......
        .......
        }
...............
...............
...............
[/code]


On Sun, Oct 17, 2010 at 3:01 PM, web service <wb...@gmail.com> wrote:

> Ok. a bit confused...Noob days.
>
> Did you mean using this method call  -  public *JobConf*(Configuration<http://hadoop.apache.org/common/docs/r0.17.0/api/org/apache/hadoop/conf/Configuration.html> conf,
> Class <http://java.sun.com/j2se/1.5/docs/api/java/lang/Class.html>
>  exampleClass)
> to initialize the Map class ?
>
> So for example, how would I invoke constructor to the below class ?
>
> [code]
> public class WordCount {
>
>     public static class Map extends MapReduceBase implements
>             Mapper<LongWritable, Text, Text, IntWritable> {
>         private final static IntWritable one = new IntWritable(1);
>         private Text word = new Text();
>         private String filename;
>         private boolean fopen=false;
>         private FSDataOutputStream dos;
>         public Map(String fname) {
>         .......
>         .......
>         }
> ...............
> ...............
> ...............
> [/code]
>
>
>
> On Sun, Oct 17, 2010 at 12:38 PM, Owen O'Malley <om...@apache.org>wrote:
>
>>
>> On Oct 17, 2010, at 11:31 AM, web service wrote:
>>
>>  I would want to initialize a Map class with some parameters. How do I do
>>> that ?
>>>
>>
>> The objects that define a MapReduce job are all configured by the job's
>> configuration, which is a string to string map. If your Mapper class
>> implements Configurable, it will be initialized with the job's configuration
>> automatically.
>>
>> -- Owen
>>
>
>

Re: Initialize Map class

Posted by web service <wb...@gmail.com>.
Ok. a bit confused...Noob days.

Did you mean using this method call  -  public
*JobConf*(Configuration<http://hadoop.apache.org/common/docs/r0.17.0/api/org/apache/hadoop/conf/Configuration.html>
conf,
Class <http://java.sun.com/j2se/1.5/docs/api/java/lang/Class.html>
 exampleClass)
to initialize the Map class ?

So for example, how would I invoke constructor to the below class ?

[code]
public class WordCount {

    public static class Map extends MapReduceBase implements
            Mapper<LongWritable, Text, Text, IntWritable> {
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        private String filename;
        private boolean fopen=false;
        private FSDataOutputStream dos;
        public Map(String fname) {
        .......
        .......
        }
...............
...............
...............
[/code]


On Sun, Oct 17, 2010 at 12:38 PM, Owen O'Malley <om...@apache.org> wrote:

>
> On Oct 17, 2010, at 11:31 AM, web service wrote:
>
>  I would want to initialize a Map class with some parameters. How do I do
>> that ?
>>
>
> The objects that define a MapReduce job are all configured by the job's
> configuration, which is a string to string map. If your Mapper class
> implements Configurable, it will be initialized with the job's configuration
> automatically.
>
> -- Owen
>

Re: Initialize Map class

Posted by Owen O'Malley <om...@apache.org>.
On Oct 17, 2010, at 11:31 AM, web service wrote:

> I would want to initialize a Map class with some parameters. How do  
> I do that ?

The objects that define a MapReduce job are all configured by the  
job's configuration, which is a string to string map. If your Mapper  
class implements Configurable, it will be initialized with the job's  
configuration automatically.

-- Owen