Search in sources :

Example 1 with PredicateMap

use of uk.gov.gchq.koryphe.predicate.PredicateMap in project gaffer-doc by gchq.

the class PredicateMapExample method mapWithDateKeyHasAValueThatExists.

public void mapWithDateKeyHasAValueThatExists() {
    // ---------------------------------------------------------
    final PredicateMap function = new PredicateMap(new Date(0L), new Exists());
    // ---------------------------------------------------------
    final Map<Date, Long> map1 = new HashMap<>();
    map1.put(new Date(0L), 1L);
    final Map<Date, Long> map2 = new HashMap<>();
    map2.put(new Date(), 2L);
    runExample(function, null, map1, map2);
}
Also used : HashMap(java.util.HashMap) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) PredicateMap(uk.gov.gchq.koryphe.predicate.PredicateMap) Date(java.util.Date)

Example 2 with PredicateMap

use of uk.gov.gchq.koryphe.predicate.PredicateMap in project gaffer-doc by gchq.

the class PredicateMapExample method freqMapIsMoreThanOrEqualTo2.

public void freqMapIsMoreThanOrEqualTo2() {
    // ---------------------------------------------------------
    final PredicateMap function = new PredicateMap("key1", new IsMoreThan(2L, true));
    // ---------------------------------------------------------
    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 3 with PredicateMap

use of uk.gov.gchq.koryphe.predicate.PredicateMap 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 4 with PredicateMap

use of uk.gov.gchq.koryphe.predicate.PredicateMap in project Gaffer by gchq.

the class RoadTrafficTestQueries method checkRoadJunctionsInSouthWestHeavilyUsedByBusesIn2000.

@Test
public void checkRoadJunctionsInSouthWestHeavilyUsedByBusesIn2000() throws OperationException, ParseException {
    assumeTrue(this.graph.hasTrait(StoreTrait.QUERY_AGGREGATION), "Skipping test as the store does not implement required trait.");
    assumeTrue(this.graph.hasTrait(StoreTrait.TRANSFORMATION), "Skipping test as the store does not implement required trait.");
    assumeTrue(this.graph.hasTrait(StoreTrait.PRE_AGGREGATION_FILTERING), "Skipping test as the store does not implement required trait.");
    assumeTrue(this.graph.hasTrait(StoreTrait.POST_AGGREGATION_FILTERING), "Skipping test as the store does not implement required trait.");
    assertNotNull(this.graph, "graph is null");
    final Date JAN_01_2000 = new SimpleDateFormat("yyyy-MM-dd").parse("2000-01-01");
    final Date JAN_01_2001 = new SimpleDateFormat("yyyy-MM-dd").parse("2001-01-01");
    final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_2000, true)).select("endDate").execute(new IsLessThan(JAN_01_2001, false)).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
    Set<String> resultSet = new HashSet<>();
    final Iterable<? extends String> results = this.graph.execute(opChain, this.user);
    for (final String r : results) {
        resultSet.add(r);
    }
    assertEquals(SW_ROAD_JUNCTIONS_WITH_HEAVY_BUS_USAGE_IN_2000, resultSet);
}
Also used : CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) PredicateMap(uk.gov.gchq.koryphe.predicate.PredicateMap) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) HashSet(java.util.HashSet) FreqMapExtractor(uk.gov.gchq.gaffer.types.function.FreqMapExtractor) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Date(java.util.Date) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.jupiter.api.Test)

Aggregations

PredicateMap (uk.gov.gchq.koryphe.predicate.PredicateMap)4 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)3 Date (java.util.Date)2 FreqMap (uk.gov.gchq.gaffer.types.FreqMap)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 CsvGenerator (uk.gov.gchq.gaffer.data.generator.CsvGenerator)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 FreqMapExtractor (uk.gov.gchq.gaffer.types.function.FreqMapExtractor)1 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)1 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)1