size += 1 * getUIDList().size();
for (String uid : v.getUIDList()) { for (String uid : v.getUIDList()) {
if (null != uidList) { count = uidList.getCOUNT(); setListSize(uidList.getUIDList().size());
for (String uuid : uidList.getUIDList()) { Text cf = new Text(datatype); TextUtil.textAppend(cf, uuid);
@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)); }
@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)); }
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 (""); } }
/** * 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; } }
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); } }
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); }