use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata in project incubator-rya by apache.
the class AccumuloPeriodicQueryResultStorageIT method testCreateAndMeta.
@Test
public void testCreateAndMeta() throws PeriodicQueryStorageException {
String sparql = "select ?x where { ?x <urn:pred> ?y.}";
VariableOrder varOrder = new VariableOrder("periodicBinId", "x");
PeriodicQueryStorageMetadata expectedMeta = new PeriodicQueryStorageMetadata(sparql, varOrder);
String id = periodicStorage.createPeriodicQuery(sparql);
Assert.assertEquals(expectedMeta, periodicStorage.getPeriodicQueryMetadata(id));
Assert.assertEquals(Arrays.asList(nameFactory.makeTableName(RYA, id)), periodicStorage.listPeriodicTables());
periodicStorage.deletePeriodicQuery(id);
}
use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata in project incubator-rya by apache.
the class AccumuloPeriodicQueryResultStorage method listResults.
@Override
public CloseableIterator<BindingSet> listResults(final String queryId, final Optional<Long> binId) throws PeriodicQueryStorageException {
requireNonNull(queryId);
final String tableName = tableNameFactory.makeTableName(ryaInstance, queryId);
// 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 PeriodicQueryStorageMetadata metadata = getPeriodicQueryMetadata(queryId);
final VariableOrder varOrder = metadata.getVariableOrder();
try {
// Fetch only the Binding Sets whose Variable Order matches the
// selected one.
final Scanner scanner = accumuloConn.createScanner(tableName, auths);
scanner.fetchColumnFamily(new Text(varOrder.toString()));
if (binId.isPresent()) {
scanner.setRange(Range.prefix(getRowPrefix(binId.get())));
}
return new AccumuloValueBindingSetIterator(scanner);
} catch (final Exception e) {
throw new PeriodicQueryStorageException(String.format("PCJ Table does not exist for name '%s'.", tableName), e);
}
}
Aggregations