Search in sources :

Example 1 with HBaseTarget

use of org.apache.crunch.io.hbase.HBaseTarget in project crunch by cloudera.

the class WordCountHBaseTest method run.

public void run(Pipeline pipeline) throws IOException {
    Random rand = new Random();
    int postFix = Math.abs(rand.nextInt());
    String inputTableName = "crunch_words_" + postFix;
    String outputTableName = "crunch_counts_" + postFix;
    try {
        HTable inputTable = hbaseTestUtil.createTable(Bytes.toBytes(inputTableName), WORD_COLFAM);
        HTable outputTable = hbaseTestUtil.createTable(Bytes.toBytes(outputTableName), COUNTS_COLFAM);
        int key = 0;
        key = put(inputTable, key, "cat");
        key = put(inputTable, key, "cat");
        key = put(inputTable, key, "dog");
        Scan scan = new Scan();
        scan.addColumn(WORD_COLFAM, null);
        HBaseSourceTarget source = new HBaseSourceTarget(inputTableName, scan);
        PTable<ImmutableBytesWritable, Result> shakespeare = pipeline.read(source);
        pipeline.write(wordCount(shakespeare), new HBaseTarget(outputTableName));
        pipeline.done();
        assertIsLong(outputTable, "cat", 2);
        assertIsLong(outputTable, "dog", 1);
    } finally {
    // not quite sure...
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Random(java.util.Random) HBaseSourceTarget(org.apache.crunch.io.hbase.HBaseSourceTarget) HBaseTarget(org.apache.crunch.io.hbase.HBaseTarget) Scan(org.apache.hadoop.hbase.client.Scan) HTable(org.apache.hadoop.hbase.client.HTable) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

Random (java.util.Random)1 HBaseSourceTarget (org.apache.crunch.io.hbase.HBaseSourceTarget)1 HBaseTarget (org.apache.crunch.io.hbase.HBaseTarget)1 HTable (org.apache.hadoop.hbase.client.HTable)1 Result (org.apache.hadoop.hbase.client.Result)1 Scan (org.apache.hadoop.hbase.client.Scan)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1