Uid.List v = Uid.List.parseFrom(value.get());
uidList = Uid.List.parseFrom(value.get()); if (null != uidList) { count = uidList.getCOUNT();
long count = 0; try { uidList = Uid.List.parseFrom(entry.getValue().get()); if (null != uidList) { count = uidList.getCOUNT();
boolean forcedDayRange = false; try { uidList = Uid.List.parseFrom(currentValue.get());
uidList = Uid.List.parseFrom(value.get()); if (null != uidList) { count = uidList.getCOUNT();
if (keyValue != null && keyValue.getValue() != null && keyValue.getValue().getSize() > 0) { try { Uid.List.Builder uidList = Uid.List.parseFrom(keyValue.getValue().get()).toBuilder(); boolean changed = false; for (int i = 0; i < uidList.getUIDList().size(); i++) {
Uid.List resultList = Uid.List.parseFrom(result.get()); assertEquals(resultList.getUIDCount(), 0); assertEquals(resultList.getCOUNT(), 0);
@Test public void testEqualsMax() throws Exception { agg.reset(); List<String> savedUUIDs = new ArrayList<>(); Collection<Value> values = Lists.newArrayList(); for (int i = 0; i < GlobalIndexUidAggregator.MAX; 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()); assertNotNull(resultList); assertEquals(false, resultList.getIGNORE()); assertEquals(resultList.getUIDCount(), (GlobalIndexUidAggregator.MAX)); List<String> resultListUUIDs = resultList.getUIDList(); for (String s : savedUUIDs) assertTrue(resultListUUIDs.contains(s)); }
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 testLessThanMax() throws Exception { agg.reset(); List<String> savedUUIDs = new ArrayList<>(); Collection<Value> values = Lists.newArrayList(); for (int i = 0; i < GlobalIndexUidAggregator.MAX - 1; 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(false, resultList.getIGNORE()); assertEquals(resultList.getUIDCount(), (GlobalIndexUidAggregator.MAX - 1)); List<String> resultListUUIDs = resultList.getUIDList(); for (String s : savedUUIDs) assertTrue(resultListUUIDs.contains(s)); }
@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()); } }
public static String getPrintableValue(final Value value) { if ((value != null) && (value.getSize() > 0)) { try { final Uid.List uidList = Uid.List.parseFrom(value.get()); return (uidList.getUIDList().toString()); } catch (final InvalidProtocolBufferException e1) { try { return (ReflectionToStringBuilder.toString(EdgeValue.decode(value), ToStringStyle.SHORT_PREFIX_STYLE)); } catch (final Exception e2) { try { final ExtendedHyperLogLogPlus ehllp = new ExtendedHyperLogLogPlus(value); return (String.valueOf(ehllp.getCardinality())); } catch (final Exception e3) { logger.error("Could not deserialize protobuff" + e2); } } } } return (""); } }
@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)); }
/** * Determine if we have events. For this to be true * * @param v * @return */ private boolean hasEvents(final Value v) { try { Uid.List protobuf = Uid.List.parseFrom(v.get()); // the protobuf list should be aggregated already return protobuf.getIGNORE() || !protobuf.getUIDList().isEmpty(); } catch (InvalidProtocolBufferException e) { // if we cannot parse the protocol buffer, then we // won't be able to use it for evaluation anyway log.error(e); return false; } }
@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); }