use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class PcjTables method purgePcjTable.
/**
* Deletes all of the rows that are in a PCJ index and sets its cardinality back to 0.
*
* @param accumuloConn - Connects to the Accumulo that hosts the PCJ indices. (not null)
* @param pcjTableName - The name of the PCJ table that will be purged. (not null)
* @throws PCJStorageException Either the rows could not be dropped from the
* PCJ table or the metadata could not be written back to the table.
*/
public void purgePcjTable(final Connector accumuloConn, final String pcjTableName) throws PCJStorageException {
checkNotNull(accumuloConn);
checkNotNull(pcjTableName);
// Fetch the metadaata from the PCJ table.
final PcjMetadata oldMetadata = getPcjMetadata(accumuloConn, pcjTableName);
// Delete all of the rows
try {
accumuloConn.tableOperations().deleteRows(pcjTableName, null, null);
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
throw new PCJStorageException("Could not delete the rows of data from PCJ table named: " + pcjTableName, e);
}
// Store the new metadata.
final PcjMetadata newMetadata = new PcjMetadata(oldMetadata.getSparql(), 0L, oldMetadata.getVarOrders());
final List<Mutation> mutations = makeWriteMetadataMutations(newMetadata);
BatchWriter writer = null;
try {
writer = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
writer.addMutations(mutations);
writer.flush();
} catch (final TableNotFoundException | MutationsRejectedException e) {
throw new PCJStorageException("Could not rewrite the PCJ cardinality for table named '" + pcjTableName + "'. This table will not work anymore.", e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (final MutationsRejectedException e) {
throw new PCJStorageException("Could not close the batch writer.", e);
}
}
}
}
use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class MongoCreatePCJIT method createPCJ.
@Test
public void createPCJ() throws Exception {
final MongoConnectionDetails connectionDetails = getConnectionDetails();
final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = ryaClient.getCreatePCJ();
final Install installRya = ryaClient.getInstall();
final InstallConfiguration installConf = InstallConfiguration.builder().setEnablePcjIndex(true).build();
installRya.install(conf.getRyaInstanceName(), installConf);
System.out.println(getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("instance_details").find().first().toJson());
// Create a PCJ.
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId = createPCJ.createPCJ(conf.getRyaInstanceName(), sparql);
// Verify the RyaDetails were updated to include the new PCJ.
final Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(conf.getRyaInstanceName());
final ImmutableMap<String, PCJDetails> details = ryaDetails.get().getPCJIndexDetails().getPCJDetails();
final PCJDetails pcjDetails = details.get(pcjId);
assertEquals(pcjId, pcjDetails.getId());
assertFalse(pcjDetails.getLastUpdateTime().isPresent());
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final PcjMetadata pcjMetadata = pcjStorage.getPcjMetadata(pcjId);
// confirm that the pcj was added to the pcj store.
assertEquals(sparql, pcjMetadata.getSparql());
assertEquals(0L, pcjMetadata.getCardinality());
}
}
Aggregations