Search in sources :

Example 16 with IsEqual

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

the class RoadTrafficTestQueries method checkM4Junction17To16RoadUse.

@Test
public void checkM4Junction17To16RoadUse() throws OperationException, ParseException {
    assumeTrue(this.graph.hasTrait(StoreTrait.INGEST_AGGREGATION), "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.");
    assertNotNull(this.graph, "graph is null");
    final GetElements query = new GetElements.Builder().input(new EdgeSeed("M4:17", "M4:16", true)).view(new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsEqual(M4_JUNCTION_17_TO_16_PROPERTIES.get("startDate"))).select("endDate").execute(new IsEqual(M4_JUNCTION_17_TO_16_PROPERTIES.get("endDate"))).build()).build()).build()).build();
    try (final CloseableIterable<? extends Element> elements = this.graph.execute(query, this.user)) {
        CloseableIterator<? extends Element> iter = elements.iterator();
        assertThat(iter).hasNext();
        final Element element = iter.next();
        assertFalse(iter.hasNext(), "Expected query to return only 1 element, but it has returned multiple!");
        assertEquals(M4_JUNCTION_17_TO_16_PROPERTIES, element.getProperties());
    }
}
Also used : EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 17 with IsEqual

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

the class FilteringIT method testFilteringProperties.

@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() 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().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(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("A3", "D3", false), getEdge("A3", "C3", false), getEdge("A5", "B5", 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 IsEqual

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

the class FilteringIT method testPostAggregationFilteringIdentifiers.

@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.INGEST_AGGREGATION })
public void testPostAggregationFilteringIdentifiers() throws OperationException {
    // Given
    final List<ElementId> seeds = Collections.singletonList(new EntitySeed("A3"));
    final GetElements getElementsWithoutFiltering = new GetElements.Builder().input(seeds).build();
    final GetElements getElementsWithFiltering = new GetElements.Builder().input(seeds).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.DESTINATION.name()).execute(new IsEqual("B3")).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
    assertThat(resultsWithoutFiltering).hasSize(9);
    ElementUtil.assertElementEquals(resultsWithoutFiltering, Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A3")));
    // Then - with filtering
    assertThat(resultsWithFiltering).hasSize(3);
    ElementUtil.assertElementEquals(resultsWithFiltering, Arrays.asList(getEdge("A3", "B3", false), getEdge("A3", "B3", true), getEntity("A3")));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) 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 19 with IsEqual

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

the class FilteringIT method testFilteringIdentifiers.

@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringIdentifiers() throws OperationException {
    // Given
    final List<ElementId> seeds = Collections.singletonList(new EntitySeed("A3"));
    final GetElements getElementsWithoutFiltering = new GetElements.Builder().input(seeds).build();
    final GetElements getElementsWithFiltering = new GetElements.Builder().input(seeds).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.DESTINATION.name()).execute(new IsEqual("B3")).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
    assertThat(resultsWithoutFiltering).hasSize(9);
    ElementUtil.assertElementEquals(resultsWithoutFiltering, Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A3")));
    // Then - with filtering
    assertThat(resultsWithFiltering).hasSize(3);
    ElementUtil.assertElementEquals(resultsWithFiltering, Arrays.asList(getEdge("A3", "B3", false), getEdge("A3", "B3", true), getEntity("A3")));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) 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 20 with IsEqual

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

the class GetAdjacentIdsTest method shouldFailValidationWhenEntityHasFilter.

@Test
public void shouldFailValidationWhenEntityHasFilter() throws OperationException {
    // Given
    final Graph graph = GetAllElementsHandlerTest.getGraph();
    final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
    graph.execute(addElements, new User());
    // When / Then
    try {
        final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).entity(GetAllElementsHandlerTest.BASIC_ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.PROPERTY1).execute(new IsEqual("string")).build()).build()).build()).build();
        final CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
        fail("Exception expected");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("View should not have entities with filters."));
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) 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) Graph(uk.gov.gchq.gaffer.graph.Graph) 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) Test(org.junit.jupiter.api.Test)

Aggregations

IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)20 Test (org.junit.jupiter.api.Test)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)16 Element (uk.gov.gchq.gaffer.data.element.Element)12 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)10 Test (org.junit.Test)7 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)7 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)7 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)6 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)6 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)6 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)6 Or (uk.gov.gchq.koryphe.impl.predicate.Or)6 Graph (uk.gov.gchq.gaffer.graph.Graph)5 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)4 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)4 User (uk.gov.gchq.gaffer.user.User)4