Search in sources :

Example 11 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AccumuloRangeIDRetrieverTest method shouldRetieveElementsInRangeBetweenSeeds.

private void shouldRetieveElementsInRangeBetweenSeeds(final AccumuloStore store) throws StoreException {
    // Create set to query for
    final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
    simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0000"), new EntitySeed("0999")));
    // Retrieve elements when less simple entities are provided than the max number of entries for the batch scanner
    final GetElementsOperation<Pair<ElementSeed>, CloseableIterable<Element>> operation = new GetElementsInRanges<>(defaultView, simpleEntityRanges);
    try {
        final AccumuloRangeIDRetriever retriever = new AccumuloRangeIDRetriever(store, operation, new User());
        assertEquals(numEntries, Iterables.size(retriever));
    } catch (IteratorSettingException e) {
        fail("Unable to construct Range Retriever");
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) GetElementsInRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) HashSet(java.util.HashSet) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 12 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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 13 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryIncomingEdgesOnly.

private void testEntitySeedQueryIncomingEdgesOnly(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);
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
    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());
    }
    //Incoming option should find all edges i-B as undirected are both incoming and outgoing.
    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) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 14 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetEntitiesBySeed.

@Test
public void shouldAddAndGetEntitiesBySeed() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the entities
    final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder().addSeed(new EntitySeed(1)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEntityDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
        int index = 0;
        SimpleEntityDataObject obj = resultList.get(index);
        assertEquals(1, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Red", obj.getProperties());
    }
    results.close();
}
Also used : SimpleEntityGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator) User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 15 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetRelatedEdges.

@Test
public void shouldAddAndGetRelatedEdges() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the edges
    final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).addSeed(new EntitySeed(2)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEdgeDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEdgeDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
        assertEquals(3, resultList.size());
        int index = 0;
        SimpleEdgeDataObject obj = resultList.get(index++);
        assertEquals(1, obj.getLeft());
        assertEquals(2, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("121", obj.getProperties());
        obj = resultList.get(index++);
        assertEquals(2, obj.getLeft());
        assertEquals(3, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("231", obj.getProperties());
        obj = resultList.get(index);
        assertEquals(4, obj.getLeft());
        assertEquals(1, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("142", obj.getProperties());
    }
    results.close();
}
Also used : User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SimpleEdgeGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) Test(org.junit.Test)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)107 Test (org.junit.Test)51 Element (uk.gov.gchq.gaffer.data.element.Element)50 User (uk.gov.gchq.gaffer.user.User)43 HashSet (java.util.HashSet)34 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)33 Entity (uk.gov.gchq.gaffer.data.element.Entity)28 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)28 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Edge (uk.gov.gchq.gaffer.data.element.Edge)22 Graph (uk.gov.gchq.gaffer.graph.Graph)22 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ArrayList (java.util.ArrayList)20 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)12 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)12 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)11 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)9