Search in sources :

Example 71 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloRangeIDRetrieverTest method shouldRetrieveElementsInRangeBetweenSeeds.

private void shouldRetrieveElementsInRangeBetweenSeeds(final AccumuloStore store) throws Exception {
    // Create set to query for
    final Set<Pair<ElementId, ElementId>> simpleEntityRanges = new HashSet<>();
    simpleEntityRanges.add(new Pair<>(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 GetElementsInRanges operation = new GetElementsInRanges.Builder().view(defaultView).input(simpleEntityRanges).build();
    final AccumuloRangeIDRetriever<?> retriever = new AccumuloRangeIDRetriever<>(store, operation, new User());
    final List<Element> elements = Lists.newArrayList(retriever);
    for (final Element element : elements) {
        if (element instanceof Edge) {
            assertEquals(EdgeId.MatchedVertex.SOURCE, ((Edge) element).getMatchedVertex());
        }
    }
    assertEquals(NUM_ENTRIES, elements.size());
}
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) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) HashSet(java.util.HashSet)

Example 72 with User

use of uk.gov.gchq.gaffer.user.User 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 73 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldStillApplyOtherFilter.

private void shouldStillApplyOtherFilter(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    // Query for all edges in set {A0, A23}
    final Set<EntityId> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    final View edgesOnlyView = new View.Builder().edge(TestGroups.EDGE).build();
    final GetElementsWithinSet op = new GetElementsWithinSet.Builder().view(edgesOnlyView).input(seeds).build();
    // Set graph to give us edges only
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results).contains(AccumuloTestData.EDGE_A0_A23);
    // Set graph to return entities only
    final View entitiesOnlyView = new View.Builder().entity(TestGroups.ENTITY).build();
    final GetElementsWithinSet entitiesOnlyOp = new GetElementsWithinSet.Builder().view(entitiesOnlyView).input(seeds).build();
    // Query for all edges in set {A0, A23}
    final Set<Element> entitiesOnlyResults = returnElementsFromOperation(store, entitiesOnlyOp, new User(), loadIntoMemory);
    assertThat(entitiesOnlyResults).contains(AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY);
    // Set graph to return both entities and edges again, and to only return summary type "X" (which will result
    // in no data)
    final View view = new View.Builder().edge("X").build();
    final GetElementsWithinSet entitiesAndEdgesOp = new GetElementsWithinSet.Builder().view(view).input(seeds).build();
    final Set<Element> entitiesAndEdgesResults = returnElementsFromOperation(store, entitiesAndEdgesOp, new User(), loadIntoMemory);
    assertThat(entitiesAndEdgesResults).isEmpty();
}
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) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 74 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldGetCorrectEdges.

private void shouldGetCorrectEdges(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    // Query for all edges in set {A0, A23}
    final Set<EntityId> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    final GetElementsWithinSet op = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results).contains(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY);
    // Query for all edges in set {A1} - there shouldn't be any, but we will get the entity for A1
    final GetElementsWithinSet a1Operation = new GetElementsWithinSet.Builder().view(defaultView).input(AccumuloTestData.SEED_A1_SET).build();
    final Set<Element> a1Results = returnElementsFromOperation(store, a1Operation, new User(), loadIntoMemory);
    assertThat(a1Results).hasSize(1).contains(AccumuloTestData.A1_ENTITY);
    // Query for all edges in set {A1, A2} - there shouldn't be any edges but will
    // get the two entities
    final Set<EntityId> a1A2Seeds = new HashSet<>();
    a1A2Seeds.add(AccumuloTestData.SEED_A1);
    a1A2Seeds.add(AccumuloTestData.SEED_A2);
    final GetElementsWithinSet a1A2Operation = new GetElementsWithinSet.Builder().view(defaultView).input(a1A2Seeds).build();
    final Set<Element> a1A2Results = returnElementsFromOperation(store, a1A2Operation, new User(), loadIntoMemory);
    assertThat(a1A2Results).hasSize(2).contains(AccumuloTestData.A1_ENTITY, AccumuloTestData.A2_ENTITY);
}
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) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) HashSet(java.util.HashSet)

Example 75 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method setupGraph.

private static void setupGraph(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).
        TableUtils.createTable(store);
        final Set<Element> data = new HashSet<>();
        // Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
        final Entity entity = new Entity(TestGroups.ENTITY);
        entity.setVertex("A0");
        entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
        data.add(entity);
        for (int i = 1; i < 100; i++) {
            data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, i).build());
            data.add(new Entity.Builder().group(TestGroups.ENTITY).vertex("A" + i).property(AccumuloPropertyNames.COUNT, i).build());
        }
        data.add(AccumuloTestData.EDGE_C_D_DIRECTED);
        data.add(AccumuloTestData.EDGE_C_D_UNDIRECTED);
        addElements(data, store, new User());
    } catch (final TableExistsException | StoreException e) {
        fail("Failed to set up graph in Accumulo with exception: " + e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) TableExistsException(org.apache.accumulo.core.client.TableExistsException) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43