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> words = pipeline.read(source);
PCollection<Put> puts = wordCount(words);
pipeline.write(puts, new HBaseTarget(outputTableName));
pipeline.write(puts, new HBaseTarget(otherTableName));
pipeline.done();
assertIsLong(outputTable, "cat", 2);
assertIsLong(outputTable, "dog", 1);
assertIsLong(otherTable, "cat", 2);
assertIsLong(otherTable, "dog", 1);
// verify we can do joins.
HTable joinTable = hbaseTestUtil.createTable(Bytes.toBytes(joinTableName), WORD_COLFAM);
key = 0;
key = put(joinTable, key, "zebra");
key = put(joinTable, key, "donkey");
key = put(joinTable, key, "bird");
key = put(joinTable, key, "horse");
Scan joinScan = new Scan();
joinScan.addColumn(WORD_COLFAM, null);
PTable<ImmutableBytesWritable, Result> other = pipeline.read(FromHBase.table(joinTableName, joinScan));
PCollection<String> joined = words.join(other).parallelDo(new StringifyFn(), Writables.strings());
assertEquals(ImmutableSet.of("cat,zebra", "cat,donkey", "dog,bird"),
ImmutableSet.copyOf(joined.materialize()));
pipeline.done();
//verify HBaseTarget supports deletes.
Scan clearScan = new Scan();
clearScan.addColumn(COUNTS_COLFAM, null);
pipeline = new MRPipeline(WordCountHBaseIT.class, hbaseTestUtil.getConfiguration());
HBaseSourceTarget clearSource = new HBaseSourceTarget(outputTableName, clearScan);
PTable<ImmutableBytesWritable, Result> counts = pipeline.read(clearSource);
pipeline.write(clearCounts(counts), new HBaseTarget(outputTableName));
pipeline.done();
assertDeleted(outputTable, "cat");