Search in sources :

Example 21 with SailRepositoryConnection

use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoPcjIntegrationTest method testEvaluateThreeIndexValidate.

@Test
public void testEvaluateThreeIndexValidate() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final IRI superclass = VF.createIRI("uri:superclass");
        final IRI superclass2 = VF.createIRI("uri:superclass2");
        final IRI howlsAt = VF.createIRI("uri:howlsAt");
        final IRI subType = VF.createIRI("uri:subType");
        final IRI superSuperclass = VF.createIRI("uri:super_superclass");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, VF.createLiteral("label"));
        conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2"));
        conn.add(sub, howlsAt, superclass);
        conn.add(superclass, subType, superSuperclass);
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final String indexSparqlString2 = // 
        "" + // 
        "SELECT ?o ?f ?e ?c ?l  " + // 
        "{" + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        final String indexSparqlString3 = // 
        "" + // 
        "SELECT ?wolf ?sheep ?chicken  " + // 
        "{" + // 
        "  ?wolf <uri:howlsAt> ?sheep . " + // 
        "  ?sheep <uri:subType> ?chicken. " + // 
        "}";
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?f ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "  ?e <uri:howlsAt> ?f. " + // 
        "  ?f <uri:subType> ?o. " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final MongoPcjQueryNode ais1 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 1);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 2, conf.getRyaInstanceName(), indexSparqlString2);
        final MongoPcjQueryNode ais2 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 2);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 3, conf.getRyaInstanceName(), indexSparqlString3);
        final MongoPcjQueryNode ais3 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 3);
        final List<ExternalTupleSet> index = new ArrayList<>();
        index.add(ais1);
        index.add(ais3);
        index.add(ais2);
        ParsedQuery pq = null;
        final SPARQLParser sp = new SPARQLParser();
        pq = sp.parseQuery(queryString, null);
        final List<TupleExpr> teList = Lists.newArrayList();
        final TupleExpr te = pq.getTupleExpr();
        final PCJOptimizer pcj = new PCJOptimizer(index, false, new MongoPcjIndexSetProvider(new StatefulMongoDBRdfConfiguration(conf, getMongoClient())));
        pcj.optimize(te, null, null);
        teList.add(te);
        final IndexPlanValidator ipv = new IndexPlanValidator(false);
        assertTrue(ipv.isValid(te));
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjQueryNode(org.apache.rya.indexing.mongodb.pcj.MongoPcjQueryNode) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Sail(org.eclipse.rdf4j.sail.Sail) MongoPcjIndexSetProvider(org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Test(org.junit.Test)

Example 22 with SailRepositoryConnection

use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoPcjIntegrationTest method testEvaluateSingleIndex.

@Test
public void testEvaluateSingleIndex() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?e ?l ?c " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "}";
        final CountingResultHandler crh1 = new CountingResultHandler();
        final CountingResultHandler crh2 = new CountingResultHandler();
        conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
        pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
        assertEquals(crh1.getCount(), crh2.getCount());
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Test(org.junit.Test)

Example 23 with SailRepositoryConnection

use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoPcjIntegrationTest method testEvaluateTwoIndexValidate.

