use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException in project incubator-rya by apache.
the class PcjTables method writeResults.
/**
* Add a collection of results to a specific PCJ table.
*
* @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
* @param pcjTableName - The name of the PCJ table that will receive the results. (not null)
* @param results - Binding sets that will be written to the PCJ table. (not null)
* @throws PCJStorageException The provided PCJ table doesn't exist, is missing the
* PCJ metadata, or the result could not be written to it.
*/
private void writeResults(final Connector accumuloConn, final String pcjTableName, final Collection<VisibilityBindingSet> results) throws PCJStorageException {
checkNotNull(accumuloConn);
checkNotNull(pcjTableName);
checkNotNull(results);
// Fetch the variable orders from the PCJ table.
final PcjMetadata metadata = getPcjMetadata(accumuloConn, pcjTableName);
// Write each result formatted using each of the variable orders.
BatchWriter writer = null;
try {
writer = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
for (final VisibilityBindingSet result : results) {
final Set<Mutation> addResultMutations = makeWriteResultMutations(metadata.getVarOrders(), result);
writer.addMutations(addResultMutations);
}
} catch (TableNotFoundException | MutationsRejectedException e) {
throw new PCJStorageException("Could not add results to the PCJ table named: " + pcjTableName, e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (final MutationsRejectedException e) {
throw new PCJStorageException("Could not add results to a PCJ table because some of the mutations were rejected.", e);
}
}
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException in project incubator-rya by apache.
the class PcjTables method listResults.
/**
* Get an {@link Iterator} over the {@link BindingSet}s that are stored in the PCJ table.
*
* @param accumuloConn - A connection to the Accumulo that hsots the PCJ table. (not null)
* @param pcjTableName - The name of the PCJ table that will be scanned. (not null)
* @param auths - the user's authorizations that will be used to scan the table. (not null)
* @return An iterator over all of the {@link BindingSet}s that are stored as
* results for the PCJ.
* @throws PCJStorageException The binding sets could not be fetched.
*/
public CloseableIterator<BindingSet> listResults(final Connector accumuloConn, final String pcjTableName, final Authorizations auths) throws PCJStorageException {
requireNonNull(pcjTableName);
// Fetch the Variable Orders for the binding sets and choose one of them. It
// doesn't matter which one we choose because they all result in the same output.
final PcjMetadata metadata = getPcjMetadata(accumuloConn, pcjTableName);
final VariableOrder varOrder = metadata.getVarOrders().iterator().next();
try {
// Fetch only the Binding Sets whose Variable Order matches the selected one.
final Scanner scanner = accumuloConn.createScanner(pcjTableName, auths);
scanner.fetchColumnFamily(new Text(varOrder.toString()));
// Return an Iterator that uses that scanner.
return new ScannerBindingSetIterator(scanner, varOrder);
} catch (final TableNotFoundException e) {
throw new PCJStorageException(String.format("PCJ Table does not exist for name '%s'.", pcjTableName), e);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException in project incubator-rya by apache.
the class PcjTables method populatePcj.
/**
* Scan Rya for results that solve the PCJ's query and store them in the PCJ table.
* <p>
* This method assumes the PCJ table has already been created.
*
* @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
* @param pcjTableName - The name of the PCJ table that will receive the results. (not null)
* @param ryaConn - A connection to the Rya store that will be queried to find results. (not null)
* @throws PCJStorageException If results could not be written to the PCJ table,
* the PCJ table does not exist, or the query that is being execute
* was malformed.
*/
public void populatePcj(final Connector accumuloConn, final String pcjTableName, final RepositoryConnection ryaConn) throws PCJStorageException {
checkNotNull(accumuloConn);
checkNotNull(pcjTableName);
checkNotNull(ryaConn);
try {
// Fetch the query that needs to be executed from the PCJ table.
final PcjMetadata pcjMetadata = getPcjMetadata(accumuloConn, pcjTableName);
final String sparql = pcjMetadata.getSparql();
// Query Rya for results to the SPARQL query.
final TupleQuery query = ryaConn.prepareTupleQuery(QueryLanguage.SPARQL, sparql);
final TupleQueryResult results = query.evaluate();
// Load batches of 1000 of them at a time into the PCJ table
final Set<VisibilityBindingSet> batch = new HashSet<>(1000);
while (results.hasNext()) {
batch.add(new VisibilityBindingSet(results.next()));
if (batch.size() == 1000) {
addResults(accumuloConn, pcjTableName, batch);
batch.clear();
}
}
if (!batch.isEmpty()) {
addResults(accumuloConn, pcjTableName, batch);
}
} catch (RepositoryException | MalformedQueryException | QueryEvaluationException e) {
throw new PCJStorageException("Could not populate a PCJ table with Rya results for the table named: " + pcjTableName, e);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException in project incubator-rya by apache.
the class AccumuloRemoveUser method removeUser.
@Override
public void removeUser(final String instanceName, final String username) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(instanceName);
requireNonNull(username);
// Update the instance details.
final RyaDetailsUpdater updater = new RyaDetailsUpdater(new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName));
try {
updater.update(originalDetails -> RyaDetails.builder(originalDetails).removeUser(username).build());
} catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new RyaClientException("Could not remove the user '" + username + "' from the Rya instance's details.", e);
}
// Revoke all access to all the instance's tables.
try {
// Build the list of tables that are present within the Rya instance.
final List<String> tables = new RyaTableNames().getTableNames(instanceName, getConnector());
// Update the user permissions for those tables.
for (final String table : tables) {
try {
TABLE_PERMISSIONS.revokeAllPermissions(username, table, getConnector());
} catch (AccumuloException | AccumuloSecurityException e) {
throw new RyaClientException("Could not revoke access to table '" + table + "' from user '" + username + "'.", e);
}
}
} catch (PCJStorageException | RyaDetailsRepositoryException e) {
throw new RyaClientException("Could not determine which tables exist for the '" + instanceName + "' instance of Rya.", e);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException in project incubator-rya by apache.
the class MongoDeletePCJ method deletePCJ.
@Override
public void deletePCJ(final String ryaInstanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(pcjId);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
try (final MongoPcjStorage pcjStore = new MongoPcjStorage(mongoClient, ryaInstanceName)) {
pcjStore.dropPcj(pcjId);
} catch (final PCJStorageException e) {
throw new RyaClientException("Unable to drop PCJ : " + pcjId, e);
}
}
Aggregations