use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetJoinOnProperty.
/**
* Tests if the StatementMetadataNode joins BindingSet correctly for
* variables appearing in metadata statements. In this case, the metadata
* statements are (_:blankNode <http://createdOn 2017-01-04 ) and
* (_:blankNode <http://createdBy> ?y). The variable ?y appears as the
* object in the above metadata statement and its values are joined to the
* constraint BindingSets in the example below.
*/
@Test
public void simpleQueryWithBindingSetJoinOnProperty() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement1);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
QueryBindingSet bsConstraint = new QueryBindingSet();
bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
bsConstraint.addBinding("y", new LiteralImpl("Doug"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(0, bsList.size());
dao.delete(statement1, conf);
} finally {
dao.destroy();
}
}
use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<?> node = new StatementMetadataNode<>(spList, conf);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(bs, bsList.get(0));
dao.delete(statement, conf);
} finally {
dao.destroy();
}
}
use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.
the class PcjDocumentsWithMockTest method populatePcj.
@Test
public void populatePcj() throws Exception {
final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
dao.init();
ryaStore.setRyaDAO(dao);
ryaStore.initialize();
final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
try {
// Load some Triples into Rya.
final Set<Statement> triples = new HashSet<>();
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
for (final Statement triple : triples) {
ryaConn.add(triple);
}
// Create a PCJ table that will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(conf.getRyaInstanceName(), "testPcj");
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createAndPopulatePcj(ryaConn, pcjTableName, sparql);
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(4, metadata.getCardinality());
} finally {
ryaConn.close();
ryaStore.shutDown();
}
}
use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.
the class MongoStatementMetadataIT method simpleQueryWithoutBindingSetInvalidProperty.
/**
* Tests if results are filtered correctly using the metadata properties. In
* this case, the date for the ingested RyaStatement differs from the date
* specified in the query.
*
* @throws MalformedQueryException
* @throws QueryEvaluationException
* @throws RyaDAOException
*/
@Test
public void simpleQueryWithoutBindingSetInvalidProperty() throws Exception {
Sail sail = RyaSailFactory.getInstance(conf);
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Doug"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-15"));
final RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
final List<BindingSet> bsList = new ArrayList<>();
while (result.hasNext()) {
bsList.add(result.next());
}
assertEquals(0, bsList.size());
dao.delete(statement, conf);
} finally {
dao.destroy();
sail.shutDown();
}
}
use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.
the class MongoStatementMetadataIT method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() throws Exception {
Sail sail = RyaSailFactory.getInstance(conf);
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
final RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
final List<BindingSet> bsList = new ArrayList<>();
while (result.hasNext()) {
bsList.add(result.next());
}
assertEquals(1, bsList.size());
assertEquals(bs, bsList.get(0));
dao.delete(statement, conf);
} finally {
dao.destroy();
sail.shutDown();
}
}
Aggregations