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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations