use of com.yahoo.sketches.hll.HllSketch in project gaffer-doc by gchq.
the class HllSketchElementGenerator method _apply.
@Override
public Iterable<Element> _apply(final String line) {
final List<Element> elements = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
final HllSketch hllSketch = new HllSketch(10);
hllSketch.update("B" + i);
final Entity entity = new Entity.Builder().group("cardinality").vertex("A").property("approxCardinality", hllSketch).build();
elements.add(entity);
}
return elements;
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class ToHllSketchTest method shouldCreateHllSketch.
@Test
public void shouldCreateHllSketch() {
// Given
ToHllSketch toHllSketch = new ToHllSketch();
// When
HllSketch result = toHllSketch.apply("input");
// Then
assertThat(result.getEstimate()).isEqualTo(1);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllSketchSerialiserTest method testSerialiseAndDeserialise.
@Test
public void testSerialiseAndDeserialise() {
final HllSketch sketch = new HllSketch(15);
sketch.update("A");
sketch.update("B");
sketch.update("C");
testSerialiser(sketch);
final HllSketch emptySketch = new HllSketch(15);
testSerialiser(emptySketch);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllpSketchJsonSerialisationTest method testNullHyperLogLogSketchDeserialisedAsEmptySketch.
@Test
public void testNullHyperLogLogSketchDeserialisedAsEmptySketch() throws IOException {
// Given
final String sketchAsString = "{}";
// When
HllSketch hllp = JSONSerialiser.deserialise(sketchAsString, HllSketch.class);
// Then
assertEquals(0, hllp.getEstimate(), 0.001);
}
use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.
the class HllpSketchJsonSerialisationTest method runTestWithSketch.
private void runTestWithSketch(final HllSketch sketch) throws IOException {
// When - serialise
final String json = new String(JSONSerialiser.serialise(sketch));
// Then - serialise
JsonAssert.assertEquals("" + "{\"bytes\":" + new String(JSONSerialiser.serialise(sketch.toCompactByteArray())) + "," + "\"cardinality\":" + sketch.getCompositeEstimate() + "}", json);
// When - deserialise
final HllSketch deserialisedSketch = JSONSerialiser.deserialise(json, HllSketch.class);
// Then - deserialise
assertNotNull(deserialisedSketch);
assertEquals(sketch.getCompositeEstimate(), deserialisedSketch.getEstimate(), 0.0001);
assertArrayEquals(sketch.toCompactByteArray(), deserialisedSketch.toCompactByteArray());
}
Aggregations