Search in sources :

Example 1 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryIntervalEquals.

/**
 * Test method for
 * {@link org.apache.rya.indexing.Mongo.temporal.MongoTemporalIndexer#queryIntervalEquals(TemporalInterval, StatementConstraints)}
 * .
 * @throws IOException
 * @throws QueryEvaluationException
 */
@Test
public void testQueryIntervalEquals() throws IOException, QueryEvaluationException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
        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));
        // instance at 4 seconds
        tIndexer.storeStatement(convertStatement(seriesSpo[4]));
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryIntervalEquals(tvB02_E40, EMPTY_CONSTRAINTS);
        // Should be found twice:
        assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but actually returned empty results. spo_B02_E40=" + spo_B02_E40, iter.hasNext());
        assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but does not match.", spo_B02_E40.equals(iter.next()));
        assertFalse("queryIntervalEquals: Find no more than one, but actually has more.", iter.hasNext());
    }
}
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) Test(org.junit.Test)

Example 2 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer 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 3 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryInstantAfterInstant.

/**
 * Test instant after a given instant.
 * From the series: instant {equal, before, after} instant
 * @throws MongoSecurityException
 * @throws MongoException
 * @throws TableNotFoundException
 */
@Test
public void testQueryInstantAfterInstant() throws IOException, QueryEvaluationException, TableNotFoundException, MongoException {
    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 instant for s seconds after the uniform time.
        final int searchForSeconds = 4;
        final int expectedResultCount = 9;
        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
            // <== logic here
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], EMPTY_CONSTRAINTS);
        int count = 0;
        while (iter.hasNext()) {
            final Statement s = iter.next();
            // <== logic here
            final Statement nextExpectedStatement = seriesSpo[searchForSeconds + count + 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) Test(org.junit.Test)

Example 4 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer 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)

Example 5 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer 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);
    }
}
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

RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)13 MongoTemporalIndexer (org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer)13 Test (org.junit.Test)13 Statement (org.openrdf.model.Statement)13 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)11 TemporalInterval (org.apache.rya.indexing.TemporalInterval)5 URI (org.openrdf.model.URI)3 ValueFactory (org.openrdf.model.ValueFactory)3 StatementImpl (org.openrdf.model.impl.StatementImpl)3 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)3 DB (com.mongodb.DB)1 DBCollection (com.mongodb.DBCollection)1 StatementConstraints (org.apache.rya.indexing.StatementConstraints)1