Search in sources :

Example 1 with ElementSeed

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

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

the class GetJavaRDDOfElementsExample method getJavaRddOfElements.

public void getJavaRddOfElements(final JavaSparkContext sc, final Graph graph) throws OperationException {
    ROOT_LOGGER.setLevel(Level.INFO);
    // Avoid using getMethodNameAsSentence as it messes up the formatting of the "RDD" part
    log("#### get Java RDD of elements\n");
    printGraph();
    ROOT_LOGGER.setLevel(Level.OFF);
    final GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>().addSeed(new EdgeSeed(1, 2, true)).addSeed(new EdgeSeed(2, 3, true)).javaSparkContext(sc).build();
    final JavaRDD<Element> rdd = graph.execute(operation, new User("user01"));
    final List<Element> elements = rdd.collect();
    ROOT_LOGGER.setLevel(Level.INFO);
    printJava("GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>()\n" + "                .addSeed(new EdgeSeed(1, 2, true))\n" + "                .addSeed(new EdgeSeed(2, 3, true))\n" + "                .javaSparkContext(sc)\n" + "                .build();\n" + "JavaRDD<Element> rdd = graph.execute(operation, new User(\"user01\"));\n" + "List<Element> elements = rdd.collect();");
    log("The results are:");
    log("```");
    for (final Element e : elements) {
        log(e.toString());
    }
    log("```");
    ROOT_LOGGER.setLevel(Level.OFF);
}
Also used : User(uk.gov.gchq.gaffer.user.User) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Element(uk.gov.gchq.gaffer.data.element.Element) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed)

Example 3 with ElementSeed

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

the class ExamplesService method getRelatedEdges.

@Override
public GetEdges getRelatedEdges() {
    final GetEdges op = new GetEdges();
    final List<ElementSeed> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntitySeed(1));
    } else if (hasEdges()) {
        seeds.add(new EntitySeed(getEdgeSeed(1, 2).getSource()));
    }
    if (hasEdges()) {
        seeds.add(getEdgeSeed(1, 2));
    }
    op.setSeeds(seeds);
    populateOperation(op);
    return op;
}
Also used : GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed)

Example 4 with ElementSeed

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

the class ExamplesService method getRelatedEntities.

@Override
public GetEntities getRelatedEntities() {
    final GetEntities op = new GetEntities();
    final List<ElementSeed> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntitySeed(1));
    }
    if (hasEdges()) {
        seeds.add(getEdgeSeed(1, 2));
    }
    op.setSeeds(seeds);
    populateOperation(op);
    return op;
}
Also used : ArrayList(java.util.ArrayList) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities)

Example 5 with ElementSeed

use of uk.gov.gchq.gaffer.operation.data.ElementSeed 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)

Aggregations

ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)49 Element (uk.gov.gchq.gaffer.data.element.Element)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 User (uk.gov.gchq.gaffer.user.User)14 ArrayList (java.util.ArrayList)13 HashSet (java.util.HashSet)13 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)13 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)11 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Graph (uk.gov.gchq.gaffer.graph.Graph)7 GetElementsInRanges (uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges)6 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)6 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 Iterator (java.util.Iterator)3