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"));
}
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");
}
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());
}
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);
}
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());
}
Aggregations