@Override public void operate(FlowProcess flowProcess, BufferCall bufferCall) { Iterator<TupleEntry> it = bufferCall.getArgumentsIterator(); HyperLogLog merged = null; try { while (it.hasNext()) { TupleEntry tupleEntry = it.next(); byte[] serialized = (byte[]) tupleEntry.getObject(0); HyperLogLog hll = HyperLogLog.Builder.build(serialized); if (merged == null) { merged = hll; } else { merged = (HyperLogLog) merged.merge(hll); } } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public HyperLogLog combine(HyperLogLog one, HyperLogLog other) { try { // logger.trace("Combine called merging now " + one.cardinality() + " cardinality of other " // + other.cardinality()); return (HyperLogLog) one.merge(other); } catch (CardinalityMergeException e) { logger.fatal("Cardinality merge exception " + e.getMessage()); e.printStackTrace(); } return zero(); }