Search in sources :

Example 86 with Element

use of uk.gov.gchq.gaffer.data.element.Element 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 87 with Element

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

the class GetElementsWithinSetHandlerTest method shouldSummarise.

private void shouldSummarise(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()).edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder().groupBy().build()).build();
    final GetElementsWithinSet<Element> operation = new GetElementsWithinSet<>(view, seeds);
    final GetElementsWithinSetHandler handler = new GetElementsWithinSetHandler();
    final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
    //After query compaction the result size should be 3
    assertEquals(3, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1, expectedEntity2));
    elements.close();
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 88 with Element

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

the class GetElementsinRangesHandlerTest method shouldReturnNothingWhenNoEdgesSet.

private void shouldReturnNothingWhenNoEdgesSet(final AccumuloStore store) throws OperationException {
    // Create set to query for
    final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
    //get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
    simpleEntityRanges.add(new Pair<ElementSeed>(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 GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
    //All Edges stored should be outgoing from our provided seeds.
    operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
    final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
    final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
    final int count = Iterables.size(elements);
    //There should be no incoming edges to the provided range
    assertEquals(0, count);
    elements.close();
}
Also used : GetElementsInRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges) 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) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) HashSet(java.util.HashSet) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 89 with Element

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

the class GetElementsinRangesHandlerTest method shouldHaveNoIncomingEdges.

private void shouldHaveNoIncomingEdges(final AccumuloStore store) throws OperationException {
    // Create set to query for
    final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
    final User user = new User();
    //get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
    simpleEntityRanges.add(new Pair<ElementSeed>(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 GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
    //All Edges stored should be outgoing from our provided seeds.
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
    final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
    final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
    final int count = Iterables.size(elements);
    //There should be no incoming edges to the provided range
    assertEquals(0, count);
    elements.close();
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsInRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges) 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) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) HashSet(java.util.HashSet) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 90 with Element

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

the class CountGroupsHandler method doOperation.

@Override
public GroupCounts doOperation(final CountGroups operation, final Context context, final Store store) throws OperationException {
    int count = 0;
    final GroupCounts groupCounts = new GroupCounts();
    if (null != operation.getElements()) {
        for (final Element element : operation.getElements()) {
            if (null != operation.getLimit()) {
                count++;
                if (count > operation.getLimit()) {
                    groupCounts.setLimitHit(true);
                    break;
                }
            }
            if (element instanceof Entity) {
                groupCounts.addEntityGroup(element.getGroup());
            } else {
                groupCounts.addEdgeGroup(element.getGroup());
            }
        }
    }
    return groupCounts;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12