aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/parallelai/spyglass/hbase/HBaseRecordWriter.java
blob: 1cca13325d2b58bfdab9cbb6f31fe330ff2d2e4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package parallelai.spyglass.hbase;

import java.io.IOException;

import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.mapred.RecordWriter;
import org.apache.hadoop.mapred.Reporter;

/**
 * Convert Reduce output (key, value) to (HStoreKey, KeyedDataArrayWritable)
 * and write to an HBase table
 */
public class HBaseRecordWriter
  implements RecordWriter<ImmutableBytesWritable, Put> {
  private HTable m_table;

  /**
   * Instantiate a TableRecordWriter with the HBase HClient for writing.
   *
   * @param table
   */
  public HBaseRecordWriter(HTable table) {
    m_table = table;
  }

  public void close(Reporter reporter)
    throws IOException {
    m_table.close();
  }

  public void write(ImmutableBytesWritable key,
      Put value) throws IOException {
    m_table.put(new Put(value));
  }
}