HBase Forum

Multi Puts in TableReducer

  • #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.

to create new topics or reply. | New User Registration

  • Author
    Replies
  • #51312
    Nick Dimiduk
    Moderator

    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

You must be to reply to this topic. | Create Account

Support from the Experts

A HDP Support Subscription connects you experts with deep experience running Apache Hadoop in production, at-scale on the most demanding workloads.

Enterprise Support »

Become HDP Certified

Real world training designed by the core architects of Hadoop. Scenario-based training courses are available in-classroom or online from anywhere in the world

Training »

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.