Search in sources :

Example 56 with EntitySeed

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

the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.

private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    final Set<EntityId> seeds = new HashSet<>();
    seeds.add(new EntitySeed("C"));
    seeds.add(new EntitySeed("D"));
    final GetElementsWithinSet op = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    // Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
    op.setDirectedType(DirectedType.UNDIRECTED);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results).contains(AccumuloTestData.EDGE_C_D_UNDIRECTED);
    // Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
    final GetElementsWithinSet directedCOop = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    directedCOop.setDirectedType(DirectedType.DIRECTED);
    final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
    assertThat(directedCDResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED);
    final GetElementsWithinSet bothDirectedAndUndirectedOp = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    // Turn off directed / undirected edges only option and check get both the undirected and directed edge
    bothDirectedAndUndirectedOp.setDirectedType(DirectedType.EITHER);
    final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
    assertThat(bothDirectedAndUndirectedResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED, (Element) AccumuloTestData.EDGE_C_D_UNDIRECTED);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) HashSet(java.util.HashSet)

Example 57 with EntitySeed

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

the class GetElementsInRangesHandlerTest method shouldSummarise.

private void shouldSummarise(final AccumuloStore store) throws OperationException {
    // Given - get everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
    final Set<Pair<ElementId, ElementId>> simpleEntityRanges = new HashSet<>();
    simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("1")));
    final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final Output operation = createOperation(simpleEntityRanges, view, IncludeIncomingOutgoingType.EITHER, DirectedType.EITHER);
    // When
    List<Element> results = executeOperation(operation, store);
    // Then
    ElementUtil.assertElementEquals(createSummarisedElements(NUM_ENTRIES), results);
    // Given - this should get everything between 0 and 0799 (again being string ordering 0800 is more than 08)
    simpleEntityRanges.clear();
    simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("08")));
    // When
    results = executeOperation(operation, store);
    // Then
    ElementUtil.assertElementEquals(createSummarisedElements(800), results);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Output(uk.gov.gchq.gaffer.operation.io.Output) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) HashSet(java.util.HashSet)

Example 58 with EntitySeed

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

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryIncomingEdgesOnly.

private void testEntityIdQueryIncomingEdgesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    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(NUM_ENTRIES, 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) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 59 with EntitySeed

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

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryOutgoingEdgesOnly.

private void testEntityIdQueryOutgoingEdgesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    int count = 0;
    for (final Element element : retriever) {
        count++;
        assertEquals(TestGroups.EDGE, element.getGroup());
    }
    // Should find both i-B and i-C edges.
    assertEquals(NUM_ENTRIES * 2, count);
}
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) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 60 with EntitySeed

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

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEdgesAndEntities.

private void testEntityIdQueryEdgesAndEntities(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    try {
        final AccumuloSingleIDRetriever retriever = new AccumuloSingleIDRetriever(store, operation, new User());
        assertEquals(NUM_ENTRIES * 3, Iterables.size(retriever));
    } catch (final IteratorSettingException e) {
        fail("Unable to construct SingleID Retriever");
    }
// Should find both i-B and i-C edges and entities i
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) 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) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)284 Test (org.junit.jupiter.api.Test)122 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)122 Element (uk.gov.gchq.gaffer.data.element.Element)102 User (uk.gov.gchq.gaffer.user.User)92 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)90 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)87 HashSet (java.util.HashSet)71 Graph (uk.gov.gchq.gaffer.graph.Graph)69 Entity (uk.gov.gchq.gaffer.data.element.Entity)65 Edge (uk.gov.gchq.gaffer.data.element.Edge)61 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)55 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)41 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)40 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)38 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)36 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)36 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)35