use of uk.gov.gchq.gaffer.doc.properties.generator.TimestampSetElementGenerator in project gaffer-doc by gchq.
the class TimestampSetWalkthrough method run.
@Override
public CloseableIterable<? extends Element> run() throws OperationException {
// / [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [add] addElements - add the edges to the graph
// ---------------------------------------------------------
final Set<String> dummyData = Collections.singleton("");
final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new TimestampSetElementGenerator()).input(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
print("Added an edge A-B 25 times, each time with a RBMBackedTimestampSet containing a random time in 2017.");
// [get] Get all edges
// ---------------------------------------------------------
CloseableIterable<? extends Element> allEdges = graph.execute(new GetAllElements(), user);
// ---------------------------------------------------------
print("\nAll edges:");
for (final Element edge : allEdges) {
print("GET_ALL_EDGES_RESULT", edge.toString());
}
// [get the first and last timestamps and the number of timestamps for edge a b] Get the edge A-B and print out the first and last times it was active and the total number of timestamps
// ---------------------------------------------------------
final GetElements query = new GetElements.Builder().input(new EdgeSeed("A", "B", DirectedType.UNDIRECTED)).build();
final Element edge;
try (final CloseableIterable<? extends Element> edges = graph.execute(query, user)) {
edge = edges.iterator().next();
}
final uk.gov.gchq.gaffer.time.TimestampSet timestampSet = (uk.gov.gchq.gaffer.time.TimestampSet) edge.getProperty("timestampSet");
final Instant earliest = timestampSet.getEarliest();
final Instant latest = timestampSet.getLatest();
final long totalNumber = timestampSet.getNumberOfTimestamps();
final String earliestLatestNumber = "Edge A-B was first seen at " + earliest + ", last seen at " + latest + ", and there were " + totalNumber + " timestamps it was active.";
// ---------------------------------------------------------
print("\nEdge A-B with the first seen time, last seen time and the number of times it was active:");
print("GET_FIRST_SEEN_LAST_SEEN_AND_NUMBER_OF_TIMES_FOR_EDGE_A_B", earliestLatestNumber);
return null;
}
Aggregations