Search in sources :

Example 31 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)

Example 32 with FreqMap

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

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty.

@Test
public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() throws AccumuloElementConversionException {
    // Given

    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "map").property(TestPropertyNames.PROP_2, "map").build()).type("string", String.class).type("map", new TypeDefinition.Builder().clazz(FreqMap.class).aggregateFunction(new FreqMapAggregator()).serialiser(new FreqMapSerialiser()).build()).build();
    converter = createConverter(schema);
    final Entity entity = new Entity.Builder().vertex("vertex1").property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
    // When 1

    final Value value = converter.getValueFromProperties(TestGroups.ENTITY, entity.getProperties());
    // Then 1
    assertTrue(value.getSize() > 0);
    // When 2
    final Properties properties = converter.getPropertiesFromValue(TestGroups.ENTITY, value);
    // Then 2
    assertEquals(entity.getProperties(), properties);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FreqMapAggregator(uk.gov.gchq.gaffer.function.aggregate.FreqMapAggregator) Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) FreqMapSerialiser(uk.gov.gchq.gaffer.serialisation.FreqMapSerialiser) Test(org.junit.Test)

Example 33 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 34 with FreqMap

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

the class PredicateMapExample method freqMapIsMoreThan2.

public void freqMapIsMoreThan2() {
    // ---------------------------------------------------------
    final PredicateMap function = new PredicateMap("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, null, map1, map2, map3, map4, map5);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) PredicateMap(uk.gov.gchq.koryphe.predicate.PredicateMap) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 35 with FreqMap

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

the class RoadTrafficStringElementGenerator method getVehicleCounts.

private FreqMap getVehicleCounts(final String[] fields) {
    final FreqMap freqMap = new FreqMap();
    for (final RoadTrafficDataField fieldName : RoadTrafficDataField.VEHICLE_COUNTS) {
        Long value;
        try {
            value = Long.parseLong(fields[fieldName.ordinal()]);
        } catch (final ArrayIndexOutOfBoundsException e) {
            value = 0L;
        }
        freqMap.upsert(fieldName.fieldName(), value);
    }
    return freqMap;
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap)

Aggregations

FreqMap (uk.gov.gchq.gaffer.types.FreqMap)62 Test (org.junit.jupiter.api.Test)29 ArrayList (java.util.ArrayList)9 Edge (uk.gov.gchq.gaffer.data.element.Edge)9 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 Date (java.util.Date)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)6 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)6 Configuration (org.apache.hadoop.conf.Configuration)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 Row (org.apache.spark.sql.Row)5 SparkSession (org.apache.spark.sql.SparkSession)5 WrappedArray (scala.collection.mutable.WrappedArray)5 Element (uk.gov.gchq.gaffer.data.element.Element)5 HashMap (java.util.HashMap)4 Key (org.apache.accumulo.core.data.Key)4 Test (org.junit.Test)4 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)4 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)4