Search in sources :

Example 6 with GetElementsBetweenSets

use of uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets in project Gaffer by gchq.

the class AccumuloIDBetweenSetsRetrieverTest method shouldDealWithOutgoingEdgesOnlyOption.

/**
     * Tests that the options to set outgoing edges or incoming edges only options work correctly.
     */
private void shouldDealWithOutgoingEdgesOnlyOption(final AccumuloStore store) {
    try {
        /*
             Create table
             (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator,
             and sets the age off iterator to age data off after it is more than ageOffTimeInMilliseconds milliseconds old).
              */
        final Set<Element> data = new HashSet<>();
        data.add(AccumuloTestData.EDGE_A1_B1);
        data.add(AccumuloTestData.EDGE_B2_A2);
        addElements(data, store, new User());
        // Query for edges between {A1} and {B1}, with outgoing edges only. Should get the edge A1>B1.
        final AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> opA1B1 = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A1_SET, AccumuloTestData.SEED_B1_SET, defaultView);
        opA1B1.setIncludeEntities(false);
        opA1B1.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
        final Set<Element> a1B1OutgoingEdgeResults = returnElementsFromOperation(store, opA1B1, new User(), false);
        assertThat(a1B1OutgoingEdgeResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A1_B1));
        // Query for edges between {A1} and {B1}, with incoming edges only. Should get nothing.
        opA1B1.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
        final Set<Element> a1B1EdgeIncomingResults = returnElementsFromOperation(store, opA1B1, new User(), false);
        assertEquals(0, a1B1EdgeIncomingResults.size());
        // Query for edges between {A2} and {B2}, with incoming edges only. Should get the edge B2->A2.
        final AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> opA2B2 = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A2_SET, AccumuloTestData.SEED_B2_SET, defaultView);
        opA2B2.setIncludeEntities(false);
        opA2B2.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
        final Set<Element> a2B2EdgeIncomingResults = returnElementsFromOperation(store, opA2B2, new User(), false);
        assertThat(a2B2EdgeIncomingResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_B2_A2));
        // Query for edges between {A2} and {B2}, with outgoing edges only. Should get nothing.
        opA2B2.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
        final Set<Element> a2B2EdgeOutgoingResults = returnElementsFromOperation(store, opA2B2, new User(), false);
        assertEquals(0, a2B2EdgeOutgoingResults.size());
    } catch (StoreException e) {
        fail("Failed to set up graph in Accumulo with exception: " + e);
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 7 with GetElementsBetweenSets

use of uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method shouldHaveNoIncomingEdges.

private void shouldHaveNoIncomingEdges(final AccumuloStore store) throws OperationException {
    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 GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, view);
    op.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
    final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
    final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
    //The result size should be 1
    assertEquals(1, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItem(expectedEntity1));
    elements.close();
}
Also used : GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) 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)

Example 8 with GetElementsBetweenSets

use of uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method shouldReturnOnlyEdgesWhenOptionSet.

private void shouldReturnOnlyEdgesWhenOptionSet(final AccumuloStore store) throws OperationException {
    final View opView = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, opView);
    op.setIncludeEdges(IncludeEdgeType.ALL);
    op.setIncludeEntities(false);
    final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
    final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
    //With query compaction the result size should be 1
    assertEquals(1, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItem(expectedSummarisedEdge));
    elements.close();
}
Also used : GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) 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)

Example 9 with GetElementsBetweenSets

use of uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method shouldSummariseOutGoingEdgesOnly.

private void shouldSummariseOutGoingEdgesOnly(final AccumuloStore store) throws OperationException {
    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 GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, view);
    op.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
    final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
    final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
    //With query compaction the result size should be 2
    assertEquals(2, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItems(expectedEntity1, expectedSummarisedEdge));
    elements.close();
}
Also used : GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) 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)

Example 10 with GetElementsBetweenSets

use of uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets in project Gaffer by gchq.

the class AccumuloIDBetweenSetsRetrieverTest method shouldGetCorrectEdges.

private void shouldGetCorrectEdges(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    // Query for all edges between the set {A0} and the set {A23}
    final AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> op = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A0_SET, AccumuloTestData.SEED_A23_SET, defaultView);
    final Set<Element> initalResults = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(initalResults, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY));
    // Query for all edges between set {A1} and the set {notpresent} - there shouldn't be any, but
    // we will get the entity for A1
    final AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> secondOp = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A1_SET, AccumuloTestData.NOT_PRESENT_ENTITY_SEED_SET, defaultView);
    final Set<Element> secondResults = returnElementsFromOperation(store, secondOp, new User(), loadIntoMemory);
    assertEquals(1, secondResults.size());
    assertThat(secondResults, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY));
    // Query for all edges between set {A1} and the set {A2} - there shouldn't be any edges but will
    // get the entity for A1
    final AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> thirdOp = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A1_SET, AccumuloTestData.SEED_A2_SET, defaultView);
    final Set<Element> thirdResults = returnElementsFromOperation(store, thirdOp, new User(), loadIntoMemory);
    assertEquals(1, thirdResults.size());
    assertThat(thirdResults, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY));
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Aggregations

GetElementsBetweenSets (uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets)11 Element (uk.gov.gchq.gaffer.data.element.Element)11 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)7 User (uk.gov.gchq.gaffer.user.User)7 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)4 HashSet (java.util.HashSet)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)2 BloomFilter (org.apache.hadoop.util.bloom.BloomFilter)1 Key (org.apache.hadoop.util.bloom.Key)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1