@Test
public void testEvaluateTwoIndexValidate() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final IRI superclass = VF.createIRI("uri:superclass");
        final IRI superclass2 = VF.createIRI("uri:superclass2");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, VF.createLiteral("label"));
        conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final String indexSparqlString2 = // 
        "" + // 
        "SELECT ?o ?f ?e ?c ?l  " + // 
        "{" + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?f ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final MongoPcjQueryNode ais1 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 1);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 2, conf.getRyaInstanceName(), indexSparqlString2);
        final MongoPcjQueryNode ais2 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 2);
        final List<ExternalTupleSet> index = new ArrayList<>();
        index.add(ais1);
        index.add(ais2);
        ParsedQuery pq = null;
        final SPARQLParser sp = new SPARQLParser();
        pq = sp.parseQuery(queryString, null);
        final List<TupleExpr> teList = Lists.newArrayList();
        final TupleExpr te = pq.getTupleExpr();
        final PCJOptimizer pcj = new PCJOptimizer(index, false, new MongoPcjIndexSetProvider(new StatefulMongoDBRdfConfiguration(conf, getMongoClient())));
        pcj.optimize(te, null, null);
        teList.add(te);
        final IndexPlanValidator ipv = new IndexPlanValidator(false);
        assertTrue(ipv.isValid(te));
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjQueryNode(org.apache.rya.indexing.mongodb.pcj.MongoPcjQueryNode) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Sail(org.eclipse.rdf4j.sail.Sail) MongoPcjIndexSetProvider(org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Test(org.junit.Test)

Example 24 with SailRepositoryConnection

use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class AccumuloRyaSailFactoryLoadFilesIT method testFileLoading.

@Test
public void testFileLoading() throws Exception {
    log.info("Starting file loading test...");
    final String query = "SELECT * WHERE { ?s ?p ?o . FILTER(?p != <" + RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE + ">) }";
    final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }";
    for (final TestFile testFile : TestFileUtils.TEST_FILES) {
        final String testFilePath = testFile.getPath();
        final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null);
        log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName());
        try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) {
            addTriples(ryaRepository, rdfContent, rdfFormat);
        }
        SailRepositoryConnection queryConn = null;
        try {
            log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file.");
            queryConn = ryaRepository.getConnection();
            final int count = performTupleQuery(query, queryConn);
            assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count);
        } finally {
            closeQuietly(queryConn);
        }
        SailRepositoryConnection deleteConn = null;
        try {
            log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file.");
            deleteConn = ryaRepository.getConnection();
            final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
            update.execute();
        } finally {
            closeQuietly(deleteConn);
        }
    }
    log.info("File loading test finished.");
}
Also used : InputStream(java.io.InputStream) TestFile(org.apache.rya.helper.TestFile) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Update(org.eclipse.rdf4j.query.Update) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) Test(org.junit.Test)

Example 25 with SailRepositoryConnection

use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoStatementMetadataIT method simpleQueryWithBindingSet.

@Test
public void simpleQueryWithBindingSet() throws Exception {
    final Sail sail = RyaSailFactory.getInstance(conf);
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final StatementMetadata metadata = new StatementMetadata();
        metadata.addMetadata(new RyaIRI("http://createdBy"), new RyaType("Joe"));
        metadata.addMetadata(new RyaIRI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
        final RyaStatement statement1 = new RyaStatement(new RyaIRI("http://Joe"), new RyaIRI("http://worksAt"), new RyaType("CoffeeShop"), new RyaIRI("http://context"), "", metadata);
        final RyaStatement statement2 = new RyaStatement(new RyaIRI("http://Joe"), new RyaIRI("http://worksAt"), new RyaType("HardwareStore"), new RyaIRI("http://context"), "", metadata);
        dao.add(statement1);
        dao.add(statement2);
        final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
        final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
        final Set<BindingSet> expected = new HashSet<>();
        final QueryBindingSet expected1 = new QueryBindingSet();
        expected1.addBinding("x", VF.createLiteral("CoffeeShop"));
        expected1.addBinding("y", VF.createLiteral("Joe"));
        final QueryBindingSet expected2 = new QueryBindingSet();
        expected2.addBinding("x", VF.createLiteral("HardwareStore"));
        expected2.addBinding("y", VF.createLiteral("Joe"));
        expected.add(expected1);
        expected.add(expected2);
        final Set<BindingSet> bsSet = new HashSet<>();
        while (result.hasNext()) {
            bsSet.add(result.next());
        }
        assertEquals(expected, bsSet);
        dao.delete(statement1, conf);
        dao.delete(statement2, conf);
    } finally {
        dao.destroy();
        sail.shutDown();
    }
}
Also used : QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) RyaIRI(org.apache.rya.api.domain.RyaIRI) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) Sail(org.eclipse.rdf4j.sail.Sail) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)65 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)44 Sail (org.eclipse.rdf4j.sail.Sail)37 Test (org.junit.Test)35 BindingSet (org.eclipse.rdf4j.query.BindingSet)24 HashSet (java.util.HashSet)17 MapBindingSet (org.eclipse.rdf4j.query.impl.MapBindingSet)15 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)13 Statement (org.eclipse.rdf4j.model.Statement)11 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)9 ArrayList (java.util.ArrayList)8 Connector (org.apache.accumulo.core.client.Connector)8 Configuration (org.apache.hadoop.conf.Configuration)8 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)7 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)7 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)7 RyaIRI (org.apache.rya.api.domain.RyaIRI)6