Search in sources :

Example 6 with TemporalInterval

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());
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 7 with TemporalInterval

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);
    }
}
Also used : Literal(org.openrdf.model.Literal) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) IOException(java.io.IOException) TemporalInstant(org.apache.rya.indexing.TemporalInstant) TemporalInterval(org.apache.rya.indexing.TemporalInterval) DateTime(org.joda.time.DateTime) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 8 with TemporalInterval

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());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Text(org.apache.hadoop.io.Text) KeyParts(org.apache.rya.indexing.KeyParts) Range(org.apache.accumulo.core.data.Range) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Example 9 with TemporalInterval

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);
    }
}
Also used : MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 10 with TemporalInterval

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);
    }
}
Also used : MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Aggregations

TemporalInterval (org.apache.rya.indexing.TemporalInterval)24 Test (org.junit.Test)16 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)12 Statement (org.openrdf.model.Statement)11 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10 TemporalInstant (org.apache.rya.indexing.TemporalInstant)7 RyaStatement (org.apache.rya.api.domain.RyaStatement)6 MongoTemporalIndexer (org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer)5 DateTime (org.joda.time.DateTime)5 Matcher (java.util.regex.Matcher)4 IOException (java.io.IOException)3 RyaURI (org.apache.rya.api.domain.RyaURI)3 Event (org.apache.rya.indexing.geotemporal.model.Event)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 ParseException (com.vividsolutions.jts.io.ParseException)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)2 GmlParser (org.apache.rya.indexing.mongodb.geo.GmlParser)2 Literal (org.openrdf.model.Literal)2