use of uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator3 in project Gaffer by gchq.
the class LoadAndQuery3 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator3 dataGenerator = new DataGenerator3();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [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 AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
log("\nAll edges containing the vertex 1. The counts have been aggregated\n");
// [get simple] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// [get] rerun previous query with a filter to return only edges with a count more than 3
// ---------------------------------------------------------
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(3)).build()).build()).build();
final GetEdges<EntitySeed> getRelatedEdgesWithCountMoreThan3 = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> filteredResults = graph.execute(getRelatedEdgesWithCountMoreThan3, user);
// ---------------------------------------------------------
log("\nAll edges containing the vertex 1 with an aggregated count more than than 3\n");
for (final Element e : filteredResults) {
log("GET_RELATED_ELEMENTS_WITH_COUNT_MORE_THAN_3_RESULT", e.toString());
}
return filteredResults;
}
Aggregations