use of org.apache.rya.indexing.pcj.storage.PcjMetadata 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.PcjMetadata 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.PcjMetadata in project incubator-rya by apache.
the class PcjTablesTest method pcjMetadata_hashCode.
@Test
public void pcjMetadata_hashCode() {
PcjMetadata meta1 = new PcjMetadata("A SPARQL string.", 5, Sets.newHashSet(new VariableOrder("a", "b", "c"), new VariableOrder("d", "e", "f")));
PcjMetadata meta2 = new PcjMetadata("A SPARQL string.", 5, Sets.newHashSet(new VariableOrder("a", "b", "c"), new VariableOrder("d", "e", "f")));
assertEquals(meta1.hashCode(), meta2.hashCode());
}
use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class CreateFluoPcj method createPcj.
/**
* Tells the Fluo PCJ Updater application to maintain a new PCJ. The method takes in an
* instance of {@link PrecomputedJoinStorage} to verify that a PCJ with the given pcjId exists.
* Results are exported to a PCJ table with the provided pcjId according to the Rya
* {@link ExportStrategy}.
*
* @param pcjId - Identifies the PCJ that will be updated by the Fluo app. (not null)
* @param pcjStorage - Provides access to the PCJ index. (not null)
* @param fluo - A connection to the Fluo application that updates the PCJ index. (not null)
* @return The metadata that was written to the Fluo application for the PCJ.
* @throws MalformedQueryException The SPARQL query stored for the {@code pcjId} is malformed.
* @throws PcjException The PCJ Metadata for {@code pcjId} could not be read from {@code pcjStorage}.
* @throws UnsupportedQueryException
*/
public FluoQuery createPcj(final String pcjId, final PrecomputedJoinStorage pcjStorage, final FluoClient fluo) throws MalformedQueryException, PcjException, UnsupportedQueryException {
requireNonNull(pcjId);
requireNonNull(pcjStorage);
requireNonNull(fluo);
// Parse the query's structure for the metadata that will be written to fluo.
final PcjMetadata pcjMetadata = pcjStorage.getPcjMetadata(pcjId);
final String sparql = pcjMetadata.getSparql();
return createPcj(pcjId, sparql, Sets.newHashSet(ExportStrategy.RYA), fluo);
}
use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class ListQueriesCommand method execute.
@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException {
checkNotNull(accumulo);
checkNotNull(fluo);
checkNotNull(args);
log.trace("Executing the List Queries Command...");
// Parse the command line arguments.
final Parameters params = new Parameters();
try {
new JCommander(params, args);
} catch (final ParameterException e) {
throw new ArgumentsException("Could not list the queries because of invalid command line parameters.", e);
}
// Fetch the PCJ metadata that will be included in the report.
final GetPcjMetadata getPcjMetadata = new GetPcjMetadata();
final Map<String, PcjMetadata> metadata = new HashMap<String, PcjMetadata>();
try {
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumulo, ryaTablePrefix);
if (params.queryId != null) {
log.trace("Fetch the PCJ Metadata from Accumulo for Query ID '" + params.queryId + "'.");
metadata.put(params.queryId, getPcjMetadata.getMetadata(pcjStorage, fluo, params.queryId));
} else {
log.trace("Fetch the PCJ Metadata from Accumulo for all queries that are being updated by Fluo.");
metadata.putAll(getPcjMetadata.getMetadata(pcjStorage, fluo));
}
} catch (NotInFluoException | NotInAccumuloException e) {
throw new ExecutionException("Could not fetch some of the metadata required to build the report.", e);
}
// Write the metadata to the console.
log.trace("Rendering the queries report...");
if (metadata.isEmpty()) {
System.out.println("No queries are being tracked by Fluo.");
} else {
final PcjMetadataRenderer renderer = new PcjMetadataRenderer();
try {
final String report = renderer.render(metadata);
System.out.println("The number of Queries that are being tracked by Fluo: " + metadata.size());
System.out.println(report);
} catch (final Exception e) {
throw new ExecutionException("Unable to render the query metadata report for output.", e);
}
}
log.trace("Finished executing the List Queries Command.");
}
Aggregations