use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class AccumuloDeletePCJIT method dropAndDestroyPCJ.
@Test
public void dropAndDestroyPCJ() throws InstanceDoesNotExistException, RyaClientException, PCJStorageException, RepositoryException, AccumuloException, AccumuloSecurityException, RyaDAOException {
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
// Create a PCJ.
final String sparql1 = "SELECT ?x " + "WHERE { " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId1 = createPCJ.createPCJ(getRyaInstanceName(), sparql1);
// Create a PCJ.
final String sparql2 = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "}";
final String pcjId2 = createPCJ.createPCJ(getRyaInstanceName(), sparql2);
// Verify a Query ID was added for the query within the Fluo app.
List<String> fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
assertEquals(2, fluoQueryIds.size());
// Insert some statements into Rya.
final ValueFactory vf = ryaRepo.getValueFactory();
ryaConn.add(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
// Verify the correct results were exported.
fluo.waitForObservers();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
assertEquals("the PCJ's metadata was added the storage.", 2, pcjStorage.listPcjs().size());
// Delete all PCJ's.
AccumuloRyaDAO dao = RyaSailFactory.getAccumuloDAOWithUpdatedConfig(conf);
dao.dropAndDestroy();
// Ensure the PCJ's metadata has been removed from the storage.
assertTrue("the PCJ's metadata has been removed from the storage.", pcjStorage.listPcjs().isEmpty());
// Ensure the PCJ has been removed from the Fluo application.
fluo.waitForObservers();
// Verify Query IDs were deleted for the query within the Fluo app.
// TODO this fails, shows expected 0, but was 2.
// fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
// assertEquals("Verify Query IDs were deleted for the query within the Fluo app.", 0, fluoQueryIds.size());
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class AccumuloIndexSetProvider method getIndices.
@Override
protected List<ExternalTupleSet> getIndices() throws PcjIndexSetException {
requireNonNull(conf);
try {
final String tablePrefix = requireNonNull(conf.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX));
final Connector conn = requireNonNull(ConfigUtils.getConnector(conf));
List<String> tables = null;
if (conf instanceof RdfCloudTripleStoreConfiguration) {
tables = ((RdfCloudTripleStoreConfiguration) conf).getPcjTables();
}
// this maps associates pcj table name with pcj sparql query
final Map<String, String> indexTables = Maps.newLinkedHashMap();
try (final PrecomputedJoinStorage storage = new AccumuloPcjStorage(conn, tablePrefix)) {
final PcjTableNameFactory pcjFactory = new PcjTableNameFactory();
final boolean tablesProvided = tables != null && !tables.isEmpty();
if (tablesProvided) {
// if tables provided, associate table name with sparql
for (final String table : tables) {
indexTables.put(table, storage.getPcjMetadata(pcjFactory.getPcjId(table)).getSparql());
}
} else if (hasRyaDetails(tablePrefix, conn)) {
// 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 id : ids) {
indexTables.put(pcjFactory.makeTableName(tablePrefix, id), storage.getPcjMetadata(id).getSparql());
}
} else {
// Otherwise figure it out by scanning tables.
final PcjTables pcjTables = new PcjTables();
for (final String table : conn.tableOperations().list()) {
if (table.startsWith(tablePrefix + "INDEX")) {
indexTables.put(table, pcjTables.getPcjMetadata(conn, table).getSparql());
}
}
}
}
// use table name sparql map (indexTables) to create {@link
// AccumuloIndexSet}
final List<ExternalTupleSet> index = Lists.newArrayList();
if (indexTables.isEmpty()) {
log.info("No Index found");
} else {
for (final String table : indexTables.keySet()) {
final String indexSparqlString = indexTables.get(table);
index.add(new AccumuloIndexSet(indexSparqlString, conf, table));
}
}
return index;
} catch (final PCJStorageException | AccumuloException | AccumuloSecurityException | MalformedQueryException | SailException | QueryEvaluationException | TableNotFoundException e) {
throw new PcjIndexSetException("Failed to retrieve the indicies.", e);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class MongoPcjStorageIT method listResults.
@Test
public void listResults() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> visiSets = new HashSet<>();
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
visiSets.add(new VisibilityBindingSet(aliceBS, ""));
expectedResults.add(aliceBS);
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
visiSets.add(new VisibilityBindingSet(charlieBS, ""));
expectedResults.add(charlieBS);
pcjStorage.addResults(pcjId, visiSets);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class MongoPcjStorageIT method dropPCJ.
@Test
public void dropPCJ() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
// Delete the PCJ that was just created.
pcjStorage.dropPcj(pcjId);
// Ensure the Rya details have been updated to no longer include the PCJ's ID.
final ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
assertFalse(detailsMap.containsKey(pcjId));
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class MongoPcjStorageIT method purge.
@Test
public void purge() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
expectedResults.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
expectedResults.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, expectedResults);
// Purge the PCJ.
pcjStorage.purge(pcjId);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertTrue(results.isEmpty());
// Make sure the PCJ metadata was updated.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
Aggregations