Search in sources :

Example 11 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class JsonSerialisationConfigIT method shouldSerialiseHyperLogLogPlussesWhenSerialiserModulesConfigured.

@Test
public void shouldSerialiseHyperLogLogPlussesWhenSerialiserModulesConfigured() throws OperationException {
    // Given
    graphFactory.getGraph().execute(new AddElements.Builder().input(new Entity.Builder().vertex("vertex1").group("Cardinality").property("hllp", new HyperLogLogPlus(5, 5)).build()).build(), new User());
    // When
    ResponseEntity<List> elements = post("/graph/operations/execute", new GetAllElements(), List.class);
    Map<String, Object> result = ((List<Map<String, Object>>) elements.getBody()).get(0);
    Map<String, Object> hllp = ((Map<String, Map<String, Map<String, Map<String, Object>>>>) result.get("properties")).get("hllp").get(HyperLogLogPlus.class.getName()).get("hyperLogLogPlus");
    assertNotNull(hllp);
    assertTrue(hllp.containsKey("cardinality"));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) ResponseEntity(org.springframework.http.ResponseEntity) User(uk.gov.gchq.gaffer.user.User) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 12 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusAggregatorTest method setupHllp.

private void setupHllp(final int p, final int sp) {
    hyperLogLogPlus1 = new HyperLogLogPlus(p, sp);
    hyperLogLogPlus1.offer("A");
    hyperLogLogPlus1.offer("B");
    hyperLogLogPlus2 = new HyperLogLogPlus(p, sp);
    hyperLogLogPlus2.offer("C");
    hyperLogLogPlus2.offer("D");
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)

Example 13 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusAggregatorTest method shouldAggregateHyperLogLogPlus.

private void shouldAggregateHyperLogLogPlus() {
    HyperLogLogPlusAggregator hyperLogLogPlusAggregator = new HyperLogLogPlusAggregator();
    HyperLogLogPlus currentState = hyperLogLogPlus1;
    assertEquals(2L, currentState.cardinality());
    currentState = hyperLogLogPlusAggregator.apply(currentState, hyperLogLogPlus2);
    assertEquals(4L, currentState.cardinality());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)

Example 14 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class ToHyperLogLogPlusTest method shouldCreateEmptyWhenNull.

@Test
public void shouldCreateEmptyWhenNull() {
    // Given
    ToHyperLogLogPlus toHyperLogLogPlus = new ToHyperLogLogPlus();
    // When
    HyperLogLogPlus result = toHyperLogLogPlus.apply(null);
    // Then
    assertThat(result.cardinality()).isEqualTo(0);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Example 15 with HyperLogLogPlus

use of com.clearspring.analytics.stream.cardinality.HyperLogLogPlus in project Gaffer by gchq.

the class HyperLogLogPlusIsLessThanTest method setup.

@BeforeAll
public static void setup() {
    hyperLogLogPlusWithCardinality5 = new HyperLogLogPlus(5, 5);
    for (int i = 1; i <= 5; i++) {
        hyperLogLogPlusWithCardinality5.offer(i);
    }
    assertEquals(5L, hyperLogLogPlusWithCardinality5.cardinality());
    hyperLogLogPlusWithCardinality15 = new HyperLogLogPlus(5, 5);
    for (int i = 1; i <= 18; i++) {
        hyperLogLogPlusWithCardinality15.offer(i);
    }
    assertEquals(15L, hyperLogLogPlusWithCardinality15.cardinality());
    hyperLogLogPlusWithCardinality31 = new HyperLogLogPlus(5, 5);
    for (int i = 1; i <= 32; i++) {
        hyperLogLogPlusWithCardinality31.offer(i);
    }
    assertEquals(31L, hyperLogLogPlusWithCardinality31.cardinality());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)58 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)6 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 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 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)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