use of org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration in project incubator-rya by apache.
the class StoreToStoreIT method getChildMongo.
private static MongoRyaStatementStore getChildMongo() throws Exception {
final MongoClient mongo = getNewMongoResources(RYA_INSTANCE);
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
dao.setConf(new StatefulMongoDBRdfConfiguration(ITBase.getConf(mongo), mongo));
dao.init();
final MongoRyaStatementStore store = new MongoRyaStatementStore(mongo, RYA_INSTANCE, dao);
clients.add(mongo);
return store;
}
use of org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration in project incubator-rya by apache.
the class StoreToStoreIT method getParentMongo.
private static TimestampPolicyMongoRyaStatementStore getParentMongo() throws Exception {
final MongoClient mongo = getNewMongoResources(RYA_INSTANCE);
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
dao.setConf(new StatefulMongoDBRdfConfiguration(ITBase.getConf(mongo), mongo));
dao.init();
final MongoRyaStatementStore store = new MongoRyaStatementStore(mongo, RYA_INSTANCE, dao);
final TimestampPolicyMongoRyaStatementStore timeStore = new TimestampPolicyMongoRyaStatementStore(store, currentDate, RYA_INSTANCE);
clients.add(mongo);
return timeStore;
}
use of org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration in project incubator-rya by apache.
the class RyaQueryEngineFactory method getQueryEngine.
@SuppressWarnings("unchecked")
public static <C extends RdfCloudTripleStoreConfiguration> RyaQueryEngine<C> getQueryEngine(RdfCloudTripleStoreConfiguration conf) {
if (conf instanceof AccumuloRdfConfiguration) {
AccumuloRdfConfiguration aConf = (AccumuloRdfConfiguration) conf;
Instance instance;
String instanceName = aConf.get("sc.cloudbase.instancename");
String user = aConf.get("sc.cloudbase.username");
String password = aConf.get("sc.cloudbase.password");
if (aConf.getBoolean(".useMockInstance", false)) {
instance = new MockInstance(instanceName);
} else {
String zookeepers = aConf.get("sc.cloudbase.zookeepers");
instance = new ZooKeeperInstance(instanceName, zookeepers);
}
Connector conn;
try {
conn = instance.getConnector(user, new PasswordToken(password));
} catch (AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException(e);
}
return (RyaQueryEngine<C>) new AccumuloRyaQueryEngine(conn, aConf);
} else if (conf instanceof StatefulMongoDBRdfConfiguration && ConfigUtils.getUseMongo(conf)) {
StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
MongoDBQueryEngine mongoQueryEngine = new MongoDBQueryEngine();
mongoQueryEngine.setConf(mongoConf);
return (RyaQueryEngine<C>) mongoQueryEngine;
} else {
throw new IllegalArgumentException("Invalid configuration type.");
}
}
use of org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration in project incubator-rya by apache.
the class MongoPcjIndexSetProvider method getIndices.
@Override
protected List<ExternalTupleSet> getIndices() throws PcjIndexSetException {
try {
final StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
final MongoClient client = mongoConf.getMongoClient();
final MongoPcjDocuments pcjDocs = new MongoPcjDocuments(client, mongoConf.getRyaInstanceName());
List<String> documents = null;
documents = mongoConf.getPcjTables();
// this maps associates pcj document name with pcj sparql query
final Map<String, String> indexDocuments = Maps.newLinkedHashMap();
try (final PrecomputedJoinStorage storage = new MongoPcjStorage(client, mongoConf.getRyaInstanceName())) {
final boolean docsProvided = documents != null && !documents.isEmpty();
if (docsProvided) {
// if tables provided, associate table name with sparql
for (final String doc : documents) {
indexDocuments.put(doc, storage.getPcjMetadata(doc).getSparql());
}
} else if (hasRyaDetails()) {
// If this is a newer install of Rya, and it has PCJ Details, then
// use those.
final List<String> ids = storage.listPcjs();
for (final String pcjId : ids) {
indexDocuments.put(pcjId, storage.getPcjMetadata(pcjId).getSparql());
}
} else {
// Otherwise figure it out by getting document IDs.
documents = pcjDocs.listPcjDocuments();
for (final String pcjId : documents) {
if (pcjId.startsWith("INDEX")) {
indexDocuments.put(pcjId, pcjDocs.getPcjMetadata(pcjId).getSparql());
}
}
}
}
final List<ExternalTupleSet> index = Lists.newArrayList();
if (indexDocuments.isEmpty()) {
log.info("No Index found");
} else {
for (final String pcjID : indexDocuments.keySet()) {
final String indexSparqlString = indexDocuments.get(pcjID);
index.add(new MongoPcjQueryNode(indexSparqlString, pcjID, pcjDocs));
}
}
return index;
} catch (final PCJStorageException | MalformedQueryException e) {
throw new PcjIndexSetException("Failed to get indicies for this PCJ index.", e);
}
}
use of org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method populatePcj.
/**
* Ensure when results are already stored in Rya, that we are able to populate
* the PCJ table for a new SPARQL query using those results.
* <p>
* The method being tested is: {@link PcjTables#populatePcj(Connector, String, RepositoryConnection, String)}
*/
@Test
public void populatePcj() throws Exception {
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
dao.init();
final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
ryaStore.setRyaDAO(dao);
ryaStore.initialize();
final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
ryaConn.begin();
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 " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = "testPcj";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Populate the PCJ table using a Rya connection.
pcjs.populatePcj(pcjTableName, ryaConn);
final Collection<BindingSet> fetchedResults = loadPcjResults(pcjTableName);
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(3, metadata.getCardinality());
// Ensure the expected results match those that were stored.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(alice, bob, charlie);
assertEquals(expected, fetchedResults);
} finally {
ryaConn.close();
ryaStore.shutDown();
}
}
Aggregations