use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class MongoTemporalIndexerIT method testQueryInstantAfterInterval.
/**
* Test instant after given interval.
* Instance {before, after, inside} given Interval
*/
@Test
public void testQueryInstantAfterInterval() throws IOException, QueryEvaluationException {
try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
tIndexer.setConf(conf);
tIndexer.init();
// tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
// these should not match as they are not instances.
tIndexer.storeStatement(convertStatement(spo_B03_E20));
tIndexer.storeStatement(convertStatement(spo_B02_E30));
tIndexer.storeStatement(convertStatement(spo_B02_E40));
tIndexer.storeStatement(convertStatement(spo_B02_E31));
tIndexer.storeStatement(convertStatement(spo_B30_E32));
// seriesSpo[s] and seriesTs[s] are statements and instants for s seconds after the uniform time.
// from 2 to 31 seconds
final TemporalInterval searchAfterInterval = tvB02_E31;
final int endingSeconds = 31;
// 32,33,...,40 seconds.
final int expectedResultCount = 9;
for (int s = 0; s <= endingSeconds + expectedResultCount; s++) {
// <== logic here
tIndexer.storeStatement(convertStatement(seriesSpo[s]));
}
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryInstantAfterInterval(searchAfterInterval, EMPTY_CONSTRAINTS);
int count = 0;
while (iter.hasNext()) {
final Statement s = iter.next();
// <== logic here
final Statement nextExpectedStatement = seriesSpo[count + endingSeconds + 1];
assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
count++;
}
assertEquals("Should find count of rows.", expectedResultCount, count);
}
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class TemporalMongoDBStorageStrategy method getTimeValue.
public DBObject getTimeValue(final String timeData) {
final Matcher match = TemporalInstantRfc3339.PATTERN.matcher(timeData);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
if (match.find()) {
final TemporalInterval date = TemporalInstantRfc3339.parseInterval(timeData);
builder.add(INTERVAL_START, date.getHasBeginning().getAsDateTime().toDate());
builder.add(INTERVAL_END, date.getHasEnd().getAsDateTime().toDate());
} else {
builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate());
}
return builder.get();
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method updateEvent.
private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
final EventStorage eventStore = events.get();
checkState(events != null, "Must set this indexers configuration before storing statements.");
new EventUpdater(eventStore).update(subject, old -> {
final Event.Builder updated;
if (!old.isPresent()) {
updated = Event.builder().setSubject(subject);
} else {
updated = Event.builder(old.get());
}
final URI pred = statement.getObject().getDataType();
if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
// is geo
try {
final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
updated.setGeometry(geometry);
} catch (final ParseException e) {
LOG.error(e.getMessage(), e);
}
} else {
// is time
final String dateTime = statement.getObject().getData();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
updated.setTemporalInterval(interval);
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
updated.setTemporalInstant(instant);
}
}
return Optional.of(updated.build());
});
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class TemporalIntervalTest method keyBeginTest.
@Test
public void keyBeginTest() throws Exception {
// 58 seconds, earlier
TemporalInterval beginTI01 = new TemporalInterval(//
new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 58), //
new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
// 59 seconds, later
TemporalInterval beginTI02 = new TemporalInterval(//
new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 59), //
new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
String key01b = Arrays.toString(beginTI01.getAsKeyBeginning());
String key02b = Arrays.toString(beginTI02.getAsKeyBeginning());
Assert.assertEquals("key02 is later so comparesTo = 1.", 1, key02b.compareTo(key01b));
Assert.assertEquals("key01 is first so comparesTo = -1", -1, key01b.compareTo(key02b));
}
use of org.apache.rya.indexing.TemporalInterval 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