You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 32 Next »

Let's make Hama interfaces with BDD(Behavior Driven Development) style.

Input/Output Formatters

  public void map(ImmutableBytesWritable key, VectorWritable value,
      OutputCollector<ImmutableBytesWritable, VectorWritable> output,
      Reporter reporter) throws IOException {

    /* Do something */
    output.collect(key, value);
  }

  public void reduce(ImmutableBytesWritable key, Iterator<VectorWritable> values,
      OutputCollector<ImmutableBytesWritable, BatchUpdate> output,
      Reporter reporter) throws IOException {

    BatchUpdate batchObj = new BatchUpdate(key.get());
    VectorDatum vector = values.next();
    for (Map.Entry<byte[], Cell> f : vector.entrySet()) {
      batchObj.put(f.getKey(), f.getValue().getValue());
    }

    output.collect(key, batchObj);
  }

Flat file to Matrix Conversion

We also need Input/Output Formatters which convert Text File/Sequence File to Matrix.

For example,

 
  public void map(LongWritable key, Text value,
    OutputCollector<ImmutableBytesWritable, VectorWritable> output, Reporter reporter)
    throws IOException {
      
    String line = value.toString();

    /* Do something */

    output.collect(rowKey, vector);
  }
  • No labels