Search in sources :

Example 1 with PeriodicQueryStorageMetadata

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);
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) PeriodicQueryStorageMetadata(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata) Test(org.junit.Test)

Example 2 with PeriodicQueryStorageMetadata

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);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) PeriodicQueryStorageMetadata(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata) Text(org.apache.hadoop.io.Text) PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MalformedQueryException(org.openrdf.query.MalformedQueryException) BindingSetConversionException(org.apache.rya.indexing.pcj.storage.accumulo.BindingSetConverter.BindingSetConversionException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Aggregations

PeriodicQueryStorageMetadata (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Text (org.apache.hadoop.io.Text)1 PeriodicQueryStorageException (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException)1 BindingSetConversionException (org.apache.rya.indexing.pcj.storage.accumulo.BindingSetConverter.BindingSetConversionException)1 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)1 Test (org.junit.Test)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1