Search in sources :

Example 16 with IsLessThan

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

the class IsLessThanExample method isLessThan5.

public void isLessThan5() {
    // ---------------------------------------------------------
    final IsLessThan function = new IsLessThan(5);
    // ---------------------------------------------------------
    runExample(function, null, 1, 1L, 5, 5L, 10, 10L, "1");
}
Also used : IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan)

Example 17 with IsLessThan

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

the class FilteringIT method testPostAggregationFilteringProperties.

@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.INGEST_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
    // Given
    final List<ElementId> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
    final GetElements getElementsWithoutFiltering = new GetElements.Builder().input(seeds).build();
    final GetElements getElementsWithFiltering = new GetElements.Builder().input(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
    // When - without filtering
    final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
    // When - with filtering
    final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
    // Then - without filtering
    List<Element> expectedResults = Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A3"), getEntity("A5"), getEntity("B5"));
    ElementUtil.assertElementEquals(expectedResults, resultsWithoutFiltering);
    // Then - with filtering
    List<Element> expectedFilteredResults = Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A5"));
    ElementUtil.assertElementEquals(expectedFilteredResults, resultsWithFiltering);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 18 with IsLessThan

use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan 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)

Example 19 with IsLessThan

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

the class JavaPredicateToParquetPredicate method getPrimitiveFilter.

public FilterPredicate getPrimitiveFilter(final Predicate filterFunction, final String selection, final String group, final SchemaUtils schemaUtils) throws SerialisationException {
    // All supported filters will be in the if else statement below
    if (filterFunction instanceof IsEqual) {
        final IsEqual isEqual = (IsEqual) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isEqual.getControlValue());
        return getIsEqualFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsLessThan) {
        final IsLessThan isLessThan = (IsLessThan) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isLessThan.getControlValue());
        if (isLessThan.getOrEqualTo()) {
            return getIsLessThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
        }
        return getIsLessThanFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsMoreThan) {
        final IsMoreThan isMoreThan = (IsMoreThan) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isMoreThan.getControlValue());
        if (isMoreThan.getOrEqualTo()) {
            return getIsMoreThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
        }
        return getIsMoreThanFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsTrue) {
        return eq(booleanColumn(selection), true);
    } else if (filterFunction instanceof IsFalse) {
        return eq(booleanColumn(selection), false);
    } else {
        fullyApplied = false;
        LOGGER.warn(filterFunction.getClass().getCanonicalName() + " is not a natively supported filter by the Parquet store, therefore execution will take longer to perform this filter.");
        return null;
    }
}
Also used : IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual)

Example 20 with IsLessThan

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

the class GetWalksIT method shouldGetPathsWithPreFiltering_2.

@Test
@TraitRequirement(StoreTrait.POST_AGGREGATION_FILTERING)
public void shouldGetPathsWithPreFiltering_2() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final OperationChain operationChain = new OperationChain.Builder().first(new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsLessThan(3)).build()).build()).build()).build()).then(operation).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operationChain, operationChain).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)20 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 Test (org.junit.jupiter.api.Test)6 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)6 TupleAdaptedPredicate (uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate)6 ArrayList (java.util.ArrayList)5 GreaterThan (org.apache.spark.sql.sources.GreaterThan)5 LessThan (org.apache.spark.sql.sources.LessThan)5 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)5 HashSet (java.util.HashSet)4 Predicate (java.util.function.Predicate)4 SparkSession (org.apache.spark.sql.SparkSession)4 Filter (org.apache.spark.sql.sources.Filter)4 Operation (uk.gov.gchq.gaffer.operation.Operation)4 GraphFilters (uk.gov.gchq.gaffer.operation.graph.GraphFilters)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 EqualTo (org.apache.spark.sql.sources.EqualTo)3