Search in sources :

Example 16 with HllSketch

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;
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList)

Example 17 with HllSketch

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);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Example 18 with HllSketch

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);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test)

Example 19 with HllSketch

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);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test)

Example 20 with HllSketch

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());
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch)

Aggregations

HllSketch (com.yahoo.sketches.hll.HllSketch)58 Test (org.testng.annotations.Test)31 DataByteArray (org.apache.pig.data.DataByteArray)30 EvalFunc (org.apache.pig.EvalFunc)18 Test (org.junit.jupiter.api.Test)15 DataBag (org.apache.pig.data.DataBag)14 Tuple (org.apache.pig.data.Tuple)12 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)5 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 Union (com.yahoo.sketches.hll.Union)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 TreeNode (com.fasterxml.jackson.core.TreeNode)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 ArrayList (java.util.ArrayList)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 HllSketchElementGenerator (uk.gov.gchq.gaffer.doc.properties.generator.HllSketchElementGenerator)1