Search in sources :

Example 11 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapSerialiserTest method shouldSerialiseDeserialiseFreqMapWithAnEmptyKey.

@Test
public void shouldSerialiseDeserialiseFreqMapWithAnEmptyKey() throws SerialisationException {
    // Given
    final FreqMap freqMap = new FreqMap();
    freqMap.put("", 10L);
    freqMap.put("y", 5L);
    freqMap.put("z", 20L);
    // When
    final byte[] serialised = serialiser.serialise(freqMap);
    final FreqMap deserialised = (FreqMap) serialiser.deserialise(serialised);
    assertEquals((Long) 10L, deserialised.get(""));
    assertEquals((Long) 5L, deserialised.get("y"));
    assertEquals((Long) 20L, deserialised.get("z"));
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Test(org.junit.Test)

Example 12 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class MapFilterExample method freqMapIsMoreThan2.

public void freqMapIsMoreThan2() {
    // ---------------------------------------------------------
    final MapFilter function = new MapFilter("key1", new IsMoreThan(2L));
    // ---------------------------------------------------------
    final FreqMap map1 = new FreqMap();
    map1.put("key1", 1L);
    final FreqMap map2 = new FreqMap();
    map2.put("key1", 2L);
    final FreqMap map3 = new FreqMap();
    map3.put("key1", 3L);
    final FreqMap map4 = new FreqMap();
    map4.put("key1", 3L);
    map4.put("key2", 0L);
    final FreqMap map5 = new FreqMap();
    map5.put("key2", 3L);
    runExample(function, map1, map2, map3, map4, map5);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) MapFilter(uk.gov.gchq.gaffer.function.MapFilter) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan)

Example 13 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapConverterTest method testConverter.

@Test
public void testConverter() throws ConversionException {
    final FreqMap freqMap = new FreqMap();
    freqMap.put("x", 10L);
    freqMap.put("y", 5L);
    freqMap.put("z", 20L);
    final scala.collection.mutable.Map<String, Long> expectedResult = scala.collection.mutable.Map$.MODULE$.empty();
    expectedResult.put("x", 10L);
    expectedResult.put("y", 5L);
    expectedResult.put("z", 20L);
    assertEquals(expectedResult, FREQ_MAP_CONVERTER.convert(freqMap));
    final FreqMap emptyFreqMap = new FreqMap();
    expectedResult.clear();
    assertEquals(expectedResult, FREQ_MAP_CONVERTER.convert(emptyFreqMap));
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Test(org.junit.Test)

Example 14 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapAggregatorTest method shouldCloneAggregator.

@Test
public void shouldCloneAggregator() {
    // Given
    final FreqMapAggregator aggregator = new FreqMapAggregator();
    final FreqMap freqMap1 = new FreqMap();
    freqMap1.put("1", 2L);
    freqMap1.put("2", 3L);
    aggregator._aggregate(freqMap1);
    // When
    final FreqMapAggregator clone = aggregator.statelessClone();
    // Then
    assertNotSame(aggregator, clone);
    assertNull((clone.state()[0]));
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 15 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapIsMoreThanTest method shouldRejectEmptyMaps.

@Test
public void shouldRejectEmptyMaps() {
    // Given
    final MapFilter filter = new MapFilter(KEY1, new IsMoreThan(0L));
    // When
    boolean accepted = filter.isValid(new Object[] { new FreqMap() });
    // Then
    assertFalse(accepted);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Aggregations

FreqMap (uk.gov.gchq.gaffer.types.FreqMap)16 Test (org.junit.Test)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 MapFilter (uk.gov.gchq.gaffer.function.MapFilter)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2 ArrayList (java.util.ArrayList)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)2 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Value (org.apache.accumulo.core.data.Value)1 Properties (uk.gov.gchq.gaffer.data.element.Properties)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)1 FreqMapAggregator (uk.gov.gchq.gaffer.function.aggregate.FreqMapAggregator)1 FreqMapSerialiser (uk.gov.gchq.gaffer.serialisation.FreqMapSerialiser)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1