Search in sources :

Example 6 with RBMBackedTimestampSet

use of uk.gov.gchq.gaffer.time.RBMBackedTimestampSet in project Gaffer by gchq.

the class MaskTimestampSetByTimeRangeTest method shouldFilterUsingMillisecondsByDefault.

@Test
public void shouldFilterUsingMillisecondsByDefault() {
    final RBMBackedTimestampSet timestampSet = createTimestampSet();
    maskTimestampSetByTimeRange.setStartTime(instant.plus(Duration.ofDays(100)).toEpochMilli());
    maskTimestampSetByTimeRange.setEndTime(instant.plus(Duration.ofDays(250)).toEpochMilli());
    final RBMBackedTimestampSet expectedTimestampSet = new RBMBackedTimestampSet(TimeBucket.MINUTE);
    expectedTimestampSet.add(instant.plus(Duration.ofDays(100L)));
    expectedTimestampSet.add(instant.plus(Duration.ofDays(200L)));
    final RBMBackedTimestampSet actualTimestampSet = maskTimestampSetByTimeRange.apply(timestampSet);
    assertEquals(expectedTimestampSet, actualTimestampSet);
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 7 with RBMBackedTimestampSet

use of uk.gov.gchq.gaffer.time.RBMBackedTimestampSet in project Gaffer by gchq.

the class MaskTimestampSetByTimeRangeTest method createTimestampSet.

private RBMBackedTimestampSet createTimestampSet() {
    final RBMBackedTimestampSet timestampSet = new RBMBackedTimestampSet(TimeBucket.MINUTE);
    timestampSet.add(instant);
    timestampSet.add(instant.plus(Duration.ofDays(100L)));
    timestampSet.add(instant.plus(Duration.ofDays(200L)));
    timestampSet.add(instant.plus(Duration.ofDays(300L)));
    return timestampSet;
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)

Example 8 with RBMBackedTimestampSet

use of uk.gov.gchq.gaffer.time.RBMBackedTimestampSet in project Gaffer by gchq.

the class MaskTimestampSetByTimeRangeTest method shouldBeAbleToChangeTimeUnit.

@Test
public void shouldBeAbleToChangeTimeUnit() {
    // Given
    final RBMBackedTimestampSet timestampSet = createTimestampSet();
    final long instantInDays = instant.toEpochMilli() / 1000 / 60 / 60 / 24;
    final MaskTimestampSetByTimeRange mask = new MaskTimestampSetByTimeRange.Builder().startTime(instantInDays).endTime(instantInDays + 150L).timeUnit(TimeUnit.DAY).build();
    // When
    final RBMBackedTimestampSet output = mask.apply(timestampSet);
    // Then
    final RBMBackedTimestampSet expected = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.MINUTE).timestamps(Sets.newHashSet(instant, instant.plus(Duration.ofDays(100)))).build();
    assertEquals(expected, output);
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 9 with RBMBackedTimestampSet

use of uk.gov.gchq.gaffer.time.RBMBackedTimestampSet 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)

Example 10 with RBMBackedTimestampSet

use of uk.gov.gchq.gaffer.time.RBMBackedTimestampSet in project gaffer-doc by gchq.

the class TimestampSetElementGenerator method _apply.

@Override
public Iterable<Element> _apply(final String line) {
    final Set<Element> elements = new HashSet<>();
    for (int i = 0; i < 25; i++) {
        final TimestampSet timestampSet = new RBMBackedTimestampSet(CommonTimeUtil.TimeBucket.MINUTE);
        timestampSet.add(START_OF_2017.plusSeconds(RANDOM.nextInt(SECONDS_IN_YEAR)));
        final Edge edge = new Edge.Builder().group("red").source("A").dest("B").property("timestampSet", timestampSet).build();
        elements.add(edge);
    }
    return elements;
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Element(uk.gov.gchq.gaffer.data.element.Element) TimestampSet(uk.gov.gchq.gaffer.time.TimestampSet) RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Aggregations

RBMBackedTimestampSet (uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)19 Test (org.junit.jupiter.api.Test)11 ToBytesSerialisationTest (uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)4 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Instant (java.time.Instant)2 RoaringBitmap (org.roaringbitmap.RoaringBitmap)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)2 TimeBucket (uk.gov.gchq.gaffer.time.CommonTimeUtil.TimeBucket)2 CustomMap (uk.gov.gchq.gaffer.types.CustomMap)2 ReservoirLongsUnion (com.yahoo.sketches.sampling.ReservoirLongsUnion)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 BitmapJsonModules (uk.gov.gchq.gaffer.bitmap.serialisation.json.BitmapJsonModules)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 TimestampSetElementGenerator (uk.gov.gchq.gaffer.doc.properties.generator.TimestampSetElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1