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();
}
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());
}
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();
}
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();
}
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;
}
Aggregations