Search in sources :

Example 1 with PeriodicQueryStorageException

use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException in project incubator-rya by apache.

the class CreatePeriodicQuery method createPeriodicQuery.

/**
 * Creates a Periodic Query by adding the query to Fluo and using the resulting
 * Fluo id to create a {@link PeriodicQueryResultStorage} table.  Additionally,
 * the associated PeriodicNotification is registered with the Periodic Query Service.
 *
 * @param sparql - sparql query registered to Fluo whose results are stored in PeriodicQueryResultStorage table
 * @param notificationClient - {@link PeriodicNotificationClient} for registering new PeriodicNotifications
 * @return FluoQuery indicating the metadata of the registered SPARQL query
 */
public FluoQuery createPeriodicQuery(String sparql, PeriodicNotificationClient notificationClient) throws PeriodicQueryCreationException {
    try {
        Optional<PeriodicQueryNode> optNode = PeriodicQueryUtil.getPeriodicNode(sparql);
        if (optNode.isPresent()) {
            PeriodicQueryNode periodicNode = optNode.get();
            String pcjId = FluoQueryUtils.createNewPcjId();
            // register query with Fluo
            CreateFluoPcj createPcj = new CreateFluoPcj();
            FluoQuery fluoQuery = createPcj.createPcj(pcjId, sparql, Sets.newHashSet(ExportStrategy.PERIODIC), fluoClient);
            // register query with PeriodicResultStorage table
            periodicStorage.createPeriodicQuery(pcjId, sparql);
            // create notification
            PeriodicNotification notification = PeriodicNotification.builder().id(pcjId).period(periodicNode.getPeriod()).timeUnit(periodicNode.getUnit()).build();
            // register notification with periodic notification app
            notificationClient.addNotification(notification);
            return fluoQuery;
        } else {
            throw new RuntimeException("Invalid PeriodicQuery.  Query must possess a PeriodicQuery Filter.");
        }
    } catch (MalformedQueryException | PeriodicQueryStorageException | UnsupportedQueryException e) {
        throw new PeriodicQueryCreationException(e);
    }
}
Also used : PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) MalformedQueryException(org.openrdf.query.MalformedQueryException) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) PeriodicQueryNode(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Example 2 with PeriodicQueryStorageException

use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException in project incubator-rya by apache.

the class CreatePeriodicQuery method createPeriodicQuery.

/**
 * Creates a Periodic Query by adding the query to Fluo and using the resulting
 * Fluo id to create a {@link PeriodicQueryResultStorage} table.
 *
 * @param sparql - sparql query registered to Fluo whose results are stored in PeriodicQueryResultStorage table
 * @return FluoQuery indicating the metadata of the registered SPARQL query
 */
public FluoQuery createPeriodicQuery(String sparql) throws PeriodicQueryCreationException {
    try {
        Optional<PeriodicQueryNode> optNode = PeriodicQueryUtil.getPeriodicNode(sparql);
        if (optNode.isPresent()) {
            String pcjId = FluoQueryUtils.createNewPcjId();
            // register query with Fluo
            CreateFluoPcj createPcj = new CreateFluoPcj();
            FluoQuery fluoQuery = createPcj.createPcj(pcjId, sparql, Sets.newHashSet(ExportStrategy.PERIODIC), fluoClient);
            // register query with PeriodicResultStorage table
            periodicStorage.createPeriodicQuery(pcjId, sparql);
            return fluoQuery;
        } else {
            throw new RuntimeException("Invalid PeriodicQuery.  Query must possess a PeriodicQuery Filter.");
        }
    } catch (MalformedQueryException | PeriodicQueryStorageException | UnsupportedQueryException e) {
        throw new PeriodicQueryCreationException(e);
    }
}
Also used : PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) MalformedQueryException(org.openrdf.query.MalformedQueryException) PeriodicQueryNode(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Example 3 with PeriodicQueryStorageException

use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException in project incubator-rya by apache.

the class AccumuloPeriodicQueryResultStorage method deletePeriodicQueryResults.

@Override
public void deletePeriodicQueryResults(final String queryId, final long binId) throws PeriodicQueryStorageException {
    final String tableName = tableNameFactory.makeTableName(ryaInstance, queryId);
    BatchDeleter deleter = null;
    try {
        final Text prefix = getRowPrefix(binId);
        deleter = accumuloConn.createBatchDeleter(tableName, auths, 1, new BatchWriterConfig());
        deleter.setRanges(Collections.singleton(Range.prefix(prefix)));
        deleter.delete();
    } catch (final Exception e) {
        throw new PeriodicQueryStorageException(e.getMessage());
    } finally {
        try {
            if (deleter != null) {
                deleter.close();
            }
        } catch (final Exception e) {
            throw new PeriodicQueryStorageException(e.getMessage());
        }
    }
}
Also used : BatchDeleter(org.apache.accumulo.core.client.BatchDeleter) PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) 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)

Example 4 with PeriodicQueryStorageException

use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException in project incubator-rya by apache.

the class AccumuloPeriodicQueryResultStorage method createPeriodicQuery.

@Override
public void createPeriodicQuery(final String queryId, final String sparql, final VariableOrder order) throws PeriodicQueryStorageException {
    Preconditions.checkNotNull(sparql);
    Preconditions.checkNotNull(queryId);
    Preconditions.checkNotNull(order);
    Preconditions.checkArgument(PeriodicQueryResultStorage.PeriodicBinId.equals(order.getVariableOrders().get(0)), "periodicBinId binding name must occur first in VariableOrder.");
    final String tableName = tableNameFactory.makeTableName(ryaInstance, queryId);
    final Set<VariableOrder> varOrders = new HashSet<>();
    varOrders.add(order);
    try {
        pcjTables.createPcjTable(accumuloConn, tableName, varOrders, sparql);
    } catch (final Exception e) {
        throw new PeriodicQueryStorageException(e.getMessage());
    }
}
Also used : PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) 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) HashSet(java.util.HashSet)

Example 5 with PeriodicQueryStorageException

use of org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException in project incubator-rya by apache.

the class AccumuloPeriodicQueryResultStorage method createPeriodicQuery.

@Override
public String createPeriodicQuery(final String queryId, final String sparql) throws PeriodicQueryStorageException {
    Set<String> bindingNames;
    try {
        bindingNames = new AggregateVariableRemover().getNonAggregationVariables(sparql);
    } catch (final MalformedQueryException e) {
        throw new PeriodicQueryStorageException(e.getMessage());
    }
    final List<String> varOrderList = new ArrayList<>();
    varOrderList.add(PeriodicQueryResultStorage.PeriodicBinId);
    varOrderList.addAll(bindingNames);
    createPeriodicQuery(queryId, sparql, new VariableOrder(varOrderList));
    return queryId;
}
Also used : PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) ArrayList(java.util.ArrayList) MalformedQueryException(org.openrdf.query.MalformedQueryException)

Aggregations

PeriodicQueryStorageException (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException)6 MalformedQueryException (org.openrdf.query.MalformedQueryException)6 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 BindingSetConversionException (org.apache.rya.indexing.pcj.storage.accumulo.BindingSetConverter.BindingSetConversionException)3 Text (org.apache.hadoop.io.Text)2 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)2 PeriodicQueryNode (org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode)2 UnsupportedQueryException (org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BatchDeleter (org.apache.accumulo.core.client.BatchDeleter)1 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)1 Scanner (org.apache.accumulo.core.client.Scanner)1 PeriodicQueryStorageMetadata (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageMetadata)1 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)1