Search in sources :

Example 1 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class ToArrayHandlerTest method shouldConvertIterableOfElementIdsToArray.

@Test
public void shouldConvertIterableOfElementIdsToArray() throws OperationException {
    // Given
    final ElementId[] originalArray = new ElementId[] { new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
    final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final ElementId[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertArrayEquals(originalArray, results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 2 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class ToArrayHandlerTest method shouldConvertIterableOfElementsAndElementIdsToArray.

@Test
public void shouldConvertIterableOfElementsAndElementIdsToArray() throws OperationException {
    // Given
    final ElementId[] originalArray = new ElementId[] { new Entity.Builder().group("entity").build(), new Edge.Builder().group("edge").build(), new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
    final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final ElementId[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertArrayEquals(originalArray, results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 3 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AbstractGetRDDHandler method addRanges.

public <INPUT_OP extends Operation & GraphFilters & Input<Iterable<? extends ElementId>>> void addRanges(final AccumuloStore accumuloStore, final Configuration conf, final INPUT_OP operation) throws OperationException {
    final List<Range> ranges = new ArrayList<>();
    for (final ElementId entityId : operation.getInput()) {
        try {
            ranges.addAll(accumuloStore.getKeyPackage().getRangeFactory().getRange(entityId, operation));
        } catch (final RangeFactoryException e) {
            throw new OperationException("Failed to add ranges to configuration", e);
        }
    }
    InputConfigurator.setRanges(AccumuloInputFormat.class, conf, ranges);
}
Also used : ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) OperationException(uk.gov.gchq.gaffer.operation.OperationException) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 4 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId 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 5 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId 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)

Aggregations

ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)58 Test (org.junit.jupiter.api.Test)32 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)29 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)17 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)14 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)14 HashSet (java.util.HashSet)11 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 User (uk.gov.gchq.gaffer.user.User)9 ArrayList (java.util.ArrayList)7 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)7 Test (org.junit.Test)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 Key (org.apache.accumulo.core.data.Key)4