Search in sources :

Example 11 with MongoTemporalIndexer

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

the class MongoTemporalIndexerIT method testDelete.

@Test
public void testDelete() throws IOException, MongoException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
        final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
        final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
        final String testDate2016InET = "2016-12-31T20:59:59-05:00";
        // These should be stored because they are in the predicate list.
        // BUT they will get converted to the same exact datetime in UTC.
        final Statement s1 = new StatementImpl(vf.createURI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST));
        final Statement s2 = new StatementImpl(vf.createURI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET));
        tIndexer.storeStatement(convertStatement(s1));
        tIndexer.storeStatement(convertStatement(s2));
        final String dbName = conf.getMongoDBName();
        final DB db = super.getMongoClient().getDB(dbName);
        DBCollection collection = db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya") + tIndexer.getCollectionName());
        printTables(tIndexer, "junit testing: Temporal entities stored in testDelete before delete");
        // 4 index entries per statement
        assertEquals("Number of rows stored.", 2, collection.count());
        tIndexer.deleteStatement(convertStatement(s1));
        tIndexer.deleteStatement(convertStatement(s2));
        printTables(tIndexer, "junit testing: Temporal entities stored in testDelete after delete");
        assertEquals("Number of rows stored after delete.", 0, collection.count());
    }
}
Also used : DBCollection(com.mongodb.DBCollection) MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) DB(com.mongodb.DB) Test(org.junit.Test)

Example 12 with MongoTemporalIndexer

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

the class MongoTemporalIndexerIT method testStoreStatement.

/**
 * Test method for {@link MongoTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)}
 */
@Test
public void testStoreStatement() throws IOException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
        final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
        // Should not be stored because they are not in the predicate list
        final String validDateStringWithThirteens = "1313-12-13T13:13:13Z";
        tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), RDFS.LABEL, vf.createLiteral(validDateStringWithThirteens))));
        final String invalidDateString = "ThisIsAnInvalidDate";
        tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral(invalidDateString))));
        // These are different datetimes instant but from different time zones.
        // This is an arbitrary zone, BRST=Brazil, better if not local.
        // same as "2015-01-01T01:59:59Z"
        final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
        // next year, same as "2017-01-01T01:59:59Z"
        final String testDate2016InET = "2016-12-31T20:59:59-05:00";
        // These should be stored because they are in the predicate list.
        // BUT they will get converted to the same exact datetime in UTC.
        final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST));
        final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET));
        tIndexer.storeStatement(convertStatement(s3));
        tIndexer.storeStatement(convertStatement(s4));
        // This should not be stored because the object is not a literal
        tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1_atTime, vf.createURI("in:valid"))));
        printTables(tIndexer, "junit testing: Temporal entities stored in testStoreStatement");
        assertEquals(2, tIndexer.getCollection().find().count());
    }
}
Also used : MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 13 with MongoTemporalIndexer

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

the class MongoTemporalIndexerIT method testQueryInstantBeforeInstant.

/**
 * Test instant before a given instant.
 * From the series: instant {equal, before, after} instant
 */
@Test
public void testQueryInstantBeforeInstant() 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 instant for s seconds after the uniform time.
        final int searchForSeconds = 4;
        final int expectedResultCount = 4;
        for (int s = 0; s <= searchForSeconds + 15; s++) {
            // <== logic here
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryInstantBeforeInstant(seriesTs[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) 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