Multi Puts in TableReducer

to create new topics or reply. | New User Registration

This topic contains 1 reply, has 2 voices, and was last updated by  Nick Dimiduk 1 year, 1 month ago.

  • Creator
    Topic
  • #50810

    Joseph Hwang
    Participant

    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();

    @Override
    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 to reply to this topic. | Create Account

  • Author
    Replies
  • #51312

    Nick Dimiduk
    Participant

    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

    Cheers,
    Nick

    Collapse
Viewing 1 replies (of 1 total)
Hortonworks Data Platform
The Hortonworks Data Platform is a 100% open source distribution of Apache Hadoop that is truly enterprise grade having been built, tested and hardened with enterprise rigor.
Get started with Sandbox
Hortonworks Sandbox is a self-contained virtual machine with Apache Hadoop pre-configured alongside a set of hands-on, step-by-step Hadoop tutorials.
Modern Data Architecture
Tackle the challenges of big data. Hadoop integrates with existing EDW, RDBMS and MPP systems to deliver lower cost, higher capacity infrastructure.