Search in sources :

Example 51 with HllSketch

use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.

the class HllSketchEntityGeneratorTest method shouldCreateSimpleEntitiesWithProperties.

@Test
public void shouldCreateSimpleEntitiesWithProperties() {
    // Given
    HllSketchEntityGenerator hllSketchEntityGenerator = new HllSketchEntityGenerator();
    hllSketchEntityGenerator.propertyToCopy(PROP1);
    Edge edge = new Edge.Builder().group(TestGroups.ENTITY).source(A).dest(B).property(PROP1, VALUE1).build();
    List<? extends Element> edges = Arrays.asList(edge);
    // When
    Iterable<? extends Element> elements = hllSketchEntityGenerator.apply(edges);
    // Then
    Iterator<? extends Element> elementIterator = elements.iterator();
    Edge edgeResult = (Edge) elementIterator.next();
    Entity entityResultA = (Entity) elementIterator.next();
    Entity entityResultB = (Entity) elementIterator.next();
    assertThat(elementIterator.hasNext()).isFalse();
    assertThat(edgeResult).isEqualTo(edge);
    assertThat(entityResultA.getGroup()).isEqualTo(DEFAULT_ENTITY_GROUP);
    assertThat(entityResultA.getVertex()).isEqualTo(A);
    HllSketch entityCardinalityA = (HllSketch) entityResultA.getProperty(DEFAULT_PROPERTY_NAME);
    assertThat(entityCardinalityA.getEstimate()).isEqualTo(1);
    assertThat(entityResultA.getProperty(PROP1)).isEqualTo(VALUE1);
    assertThat(entityResultB.getGroup()).isEqualTo(DEFAULT_ENTITY_GROUP);
    assertThat(entityResultB.getVertex()).isEqualTo(B);
    HllSketch entityCardinalityB = (HllSketch) entityResultB.getProperty(DEFAULT_PROPERTY_NAME);
    assertThat(entityCardinalityB.getEstimate()).isEqualTo(1);
    assertThat(entityResultB.getProperty(PROP1)).isEqualTo(VALUE1);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Entity(uk.gov.gchq.gaffer.data.element.Entity) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 52 with HllSketch

use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.

the class ToHllSketchTest method shouldCreateEmptyWhenNull.

@Test
public void shouldCreateEmptyWhenNull() {
    // Given
    ToHllSketch toHllSketch = new ToHllSketch();
    // When
    HllSketch result = toHllSketch.apply(null);
    // Then
    assertThat(result.getEstimate()).isEqualTo(0);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Example 53 with HllSketch

use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.

the class HllSketchSerialiserTest method testSerialiser.

private void testSerialiser(final HllSketch sketch) {
    final double cardinality = sketch.getEstimate();
    final byte[] sketchSerialised;
    try {
        sketchSerialised = SERIALISER.serialise(sketch);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final HllSketch sketchDeserialised;
    try {
        sketchDeserialised = SERIALISER.deserialise(sketchSerialised);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    assertEquals(cardinality, sketchDeserialised.getEstimate(), DELTA);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException)

Example 54 with HllSketch

use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.

the class HllpSketchJsonSerialisationTest method testNullHyperLogLogPlusSketchIsSerialisedAsNullString.

@Test
public void testNullHyperLogLogPlusSketchIsSerialisedAsNullString() throws SerialisationException {
    // Given
    final HllSketch sketch = null;
    // When
    final String sketchAsString = new String(JSONSerialiser.serialise(sketch));
    // Then - Serialisation framework will serialise nulls as 'null' string.
    assertEquals("null", sketchAsString);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test)

Example 55 with HllSketch

use of com.yahoo.sketches.hll.HllSketch in project Gaffer by gchq.

the class HllpSketchJsonSerialisationTest method shouldDeserialiseNewHllpWithSAndSpValues.

@Test
public void shouldDeserialiseNewHllpWithSAndSpValues() throws IOException {
    // Given
    final String sketchAsString = "{\"logK\": 20}";
    // When
    HllSketch hllp = JSONSerialiser.deserialise(sketchAsString, HllSketch.class);
    // Then
    assertArrayEquals(new HllSketch(20).toCompactByteArray(), hllp.toCompactByteArray());
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) Test(org.junit.jupiter.api.Test)

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