use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class LoadAndQuery6 method run.
public CloseableIterable<String> 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] Create a data generator and add the edges to the graph using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final DataGenerator6 dataGenerator = new DataGenerator6();
final List<String> data = DataUtils.loadData(getData());
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(dataGenerator).objects(data).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// [get] Create and execute an operation chain consisting of 3 operations:
//GetAdjacentEntitySeeds - starting at vertex 1 get all adjacent vertices (vertices at other end of outbound edges)
//GetRelatedEdges - get outbound edges
//GenerateObjects - convert the edges back into comma separated strings
// ---------------------------------------------------------
final OperationChain<CloseableIterable<String>> opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds.Builder().addSeed(new EntitySeed("1")).inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GenerateObjects.Builder<Edge, String>().generator(dataGenerator).build()).build();
final CloseableIterable<String> results = graph.execute(opChain, user);
// ---------------------------------------------------------
log("\nFiltered edges converted back into comma separated strings. The counts have been aggregated\n");
for (final String result : results) {
log("RESULT", result);
}
return results;
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class LoadAndQuery7 method run.
public Iterable<Edge> 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 using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator7()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// Create some starting seeds for the sub graph.
final Iterable<EntitySeed> seeds = Lists.newArrayList(new EntitySeed("1"));
// Create a view to return only edges that have a count more than 1
// Note we could have used a different view for each hop in order to
// specify the edges we wish to hop down or to attempt to prevent caching
// duplicate edges.
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(1)).build()).build()).build();
// [extractor] Create a generator that will extract entity seeds
// This generator will extract just the destination vertices from edges
// and skip any entities.
// ---------------------------------------------------------
final EntitySeedExtractor destVerticesExtractor = new EntitySeedExtractor(new IsEdgeValidator(), new AlwaysValid<>(), true, IdentifierType.DESTINATION);
// ---------------------------------------------------------
// [get] Create a sub graph
// Start getting related edges with the given seeds.
// Then update the export with the results
// Between each hop we need to extract the destination vertices of the
// previous edges.
// Finally finish off by returning all the edges in the export.
// ---------------------------------------------------------
final OperationChain opChain = new OperationChain.Builder().first(new GetEdges.Builder<EntitySeed>().seeds(seeds).inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GenerateObjects<Edge, EntitySeed>(destVerticesExtractor)).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GetSetExport()).build();
final Iterable<Edge> subGraph = (Iterable<Edge>) graph.execute(opChain, user);
// ---------------------------------------------------------
log("\nSub graph:");
for (final Edge edge : subGraph) {
log("SUB_GRAPH", edge.toString());
}
return subGraph;
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class TransformationIT method setup.
@Override
@Before
public void setup() throws Exception {
super.setup();
addDefaultElements();
final Collection<Element> elements = new ArrayList<>(2);
final Edge sampleEdgeWithTransientProperty = new Edge(TestGroups.EDGE, VERTEX + SOURCE, VERTEX + DEST, true);
sampleEdgeWithTransientProperty.putProperty(TestPropertyNames.COUNT, 1L);
sampleEdgeWithTransientProperty.putProperty(TestPropertyNames.TRANSIENT_1, "test");
elements.add(sampleEdgeWithTransientProperty);
final Entity sampleEntityWithTransientProperty = new Entity(TestGroups.ENTITY, VERTEX);
sampleEntityWithTransientProperty.putProperty(TestPropertyNames.TRANSIENT_1, "test");
elements.add(sampleEntityWithTransientProperty);
graph.execute(new AddElements(elements), getUser());
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class LoadAndQuery8 method run.
public Iterable<Edge> run() throws OperationException {
// [user] Create a user who can see public and private data
// ---------------------------------------------------------
final User user = new User.Builder().userId("user").dataAuths("public", "private").build();
// ---------------------------------------------------------
// [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 OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator8()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// [get] Get all edges
// ---------------------------------------------------------
final GetAllEdges allEdgesOperation = new GetAllEdges();
final Iterable<Edge> edges = graph.execute(allEdgesOperation, user);
// ---------------------------------------------------------
log("\nAll edges in daily time buckets:");
for (final Edge edge : edges) {
log("GET_ALL_EDGES_RESULT", edge.toString());
}
// [get all edges summarised] Get all edges summarised (merge all time windows together)
// This is achieved by overriding the 'groupBy' start and end time properties.
// ---------------------------------------------------------
final GetAllEdges edgesSummarisedOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
final Iterable<Edge> edgesSummarised = graph.execute(edgesSummarisedOperation, user);
// ---------------------------------------------------------
log("\nAll edges summarised:");
for (final Edge edge : edgesSummarised) {
log("GET_ALL_EDGES_SUMMARISED_RESULT", edge.toString());
}
// [get all edges summarised in time window] Get all edges summarised over a provided 2 day time period
// This is achieved by overriding the 'groupBy' start and end time properties
// and providing a filter.
// ---------------------------------------------------------
final GetAllEdges edgesSummarisedInTimeWindowOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_16, true)).select("endDate").execute(new IsLessThan(JAN_02_16, true)).build()).groupBy().build()).build()).build();
final Iterable<Edge> edgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, user);
// ---------------------------------------------------------
log("\nEdges in 2 day time window:");
for (final Edge edge : edgesSummarisedInTimeWindow) {
log("GET_ALL_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
}
// Repeat with a public user and you will see the private edges are not part of the summarised edges
final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
final Iterable<Edge> publicEdgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, publicUser);
log("\nPublic edges in 2 day time window:");
for (final Edge edge : publicEdgesSummarisedInTimeWindow) {
log("GET_PUBLIC_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
}
return publicEdgesSummarisedInTimeWindow;
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class AddElementsExample method addElements.
public void addElements() throws OperationException {
log("#### " + getMethodNameAsSentence(0) + "\n");
printGraph();
final AddElements operation = new AddElements.Builder().elements(new Entity.Builder().group("entity").vertex(6).property("count", 1).build(), new Edge.Builder().group("edge").source(5).dest(6).directed(true).property("count", 1).build()).build();
printJava("new AddElements.Builder()\n" + " .elements(new Entity.Builder()\n" + " .group(\"entity\")\n" + " .vertex(6)\n" + " .property(\"count\", 1)\n" + " .build(),\n" + " new Edge.Builder()\n" + " .group(\"edge\")\n" + " .source(5).dest(6).directed(true)\n" + " .property(\"count\", 1)\n" + " .build())\n" + " .build();");
printAsJson(operation);
printOperationClass(operation);
getGraph().execute(operation, new User("user01"));
log("Updated graph:");
log("```");
log(" --> 4 <--");
log(" / ^ \\");
log(" / | \\");
log("1 --> 2 --> 3");
log(" \\");
log(" --> 5 --> 6");
log("```");
}
Aggregations