Search in sources :

Example 11 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class FilteringIT method testPostAggregationFilteringProperties.

@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
    // Given
    final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
    final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
    final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(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
    assertNotNull(resultsWithoutFiltering);
    assertEquals(8, resultsWithoutFiltering.size());
    assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(6, resultsWithFiltering.size());
    assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
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.gaffer.function.filter.IsEqual) IsLessThan(uk.gov.gchq.gaffer.function.filter.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) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 12 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class GetAllElementsIT method shouldGetAllElementsWithFilterWithoutSummarisation.

@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
@Test
public void shouldGetAllElementsWithFilterWithoutSummarisation() throws Exception {
    final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
    edge1.putProperty(TestPropertyNames.INT, 100);
    edge1.putProperty(TestPropertyNames.COUNT, 1L);
    final Edge edge2 = edge1.emptyClone();
    edge2.putProperty(TestPropertyNames.INT, 101);
    edge2.putProperty(TestPropertyNames.COUNT, 1L);
    graph.execute(new AddElements.Builder().elements(Arrays.asList((Element) edge1, edge2)).build(), getUser());
    final GetAllElements<Element> op = new GetAllElements.Builder<>().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100, 101))).build()).build()).build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> resultList = Lists.newArrayList(results);
    assertEquals(2, resultList.size());
    assertThat(resultList, IsCollectionContaining.hasItems((Element) edge1, edge2));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Element(uk.gov.gchq.gaffer.data.element.Element) IsIn(uk.gov.gchq.gaffer.function.filter.IsIn) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 13 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class StoreValidationIT method shouldAgeOfDataBasedOnTimestampAndAgeOfFunctionInSchema.

@Test
@TraitRequirement(StoreTrait.STORE_VALIDATION)
public void shouldAgeOfDataBasedOnTimestampAndAgeOfFunctionInSchema() throws OperationException, InterruptedException {
    // Given
    final User user = new User();
    final long now = System.currentTimeMillis();
    final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
    entity.putProperty(TestPropertyNames.TIMESTAMP, now);
    entity.putProperty(TestPropertyNames.INT, 5);
    graph.execute(new AddElements.Builder().elements(Collections.<Element>singleton(entity)).build(), user);
    // When 1 - before age off
    final CloseableIterable<Entity> results1 = graph.execute(new GetEntities.Builder<>().addSeed(new EntitySeed(VERTEX)).build(), user);
    // Then 1
    final List<Entity> results1List = Lists.newArrayList(results1);
    assertEquals(1, results1List.size());
    assertEquals(VERTEX, results1List.get(0).getVertex());
    // Wait until after the age off time
    while (System.currentTimeMillis() - now < AGE_OFF_TIME) {
        Thread.sleep(1000L);
    }
    // When 2 - after age off
    final CloseableIterable<Entity> results2 = graph.execute(new GetEntities.Builder<>().addSeed(new EntitySeed(VERTEX)).build(), user);
    // Then 2
    final List<Entity> results2List = Lists.newArrayList(results2);
    assertTrue(results2List.isEmpty());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 14 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class TransformationIT method shouldTransformExistingProperty.

@Test
@TraitRequirement(StoreTrait.TRANSFORMATION)
public void shouldTransformExistingProperty() throws OperationException {
    // Given
    final GetEntities<EntitySeed> getEntities = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("A1")).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(IdentifierType.VERTEX.name(), TestPropertyNames.STRING).execute(new Concat()).project(TestPropertyNames.STRING).build()).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getEntities, getUser()));
    assertNotNull(results);
    assertEquals(1, results.size());
    for (final Entity result : results) {
        assertEquals("A1,3", result.getProperty(TestPropertyNames.STRING));
    }
}
Also used : Concat(uk.gov.gchq.gaffer.function.transform.Concat) Entity(uk.gov.gchq.gaffer.data.element.Entity) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 15 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class TransformationIT method shouldCreateTransientEntityProperty.

@Test
@TraitRequirement(StoreTrait.TRANSFORMATION)
public void shouldCreateTransientEntityProperty() throws OperationException {
    // Given
    final GetEntities<EntitySeed> getEntities = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("A1")).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.TRANSIENT_1, String.class).transformer(new ElementTransformer.Builder().select(IdentifierType.VERTEX.name(), TestPropertyNames.STRING).execute(new Concat()).project(TestPropertyNames.TRANSIENT_1).build()).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getEntities, getUser()));
    assertNotNull(results);
    assertEquals(1, results.size());
    for (final Entity result : results) {
        assertEquals("A1,3", result.getProperty(TestPropertyNames.TRANSIENT_1));
    }
}
Also used : Concat(uk.gov.gchq.gaffer.function.transform.Concat) Entity(uk.gov.gchq.gaffer.data.element.Entity) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

Test (org.junit.Test)18 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)18 Element (uk.gov.gchq.gaffer.data.element.Element)14 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)10 HashSet (java.util.HashSet)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)5 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)4 User (uk.gov.gchq.gaffer.user.User)4 Concat (uk.gov.gchq.gaffer.function.transform.Concat)3 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)3 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 IsEqual (uk.gov.gchq.gaffer.function.filter.IsEqual)2 IsIn (uk.gov.gchq.gaffer.function.filter.IsIn)2 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)2