Uid.List v = Uid.List.parseFrom(value.get()); long delta = v.getCOUNT();
uidList = Uid.List.parseFrom(value.get()); if (null != uidList) { count = uidList.getCOUNT();
uidList = Uid.List.parseFrom(entry.getValue().get()); if (null != uidList) { count = uidList.getCOUNT();
uidList = Uid.List.parseFrom(value.get()); if (null != uidList) { count = uidList.getCOUNT(); setListSize(uidList.getUIDList().size());
setCOUNT(other.getCOUNT());
Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(resultList.getUIDCount(), 0); assertEquals(resultList.getCOUNT(), 0);
public void findTop() throws IOException { long count = 0; // Sum the Uid.List (value) count for this term (row) // Copy the starting key or this won't work.... Key startKey = new Key(this.iterator.getTopKey()); do { // Get the shard id and datatype from the colq String colq = this.iterator.getTopKey().getColumnQualifier().toString(); // Parse the UID.List object from the value Uid.List uidList = null; try { uidList = Uid.List.parseFrom(this.iterator.getTopValue().get()); // Add the count for this shard to the total count for the term. count += uidList.getCOUNT(); } catch (InvalidProtocolBufferException e) { count = Long.MAX_VALUE; log.debug("Error deserializing Uid.List at: " + this.iterator.getTopKey()); break; } this.iterator.next(); } while (this.iterator.hasTop() && startKey.equals(this.iterator.getTopKey(), PartialKey.ROW)); key = new Key(startKey); value = new Value(Long.toString(count).getBytes()); }
@Test public void testCount() throws Exception { agg.reset(); UUID uuid = UUID.randomUUID(); // Collect the same UUID five times. Collection<Value> values = Lists.newArrayList(); for (int i = 0; i < 5; i++) { Builder b = createNewUidList(); b.setCOUNT(1); b.setIGNORE(false); b.addUID(uuid.toString()); Uid.List uidList = b.build(); Value val = new Value(uidList.toByteArray()); values.add(val); } Value result = agg.reduce(new Key("key"), values.iterator()); Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(5, resultList.getCOUNT()); assertEquals(false, resultList.getIGNORE()); assertEquals(1, resultList.getUIDCount()); } }
@Test public void testSeenIgnore() throws Exception { Logger.getRootLogger().setLevel(Level.ALL); agg.reset(); Builder b = createNewUidList(); b.setIGNORE(true); b.setCOUNT(0); Uid.List uidList = b.build(); Collection<Value> values = Lists.newArrayList(); Value val = new Value(uidList.toByteArray()); values.add(val); b = createNewUidList(); b.setIGNORE(false); b.setCOUNT(1); b.addUID(UUID.randomUUID().toString()); uidList = b.build(); val = new Value(uidList.toByteArray()); values.add(val); Value result = agg.reduce(new Key("key"), values.iterator()); Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(true, resultList.getIGNORE()); assertEquals(0, resultList.getUIDCount()); assertEquals(1, resultList.getCOUNT()); }
@Test public void testMoreThanMax() throws Exception { agg.reset(); List<String> savedUUIDs = new ArrayList<>(); Collection<Value> values = Lists.newArrayList(); for (int i = 0; i < GlobalIndexUidAggregator.MAX + 10; i++) { Builder b = createNewUidList(); b.setIGNORE(false); String uuid = UUID.randomUUID().toString(); savedUUIDs.add(uuid); b.setCOUNT(1); b.addUID(uuid); Uid.List uidList = b.build(); Value val = new Value(uidList.toByteArray()); values.add(val); } Value result = agg.reduce(new Key("key"), values.iterator()); Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(true, resultList.getIGNORE()); assertEquals(0, resultList.getUIDCount()); assertEquals(resultList.getCOUNT(), (GlobalIndexUidAggregator.MAX + 10)); }
@Test public void testInvalidValueType() throws Exception { Logger log = Logger.getLogger(GlobalIndexUidAggregator.class); Level origLevel = log.getLevel(); log.setLevel(Level.FATAL); Collection<Value> values = Lists.newArrayList(); agg.reset(); Value val = new Value(UUID.randomUUID().toString().getBytes()); values.add(val); Value result = agg.reduce(new Key("key"), values.iterator()); Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(false, resultList.getIGNORE()); assertEquals(0, resultList.getUIDCount()); assertEquals(0, resultList.getCOUNT()); log.setLevel(origLevel); }
public static Tuple3<Long,Boolean,List<String>> parseUids(Key k, Value v) throws IOException { final String dataType = parseDataType(k); Uid.List docIds = Uid.List.parseFrom(v.get()); final boolean ignore = docIds.getIGNORE(); List<String> uids = ignore || docIds.getUIDList() == null ? Collections.emptyList() : Lists.transform(docIds.getUIDList(), s -> dataType + "\u0000" + s.trim()); return Tuples.tuple(docIds.getCOUNT(), ignore, uids); }
/** * @param topValue * @param uids * @throws InvalidProtocolBufferException */ private void validateUids(Value topValue, String... uids) throws InvalidProtocolBufferException { Uid.List v = Uid.List.parseFrom(topValue.get()); Assert.assertEquals(uids.length, v.getCOUNT()); for (String uid : uids) { v.getUIDList().contains(uid); } }
/** * @param topValue * @param uids * @throws InvalidProtocolBufferException */ private void validateRemoval(Value topValue, String... uids) throws InvalidProtocolBufferException { Uid.List v = Uid.List.parseFrom(topValue.get()); Assert.assertEquals(-uids.length, v.getCOUNT()); for (String uid : uids) { v.getREMOVEDUIDList().contains(uid); } }
public static Tuple3<Long,Boolean,List<String>> parseUids(Key k, Value v) throws IOException { final String dataType = parseDataType(k); Uid.List docIds = Uid.List.parseFrom(v.get()); final boolean ignore = docIds.getIGNORE(); List<String> uids = ignore || docIds.getUIDList() == null ? Collections.emptyList() : Lists.transform(docIds.getUIDList(), s -> dataType + "\u0000" + s.trim()); return Tuples.tuple(docIds.getCOUNT(), ignore, uids); }