public static Long decodeLinkCount(final Value value) { try { final ExtendedHyperLogLogPlus ehllp = new ExtendedHyperLogLogPlus(value); return (Long.valueOf(ehllp.getCardinality())); } catch (IOException e) { return (Long.valueOf(Long.MIN_VALUE)); } }
public static Value combineStatsLinksEdgeValues(final Object key, final Iterator<Value> valueIterator) { final ExtendedHyperLogLogPlus ehllp = new ExtendedHyperLogLogPlus(); while (valueIterator.hasNext()) { try { ehllp.addAll(new ExtendedHyperLogLogPlus(valueIterator.next())); } catch (final IOException e) { LOG.error("Failed to add the hyperloglog value for {}", key); } } try { return (new Value(ehllp.getBytes())); } catch (final IOException e) { LOG.error("Failed to build the value for {}", key); } // This "should" never be returned, but just in case return (new Value(ERROR_EHLLP_BYTES)); }
/** * Create a STATS link count edge value initialized with a single identifier. * * @param realmedIdentifier * The identifier to add to the STATS link count edge value. * @return A Value or null if there was an error. */ public static Value getStatsLinkValue(final String realmedIdentifier) { try { final ExtendedHyperLogLogPlus hll = new ExtendedHyperLogLogPlus(); hll.offer(realmedIdentifier); return (new Value(hll.getBytes())); } catch (IOException e) { log.warn("Failed to add " + realmedIdentifier + " to HyperLogLog", e); return (null); } }
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 (""); } }