Search in sources :

Example 11 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View 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<EntitySeed> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
    // Set graph to give us edges only
    op.setIncludeEntities(false);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A0_A23));
    // Set graph to return entities only
    final GetElements<EntitySeed, ?> entitiesOnlyOp = new GetElements<>(defaultView, seeds);
    entitiesOnlyOp.setIncludeEntities(true);
    entitiesOnlyOp.setIncludeEdges(IncludeEdgeType.NONE);
    // Query for all edges in set {A0, A23}
    final Set<Element> entitiesOnlyResults = returnElementsFromOperation(store, entitiesOnlyOp, new User(), loadIntoMemory);
    assertThat(entitiesOnlyResults, IsCollectionContaining.hasItems(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 GetElements<EntitySeed, ?> entitiesAndEdgesOp = new GetElements<>(view, seeds);
    entitiesAndEdgesOp.setIncludeEdges(IncludeEdgeType.ALL);
    entitiesAndEdgesOp.setIncludeEntities(true);
    final Set<Element> entitiesAndEdgesResults = returnElementsFromOperation(store, entitiesAndEdgesOp, new User(), loadIntoMemory);
    assertEquals(0, entitiesAndEdgesResults.size());
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 12 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testUndirectedEdgeSeedQueries.

private void testUndirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("B", edge.getDestination());
    }
    //We should have only 1000 returned the i-B edges that are undirected
    assertEquals(numEntries, 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) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 13 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEdgesOnly.

private void testEntitySeedQueryEdgesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEntities(false);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    //Should find both i-B and i-C edges.
    assertEquals(numEntries * 2, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) 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) HashSet(java.util.HashSet)

Example 14 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testDirectedEdgeSeedQueries.

private void testDirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.DIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("C", edge.getDestination());
    }
    //Should find 1000 only A-C
    assertEquals(numEntries, 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) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 15 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryIncomingEdgesOnly.

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

Aggregations

View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)107 Test (org.junit.Test)70 Element (uk.gov.gchq.gaffer.data.element.Element)42 User (uk.gov.gchq.gaffer.user.User)38 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)32 HashSet (java.util.HashSet)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 Graph (uk.gov.gchq.gaffer.graph.Graph)20 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)19 ArrayList (java.util.ArrayList)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 Edge (uk.gov.gchq.gaffer.data.element.Edge)13 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)12 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)11 SQLContext (org.apache.spark.sql.SQLContext)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8