Search in sources :

Example 31 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetEntitiesBySeed.

@Test
public void shouldAddAndGetEntitiesBySeed() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the entities
    final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder().addSeed(new EntitySeed(1)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEntityDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
        int index = 0;
        SimpleEntityDataObject obj = resultList.get(index);
        assertEquals(1, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Red", obj.getProperties());
    }
    results.close();
}
Also used : SimpleEntityGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator) User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 32 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class ArrayListStoreTest method addElementsToGraph.

private void addElementsToGraph(final Graph graph) throws OperationException {
    final OperationChain<Void> opChain = new OperationChain.Builder().first(new GenerateElements.Builder<>().objects(getDomainObjects()).generator(new SimpleGenerator()).build()).then(new AddElements()).build();
    // execute the operation
    graph.execute(opChain, new User());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SimpleGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleGenerator)

Example 33 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetRelatedEdges.

@Test
public void shouldAddAndGetRelatedEdges() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the edges
    final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).addSeed(new EntitySeed(2)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEdgeDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEdgeDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
        assertEquals(3, resultList.size());
        int index = 0;
        SimpleEdgeDataObject obj = resultList.get(index++);
        assertEquals(1, obj.getLeft());
        assertEquals(2, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("121", obj.getProperties());
        obj = resultList.get(index++);
        assertEquals(2, obj.getLeft());
        assertEquals(3, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("231", obj.getProperties());
        obj = resultList.get(index);
        assertEquals(4, obj.getLeft());
        assertEquals(1, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("142", obj.getProperties());
    }
    results.close();
}
Also used : User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SimpleEdgeGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) Test(org.junit.Test)

Example 34 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetRelatedEntities.

@Test
public void shouldAddAndGetRelatedEntities() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the entities
    final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder<>().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEntityDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
        int index = 0;
        SimpleEntityDataObject obj = resultList.get(index++);
        assertEquals(1, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Red", obj.getProperties());
        obj = resultList.get(index);
        assertEquals(2, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Orange", obj.getProperties());
    }
    results.close();
}
Also used : SimpleEntityGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator) User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 35 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class LoadAndQuery10 method run.

public Iterable<Entity> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator10()).objects(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    log("Added an edge A-B 1000 times, each time with a LongsSketch containing a random long between 0 and 9.");
    // [get] Get all edges
    // ---------------------------------------------------------
    Iterable<Edge> allEdges = graph.execute(new GetAllEdges(), user);
    // ---------------------------------------------------------
    log("\nAll edges:");
    for (final Edge edge : allEdges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get frequencies of 1L and 9L] Get the edge A-B and print estimates of frequencies of 1L and 9L
    // ---------------------------------------------------------
    final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
    final Iterable<Edge> edges = graph.execute(query, user);
    final Edge edge = edges.iterator().next();
    final LongsSketch longsSketch = (LongsSketch) edge.getProperty("longsSketch");
    final String estimates = "Edge A-B: 1L seen approximately " + longsSketch.getEstimate(1L) + " times, 9L seen approximately " + longsSketch.getEstimate(9L) + " times.";
    // ---------------------------------------------------------
    log("\nEdge A-B with estimates of the frequencies of 1 and 9");
    log("GET_FREQUENCIES_OF_1_AND_9_FOR_EDGE_A_B", estimates);
    return null;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) DataGenerator10(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator10) User(uk.gov.gchq.gaffer.user.User) LongsSketch(com.yahoo.sketches.frequencies.LongsSketch) Graph(uk.gov.gchq.gaffer.graph.Graph) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6