Search in sources :

Example 41 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class FilteringIT method testFilteringProperties.

@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() 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().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
    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 42 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GetAllElementsIT method shouldGetAllElements.

protected void shouldGetAllElements(boolean includeEntities, final IncludeEdgeType includeEdgeType) throws Exception {
    // Given
    final List<Element> expectedElements = new ArrayList<>();
    if (includeEntities) {
        expectedElements.addAll(getEntities().values());
    }
    for (final Edge edge : getEdges().values()) {
        if (IncludeEdgeType.ALL == includeEdgeType || (edge.isDirected() && IncludeEdgeType.DIRECTED == includeEdgeType) || (!edge.isDirected() && IncludeEdgeType.UNDIRECTED == includeEdgeType)) {
            expectedElements.add(edge);
        }
    }
    final GetAllElements<Element> op = new GetAllElements.Builder<>().includeEntities(includeEntities).includeEdges(includeEdgeType).populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> expectedElementsCopy = Lists.newArrayList(expectedElements);
    for (final Element result : results) {
        final ElementSeed seed = ElementSeed.createSeed(result);
        if (result instanceof Entity) {
            Entity entity = (Entity) result;
            assertTrue("Entity was not expected: " + entity, expectedElements.contains(entity));
        } else {
            Edge edge = (Edge) result;
            if (edge.isDirected()) {
                assertTrue("Edge was not expected: " + edge, expectedElements.contains(edge));
            } else {
                final Edge edgeReversed = new Edge(TestGroups.EDGE, edge.getDestination(), edge.getSource(), edge.isDirected());
                expectedElementsCopy.remove(edgeReversed);
                assertTrue("Edge was not expected: " + seed, expectedElements.contains(result) || expectedElements.contains(edgeReversed));
            }
        }
        expectedElementsCopy.remove(result);
    }
    assertEquals("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy, expectedElements.size(), Lists.newArrayList(results).size());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 43 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testUndirectedEdgeSeedQueries.

private void testUndirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("B", edge.getDestination());
    }
    //We should have only 1000 returned the i-B edges that are undirected
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 44 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEdgesOnly.

private void testEntitySeedQueryEdgesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEntities(false);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    //Should find both i-B and i-C edges.
    assertEquals(numEntries * 2, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 45 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testDirectedEdgeSeedQueries.

private void testDirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.DIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("C", edge.getDestination());
    }
    //Should find 1000 only A-C
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Aggregations

View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)107 Test (org.junit.Test)70 Element (uk.gov.gchq.gaffer.data.element.Element)42 User (uk.gov.gchq.gaffer.user.User)38 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)32 HashSet (java.util.HashSet)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 Graph (uk.gov.gchq.gaffer.graph.Graph)20 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)19 ArrayList (java.util.ArrayList)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 Edge (uk.gov.gchq.gaffer.data.element.Edge)13 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)12 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)11 SQLContext (org.apache.spark.sql.SQLContext)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8