use of org.apache.rya.rdftriplestore.RyaSailRepository 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.rdftriplestore.RyaSailRepository in project incubator-rya by apache.
the class AccumuloIndexSetTest method init.
@Before
public void init() throws AccumuloException, AccumuloSecurityException, RyaDAOException, RepositoryException, TableNotFoundException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException {
accumuloConn = ConfigUtils.getConnector(conf);
final TableOperations ops = accumuloConn.tableOperations();
if (ops.exists(prefix + "INDEX_" + "testPcj")) {
ops.delete(prefix + "INDEX_" + "testPcj");
}
ryaRepo = new RyaSailRepository(RyaSailFactory.getInstance(conf));
ryaConn = ryaRepo.getConnection();
}
use of org.apache.rya.rdftriplestore.RyaSailRepository in project incubator-rya by apache.
the class PcjTablesIT method setupRya.
/**
* Format a Mini Accumulo to be a Rya repository.
*
* @return The Rya repository sitting on top of the Mini Accumulo.
*/
private RyaSailRepository setupRya() throws AccumuloException, AccumuloSecurityException, RepositoryException {
// Setup the Rya Repository that will be used to create Repository Connections.
final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
final AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
crdfdao.setConnector(cluster.getConnector());
// Setup Rya configuration values.
final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
conf.setTablePrefix(getRyaInstanceName());
conf.setDisplayQueryPlan(true);
conf.setBoolean(USE_MOCK_INSTANCE, false);
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, getRyaInstanceName());
conf.set(CLOUDBASE_USER, cluster.getUsername());
conf.set(CLOUDBASE_PASSWORD, cluster.getPassword());
conf.set(CLOUDBASE_INSTANCE, cluster.getInstanceName());
crdfdao.setConf(conf);
ryaStore.setRyaDAO(crdfdao);
final RyaSailRepository ryaRepo = new RyaSailRepository(ryaStore);
ryaRepo.initialize();
return ryaRepo;
}
use of org.apache.rya.rdftriplestore.RyaSailRepository in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method createAndPopulatePcj.
/**
* Ensure the method that creates a new PCJ table, scans Rya for matches, and
* stores them in the PCJ table works.
* <p>
* The method being tested is: {@link PcjTables#createAndPopulatePcj(RepositoryConnection, Connector, String, String, String[], Optional)}
*/
@Test
public void createAndPopulatePcj() 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";
// Create and populate the PCJ table.
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(3, metadata.getCardinality());
// Scan Accumulo for the stored results.
final Collection<BindingSet> fetchedResults = loadPcjResults(pcjTableName);
// 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();
}
}
use of org.apache.rya.rdftriplestore.RyaSailRepository in project incubator-rya by apache.
the class PcjVisibilityIT method visibilitySimplified.
@Test
public void visibilitySimplified() throws Exception {
// Create a PCJ index within Rya.
final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "?customer <" + TALKS_TO + "> ?worker. " + "?worker <" + LIVES_IN + "> ?city. " + "?worker <" + WORKS_AT + "> <" + BURGER_JOINT + ">. " + "}";
final Connector accumuloConn = super.getAccumuloConnector();
final String instanceName = super.getMiniAccumuloCluster().getInstanceName();
final String zookeepers = super.getMiniAccumuloCluster().getZooKeepers();
final RyaClient ryaClient = AccumuloRyaClientFactory.build(createConnectionDetails(), accumuloConn);
final String pcjId = ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
// Grant the root user the "u" authorization.
super.getAccumuloConnector().securityOperations().changeUserAuthorizations(getUsername(), new Authorizations("u"));
// Setup a connection to the Rya instance that uses the "u" authorizations. This ensures
// any statements that are inserted will have the "u" authorization on them and that the
// PCJ updating application will have to maintain visibilities.
final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
ryaConf.setTablePrefix(getRyaInstanceName());
// Accumulo connection information.
ryaConf.setAccumuloUser(getUsername());
ryaConf.setAccumuloPassword(getPassword());
ryaConf.setAccumuloInstance(super.getAccumuloConnector().getInstance().getInstanceName());
ryaConf.setAccumuloZookeepers(super.getAccumuloConnector().getInstance().getZooKeepers());
ryaConf.set(ConfigUtils.CLOUDBASE_AUTHS, "u");
ryaConf.set(RdfCloudTripleStoreConfiguration.CONF_CV, "u");
// PCJ configuration information.
ryaConf.set(ConfigUtils.USE_PCJ, "true");
ryaConf.set(ConfigUtils.USE_PCJ_UPDATER_INDEX, "true");
ryaConf.set(ConfigUtils.FLUO_APP_NAME, super.getFluoConfiguration().getApplicationName());
ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType.ACCUMULO.toString());
ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType.FLUO.toString());
Sail sail = null;
RyaSailRepository ryaRepo = null;
RepositoryConnection ryaConn = null;
try {
sail = RyaSailFactory.getInstance(ryaConf);
ryaRepo = new RyaSailRepository(sail);
ryaConn = ryaRepo.getConnection();
// Load a few Statements into Rya.
ryaConn.add(VF.createStatement(ALICE, TALKS_TO, BOB));
ryaConn.add(VF.createStatement(BOB, LIVES_IN, HAPPYVILLE));
ryaConn.add(VF.createStatement(BOB, WORKS_AT, BURGER_JOINT));
// Wait for Fluo to finish processing.
super.getMiniFluo().waitForObservers();
// Fetch the exported result and show that its column visibility has been simplified.
final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), pcjId);
final Scanner scan = accumuloConn.createScanner(pcjTableName, new Authorizations("u"));
scan.fetchColumnFamily(new Text("customer;worker;city"));
final Entry<Key, Value> result = scan.iterator().next();
final Key key = result.getKey();
assertEquals(new Text("u"), key.getColumnVisibility());
} finally {
if (ryaConn != null) {
try {
ryaConn.close();
} finally {
}
}
if (ryaRepo != null) {
try {
ryaRepo.shutDown();
} finally {
}
}
if (sail != null) {
try {
sail.shutDown();
} finally {
}
}
}
}
Aggregations