Home Forums HBase Multi Puts in TableReducer

This topic contains 1 reply, has 2 voices, and was last updated by  Nick Dimiduk 8 months, 1 week ago.

  • Creator
  • #50810

    Joseph Hwang

    Using Put Class to insert Data into HBase with TableReducer. Below is the source.

    public class MyReducer extends TableReducer<CountryData, Text, ImmutableBytesWritable> {

    private final byte[] COLUMN_FAMILY = “INTLCTRY”.getBytes();

    public void reduce(CountryData key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

    long ts = 0;

    String rowKey = key.getCountry();

    Put put = new Put(Bytes.toBytes(rowKey));

    for (Text value : values) {
    String[] columns = value.toString().trim().split(“,”);

    String time = columns[0].replaceAll(“-“, “”);
    ts = Long.parseLong(time);
    // I thought data are accumulate in Put object. But it did not.
    put.add(COLUMN_FAMILY, Bytes.toBytes(“data”), ts, Bytes.toBytes(columns[1]));

    // All Data are not inserted into HBase, but only the newest version.
    context.write(null, put);

    The Data are not accumulated in put object, those are overwritten. So I can see only the last data in hbase.
    How can i insert all data into hbase with tablereducer?
    I need your advice. Thanks in advance.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.

  • Author
  • #51312

    Nick Dimiduk

    Are you sure the timestamp attribute is incrementing with every pass through the loop? The put will accumulate edits but may overwrite previous edits if the coordinates match exactly. The only coordinate that changes with each cell is the timestamp. You can verify the content of the Put before the context.write by calling put.toMap(Integert.MAX_VALUE).

    Also keep in mind that HBase will keep only a limited number of pervious versions, though this is configurable. Also make sure your query is requesting to include all historical versions of the cell data, using Get#setMaxVersions(). A more complete explanation is available in the book http://hbase.apache.org/book/versions.html


Viewing 1 replies (of 1 total)