Collecting text in output

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Collecting text in output

Anurup Pavuluri

Hi,

In my Map function I am collecting Text as the output. When I run the
job the job gives a java.io.IOException. The following code is exactly
what I am doing. Did someone else have a similar problem with Text? It
works for IntWritable instead of Text.

    private Text word = new Text();

    public void map(WritableComparable key, Writable value,
        OutputCollector output,
        Reporter reporter) throws IOException {
       
        String line = ((Text)value).toString();
        StringTokenizer itr = new StringTokenizer(line);
        for(int i=0; i<3; i++)
        {
                itr.nextToken();
        }
        String ipAddress = itr.nextToken();
        ipAddress = ipAddress.trim();
        word.set(ipAddress);
        output.collect(word, word);
    }
  }

  public static class Reduce extends MapReduceBase implements Reducer {

    public void reduce(WritableComparable key, Iterator values,
        OutputCollector output,
        Reporter reporter) throws IOException {
        int sum = 0;
        Text word = new Text();
      while (values.hasNext()) {
        sum += ((IntWritable) values.next()).get();
      }
        word.set("word");
        output.collect(key, word);
    }
  }



-- Anurup Pavuluri Graduate Student Information Networking Institute,
Carnegie Mellon University. E-Mail: [hidden email] Phone: 412
726 7193(M)