use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class TemporalIntervalTest method constructorTest.
@Test
public void constructorTest() throws Exception {
TemporalInterval ti = new //
TemporalInterval(//
new TemporalInstantRfc3339(2014, 12, 30, 12, 59, 59), //
new TemporalInstantRfc3339(2014, 12, 30, 13, 00, 00));
Assert.assertNotNull(ti.getAsKeyBeginning());
Assert.assertNotNull(ti.getHasEnd());
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class AccumuloTemporalIndexer method deleteStatement.
private void deleteStatement(final Statement statement) throws IOException, IllegalArgumentException {
Objects.requireNonNull(temporalIndexBatchWriter, "This is not initialized for writing. Must call setMultiTableBatchWriter() and init().");
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (!isValidPredicate || !(statement.getObject() instanceof Literal)) {
return;
}
// 0 begin, 1 end of interval
final DateTime[] indexDateTimes = new DateTime[2];
extractDateTime(statement, indexDateTimes);
if (indexDateTimes[0] == null) {
return;
}
// Remove this as an instant, or interval.
try {
if (indexDateTimes[1] != null) {
final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1]));
removeInterval(temporalIndexBatchWriter, interval, statement);
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]);
removeInstant(temporalIndexBatchWriter, instant, statement);
}
} catch (final MutationsRejectedException e) {
throw new IOException("While adding interval/instant for statement =" + statement, e);
}
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class AccumuloTemporalIndexer method queryInstantInsideInterval.
/**
* Get instances inside a given interval.
* Returns after interval's beginning time, and before ending time,
* exclusive (don't match the beginning and ending).
*/
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantInsideInterval(final TemporalInterval queryInterval, final StatementConstraints constraints) throws QueryEvaluationException {
// get rows where the time is after the given interval's beginning time and before the ending time.
final TemporalInterval theQueryInterval = queryInterval;
final Query query = new Query() {
private final TemporalInterval queryInterval = theQueryInterval;
@Override
public Range getRange(final KeyParts keyParts) {
final Text start = Range.followingPrefix(new Text(keyParts.getQueryKey(queryInterval.getHasBeginning())));
// <-- end specific logic
final Text endAt = new Text(keyParts.getQueryKey(queryInterval.getHasEnd()));
// System.out.println("Scanning queryInstantInsideInterval: from excluding:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt));
return new Range(start, false, endAt, false);
}
};
final ScannerBase scanner = query.doQuery(queryInterval.getHasBeginning(), constraints);
return getContextIteratorWrapper(scanner, constraints.getContext());
}
use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.
the class MongoTemporalIndexerIT method testQueryInstantInsideInterval.
/**
* Test instant inside given interval.
* Instance {before, after, inside} given Interval
*/
@Test
public void testQueryInstantInsideInterval() 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 beginningSeconds = 2;
final int endingSeconds = 31;
// 3,4,...,30 seconds.
final int expectedResultCount = endingSeconds - beginningSeconds - 1;
for (int s = 0; s <= 40; s++) {
tIndexer.storeStatement(convertStatement(seriesSpo[s]));
}
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryInstantInsideInterval(searchInsideInterval, EMPTY_CONSTRAINTS);
int count = 0;
while (iter.hasNext()) {
final Statement s = iter.next();
// <== logic here
final Statement nextExpectedStatement = seriesSpo[count + beginningSeconds + 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 MongoTemporalIndexerIT method testQueryInstantBeforeInterval.
/**
* Test instant before given interval.
* From the series: Instance {before, after, inside} given Interval
*/
@Test
public void testQueryInstantBeforeInterval() 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.
final TemporalInterval searchForSeconds = tvB02_E31;
// 00 and 01 seconds.
final int expectedResultCount = 2;
for (int s = 0; s <= 40; s++) {
// <== logic here
tIndexer.storeStatement(convertStatement(seriesSpo[s]));
}
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryInstantBeforeInterval(searchForSeconds, EMPTY_CONSTRAINTS);
int count = 0;
while (iter.hasNext()) {
final Statement s = iter.next();
// <== logic here
final Statement nextExpectedStatement = seriesSpo[count];
assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
count++;
}
assertEquals("Should find count of rows.", expectedResultCount, count);
}
}
Aggregations