use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class RyaOutputFormatTest method testTemporalIndexing.
@Test
public void testTemporalIndexing() throws Exception {
final TemporalInstant[] instants = { new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 01), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 02), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 03), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 03) };
final Statement[] statements = new Statement[instants.length];
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, true);
RyaOutputFormat.setEntityEnabled(job, false);
final ValueFactory vf = new ValueFactoryImpl();
for (int i = 0; i < instants.length; i++) {
final RyaType time = RdfToRyaConversions.convertLiteral(vf.createLiteral(instants[i].toString()));
final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(time).build();
write(input);
statements[i] = RyaToRdfConversions.convertStatement(input);
}
final AccumuloTemporalIndexer temporal = new AccumuloTemporalIndexer();
temporal.setConf(conf);
Connector connector = ConfigUtils.getConnector(conf);
MultiTableBatchWriter mtbw = connector.createMultiTableBatchWriter(new BatchWriterConfig());
temporal.setConnector(connector);
temporal.setMultiTableBatchWriter(mtbw);
temporal.init();
final Set<Statement> empty = new HashSet<>();
final Set<Statement> head = new HashSet<>();
final Set<Statement> tail = new HashSet<>();
head.add(statements[0]);
tail.add(statements[2]);
tail.add(statements[3]);
Assert.assertEquals(empty, getSet(temporal.queryInstantBeforeInstant(instants[0], new StatementConstraints())));
Assert.assertEquals(empty, getSet(temporal.queryInstantAfterInstant(instants[3], new StatementConstraints())));
Assert.assertEquals(head, getSet(temporal.queryInstantBeforeInstant(instants[1], new StatementConstraints())));
Assert.assertEquals(tail, getSet(temporal.queryInstantAfterInstant(instants[1], new StatementConstraints())));
temporal.close();
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class EventQueryNode method evaluate.
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
final List<BindingSet> list = new ArrayList<>();
try {
final Collection<Event> searchEvents;
final String subj;
// if the provided binding set has the subject already, set it to the constant subject.
if (!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
} else if (bindings.size() != 0) {
list.add(bindings);
}
// If the subject needs to be filled in, check if the subject variable is in the binding set.
if (subjectConstant.isPresent()) {
// if it is, fetch that value and then fetch the entity for the subject.
subj = subjectConstant.get();
searchEvents = eventStore.search(Optional.of(new RyaURI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
} else {
searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
}
for (final Event event : searchEvents) {
final MapBindingSet resultSet = new MapBindingSet();
if (event.getGeometry().isPresent()) {
final Geometry geo = event.getGeometry().get();
final Value geoValue = ValueFactoryImpl.getInstance().createLiteral(geo.toText());
final Var geoObj = geoPattern.getObjectVar();
resultSet.addBinding(geoObj.getName(), geoValue);
}
final Value temporalValue;
if (event.isInstant() && event.getInstant().isPresent()) {
final Optional<TemporalInstant> opt = event.getInstant();
DateTime dt = opt.get().getAsDateTime();
dt = dt.toDateTime(DateTimeZone.UTC);
final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
temporalValue = ValueFactoryImpl.getInstance().createLiteral(str);
} else if (event.getInterval().isPresent()) {
temporalValue = ValueFactoryImpl.getInstance().createLiteral(event.getInterval().get().getAsPair());
} else {
temporalValue = null;
}
if (temporalValue != null) {
final Var temporalObj = temporalPattern.getObjectVar();
resultSet.addBinding(temporalObj.getName(), temporalValue);
}
list.add(resultSet);
}
} catch (final ObjectStorageException e) {
throw new QueryEvaluationException("Failed to evaluate the binding set", e);
}
return new CollectionIteration<>(list);
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class EventDocumentConverterTest method to_and_from_document.
@Test
public void to_and_from_document() throws DocumentConverterException {
final Geometry geo = GF.createPoint(new Coordinate(10, 10));
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
// An Event that will be stored.
final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
final Document document = new EventDocumentConverter().toDocument(event);
// Convert the Document back into an Event.
final Event converted = new EventDocumentConverter().fromDocument(document);
// Ensure the original matches the round trip converted Event.
assertEquals(event, converted);
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class MongoEventStorageIT method create_and_get.
@Test
public void create_and_get() throws Exception {
final Geometry geo = GF.createPoint(new Coordinate(10, 10));
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
// An Event that will be stored.
final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
// Create it.
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
storage.create(event);
// Get it.
final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/001"));
// Verify the correct value was returned.
assertEquals(event, storedEvent.get());
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class TemporalIntervalTest method infinitePastFutureAlwaysTest.
@Test
public void infinitePastFutureAlwaysTest() throws Exception {
final TemporalInstant TestDateString = new TemporalInstantRfc3339(new DateTime("2015-01-01T01:59:59Z"));
TemporalInterval tvFuture = new TemporalInterval(TestDateString, TemporalInstantRfc3339.getMaximumInstance());
TemporalInterval tvPast = new TemporalInterval(TemporalInstantRfc3339.getMinimumInstance(), TestDateString);
TemporalInterval tvAlways = new TemporalInterval(TemporalInstantRfc3339.getMinimumInstance(), TemporalInstantRfc3339.getMaximumInstance());
Assert.assertTrue("The future is greater (starts after) than the past for compareTo().", tvFuture.compareTo(tvPast) > 0);
Assert.assertTrue("The future is greater (starts after) than always for compareTo().", tvFuture.compareTo(tvAlways) > 0);
Assert.assertTrue("The past is less (starts same, ends earlier) than always for compareTo().", tvFuture.compareTo(tvPast) > 0);
}
Aggregations