use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategy method getTemporalObjs.
private DBObject[] getTemporalObjs(final Collection<IndexingExpr> temporalFilters) {
final List<DBObject> objs = new ArrayList<>();
temporalFilters.forEach(filter -> {
final TemporalPolicy policy = TemporalPolicy.fromURI(filter.getFunction());
final String timeStr = ((Value) filter.getArguments()[0]).stringValue();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(timeStr);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(timeStr);
if (policy == TemporalPolicy.INSTANT_AFTER_INSTANT || policy == TemporalPolicy.INSTANT_BEFORE_INSTANT || policy == TemporalPolicy.INSTANT_EQUALS_INSTANT) {
if (interval == null) {
LOG.error("Cannot perform temporal interval based queries on an instant.");
}
}
objs.add(getTemporalObject(interval, policy));
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(timeStr));
if (policy != TemporalPolicy.INSTANT_AFTER_INSTANT && policy != TemporalPolicy.INSTANT_BEFORE_INSTANT && policy != TemporalPolicy.INSTANT_EQUALS_INSTANT) {
LOG.error("Cannot perform temporal instant based queries on an interval.");
}
objs.add(getTemporalObject(instant, policy));
}
});
return objs.toArray(new DBObject[] {});
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method deleteStatement.
@Override
public void deleteStatement(final RyaStatement statement) throws IOException {
requireNonNull(statement);
final RyaURI subject = statement.getSubject();
try {
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()) {
return Optional.empty();
} else {
updated = Event.builder(old.get());
}
final Event currentEvent = updated.build();
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)) && currentEvent.getGeometry().isPresent()) {
// is geo and needs to be removed.
try {
if (currentEvent.getGeometry().get().equals(GeoParseUtils.getGeometry(RyaToRdfConversions.convertStatement(statement), new GmlParser()))) {
updated.setGeometry(null);
}
} catch (final Exception e) {
LOG.debug("Unable to parse the stored geometry.");
}
} 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);
if (currentEvent.getInterval().get().equals(interval)) {
updated.setTemporalInterval(null);
}
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
if (currentEvent.getInstant().get().equals(instant)) {
updated.setTemporalInstant(null);
}
}
}
return Optional.of(updated.build());
});
} catch (final IndexingException e) {
throw new IOException("Failed to update the Entity index.", e);
}
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class MongoTemporalIndexerIT method testQueryInstantHasBeginningInterval.
/**
* Test instant is the Beginning of the given interval.
* from the series: Instance {hasBeginning, hasEnd} Interval
*/
@Test
public void testQueryInstantHasBeginningInterval() 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 searchInsideInterval = tvB02_E31;
// <== logic here, and next few lines.
final int searchSeconds = 2;
// 2 seconds.
final int expectedResultCount = 1;
for (int s = 0; s <= 10; s++) {
tIndexer.storeStatement(convertStatement(seriesSpo[s]));
}
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryInstantHasBeginningInterval(searchInsideInterval, EMPTY_CONSTRAINTS);
int count = 0;
while (iter.hasNext()) {
final Statement s = iter.next();
// <== logic here
final Statement nextExpectedStatement = seriesSpo[searchSeconds];
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 MongoTemporalIndexerIT method testQueryInstantHasEndInterval.
/**
* Test instant is the end of the given interval.
* from the series: Instance {hasBeginning, hasEnd} Interval
*/
@Test
public void testQueryInstantHasEndInterval() 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 searchInsideInterval = tvB02_E31;
// <== logic here, and next few lines.
final int searchSeconds = 31;
// 31 seconds.
final int expectedResultCount = 1;
for (int s = 0; s <= 40; s++) {
tIndexer.storeStatement(convertStatement(seriesSpo[s]));
}
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryInstantHasEndInterval(searchInsideInterval, EMPTY_CONSTRAINTS);
int count = 0;
while (iter.hasNext()) {
final Statement s = iter.next();
// <== logic here
final Statement nextExpectedStatement = seriesSpo[searchSeconds];
assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
count++;
}
assertEquals("Should find count of rows.", expectedResultCount, count);
}
}
Aggregations