use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusSerialiserTest method testSerialiseAndDeserialise.
@Test
public void testSerialiseAndDeserialise() {
final HyperLogLogPlus hyperLogLogPlus1 = new HyperLogLogPlus(5, 5);
hyperLogLogPlus1.offer("A");
hyperLogLogPlus1.offer("B");
long hyperLogLogPlus1PreSerialisationCardinality = hyperLogLogPlus1.cardinality();
final byte[] hyperLogLogPlus1Serialised;
try {
hyperLogLogPlus1Serialised = HYPER_LOG_LOG_PLUS_SERIALISER.serialise(hyperLogLogPlus1);
} catch (SerialisationException exception) {
fail("A Serialisation Exception Occurred");
return;
}
final HyperLogLogPlus hyperLogLogPlus1Deserialised;
try {
hyperLogLogPlus1Deserialised = HYPER_LOG_LOG_PLUS_SERIALISER.deserialise(hyperLogLogPlus1Serialised);
} catch (SerialisationException exception) {
fail("A Serialisation Exception Occurred");
return;
}
assertEquals(hyperLogLogPlus1PreSerialisationCardinality, hyperLogLogPlus1Deserialised.cardinality());
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testEmptyHyperLogLogPlusSketchIsSerialised.
@Test
public void testEmptyHyperLogLogPlusSketchIsSerialised() throws IOException {
// Given
final HyperLogLogPlus sketch = new HyperLogLogPlus(5, 5);
// When / Then
runTestWithSketch(sketch);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method testValidHyperLogLogPlusSketchSerialisedCorrectly.
@Test
public void testValidHyperLogLogPlusSketchSerialisedCorrectly() throws IOException {
// Given
final String testString = "TestString";
final HyperLogLogPlus sketch = new HyperLogLogPlus(5, 5);
sketch.offer(testString);
// When / Then
runTestWithSketch(sketch);
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusJsonDeserialiser method deserialize.
// TODO - See 'Can't create HyperLogLogPlus sketches in JSON'
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus");
if (coreHyperLogLogPlusObject != null) {
final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
final byte[] nodeAsString = jsonNodes.binaryValue();
final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString);
return hyperLogLogPlus;
} else {
throw new IllegalArgumentException("Recieved null or empty HyperLogLogPlus sketch");
}
}
use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.
the class HyperLogLogPlusAggregatorTest method shouldBeNotEqualWhenBothAggregatorsHaveDifferentSketches.
@Test
public void shouldBeNotEqualWhenBothAggregatorsHaveDifferentSketches() throws IOException {
// Given
final HyperLogLogPlusAggregator aggregator1 = new HyperLogLogPlusAggregator();
final HyperLogLogPlusAggregator aggregator2 = new HyperLogLogPlusAggregator();
final HyperLogLogPlus hllp1 = new HyperLogLogPlus(5, 5);
hllp1.offer("A");
hllp1.offer("B");
final HyperLogLogPlus hllp2 = new HyperLogLogPlus(5, 5);
hllp2.offer("A");
hllp2.offer("C");
aggregator1._aggregate(hllp1);
aggregator2._aggregate(hllp2);
// Then
assertNotEquals(aggregator1, aggregator2);
}
Aggregations