Tags { public Deferred<IntVec> getTagsetIDsForTag(final String key, final String value) { AsyncKuduScanner.AsyncKuduScannerBuilder scan = client.newScannerBuilder(table); scan.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGS_KEY_COLUMN, ComparisonOp.EQUAL, key)); scan.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGS_VALUE_COLUMN, ComparisonOp.EQUAL, value)); scan.setProjectedColumnIndexes(TAGSET_ID_PROJECTION); final AsyncKuduScanner scanner = scan.build(); class GetTagCB implements Callback<Deferred<IntVec>, RowResultIterator> { private final IntVec tagsetIDs = IntVec.create(); @Override public Deferred<IntVec> call(RowResultIterator results) { for (RowResult result : results) { tagsetIDs.push(result.getInt(0)); } if (scanner.hasMoreRows()) { return scanner.nextRows().addCallbackDeferring(this); } tagsetIDs.sort(); return Deferred.fromResult(tagsetIDs); } @Override public String toString() { return MoreObjects.toStringHelper(this).add("key", key).add("value", value).toString(); } } return scanner.nextRows().addCallbackDeferring(new GetTagCB()); } Tags(AsyncKuduClient client, KuduTable table); Deferred<Integer> insertTagset(final int id, final SortedMap<String, String> tagset); Deferred<IntVec> getTagsetIDsForTag(final String key, final String value); Deferred<IntVec> getTagsetIDsForTags(Map<String, String> tags);  }
@Test public void testGetTagsetIDsForTag() throws Exception { try (KuduTS ts = KuduTS.openOrCreate(ImmutableList.of(getMasterAddresses()), "testGetTagsetIDsForTag", CreateOptions.defaults())) { Tags tags = ts.getTags(); assertEquals(Integer.valueOf(0), tags.insertTagset(0, tagset("k1", "v1")).join()); assertEquals(Integer.valueOf(1), tags.insertTagset(1, tagset("k1", "v2")).join()); assertEquals(Integer.valueOf(2), tags.insertTagset(2, tagset("k2", "v1")).join()); assertEquals(Integer.valueOf(3), tags.insertTagset(3, tagset("k2", "v2")).join()); assertEquals(Integer.valueOf(4), tags.insertTagset(4, tagset("k1", "v1", "k2", "v1")).join()); assertEquals(Integer.valueOf(5), tags.insertTagset(5, tagset("k1", "v1", "k2", "v2")).join()); assertEquals(Integer.valueOf(6), tags.insertTagset(6, tagset("k1", "v2", "k2", "v1")).join()); assertEquals(Integer.valueOf(7), tags.insertTagset(7, tagset("k1", "v2", "k2", "v2")).join()); assertEquals(ImmutableList.of(0, 4, 5), tags.getTagsetIDsForTag("k1", "v1").join().asList()); assertEquals(ImmutableList.of(3, 5, 7), tags.getTagsetIDsForTag("k2", "v2").join().asList()); assertEquals(ImmutableList.of(), tags.getTagsetIDsForTag("k1", "v3").join().asList()); } }