Search in sources :

Example 1 with TimestampSetElementGenerator

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;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Instant(java.time.Instant) TimestampSetElementGenerator(uk.gov.gchq.gaffer.doc.properties.generator.TimestampSetElementGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed)

Aggregations

Instant (java.time.Instant)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 TimestampSetElementGenerator (uk.gov.gchq.gaffer.doc.properties.generator.TimestampSetElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)1 RBMBackedTimestampSet (uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)1 User (uk.gov.gchq.gaffer.user.User)1