Search in sources :

Example 1 with HyperLogLogPlus

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());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Test(org.junit.Test)

Example 2 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.Test)

Example 3 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.Test)

Example 4 with HyperLogLogPlus

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");
    }
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 5 with HyperLogLogPlus

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);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Aggregations

HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)63 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 User (uk.gov.gchq.gaffer.user.User)6 Edge (uk.gov.gchq.gaffer.data.element.Edge)5 Element (uk.gov.gchq.gaffer.data.element.Element)5 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)5 Graph (uk.gov.gchq.gaffer.graph.Graph)5 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)5 ArrayList (java.util.ArrayList)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 HashSet (java.util.HashSet)3 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)3 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)3 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)3 CardinalityMergeException (com.clearspring.analytics.stream.cardinality.CardinalityMergeException)2 TreeNode (com.fasterxml.jackson.core.TreeNode)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)2