use of org.apache.crunch.io.hbase.HBaseSourceTarget 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...
}
}
Aggregations