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();
}
}
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();
}
}
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();
}
}
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.");
}
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();
}
}
Aggregations