Search in sources :

Example 1 with PeriodicQueryNode

use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode 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 PeriodicQueryNode

use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode in project incubator-rya by apache.

the class CreatePeriodicQuery method withRyaIntegration.

/**
 * 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
 * @param notificationClient - {@link PeriodicNotificationClient} for registering new PeriodicNotifications
 * @param conn - Accumulo connector for connecting to the Rya instance
 * @param ryaInstance - name of the Accumulo back Rya instance
 * @return FluoQuery indicating the metadata of the registered SPARQL query
 */
public FluoQuery withRyaIntegration(String sparql, PeriodicNotificationClient notificationClient, Connector conn, String ryaInstance) 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.withRyaIntegration(pcjId, sparql, Sets.newHashSet(ExportStrategy.PERIODIC), fluoClient, conn, ryaInstance);
            // 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 (Exception e) {
        throw new PeriodicQueryCreationException(e);
    }
}
Also used : 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) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) PeriodicQueryStorageException(org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException) MalformedQueryException(org.openrdf.query.MalformedQueryException)

Example 3 with PeriodicQueryNode

use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode 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 4 with PeriodicQueryNode

use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode in project incubator-rya by apache.

the class PeriodicQueryUtil method parseAndSetValues.

/**
 * @param values - Values extracted from FunctionCall representing the PeriodicQuery Filter
 * @param arg - Argument of the PeriodicQueryNode that will be created (PeriodicQueryNode is a UnaryTupleOperator)
 * @return - PeriodicQueryNode to be inserted in place of the original FunctionCall
 * @throws Exception
 */
private static PeriodicQueryNode parseAndSetValues(List<ValueExpr> values, TupleExpr arg) throws Exception {
    // general validation of input
    Preconditions.checkArgument(values.size() == 4);
    Preconditions.checkArgument(values.get(0) instanceof Var);
    Preconditions.checkArgument(values.get(1) instanceof ValueConstant);
    Preconditions.checkArgument(values.get(2) instanceof ValueConstant);
    Preconditions.checkArgument(values.get(3) instanceof ValueConstant);
    // get temporal variable
    Var var = (Var) values.get(0);
    Preconditions.checkArgument(var.getValue() == null);
    String tempVar = var.getName();
    // get TimeUnit
    TimeUnit unit = getTimeUnit((ValueConstant) values.get(3));
    // get window and period durations
    double windowDuration = parseTemporalDuration((ValueConstant) values.get(1));
    double periodDuration = parseTemporalDuration((ValueConstant) values.get(2));
    long windowMillis = convertToMillis(windowDuration, unit);
    long periodMillis = convertToMillis(periodDuration, unit);
    // period must evenly divide window at least once
    Preconditions.checkArgument(windowMillis > periodMillis);
    Preconditions.checkArgument(windowMillis % periodMillis == 0, "Period duration does not evenly divide window duration.");
    // create PeriodicMetadata.Builder
    return new PeriodicQueryNode(windowMillis, periodMillis, TimeUnit.MILLISECONDS, tempVar, arg);
}
Also used : Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) TimeUnit(java.util.concurrent.TimeUnit) PeriodicQueryNode(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode)

Aggregations

PeriodicQueryNode (org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode)4 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)3 UnsupportedQueryException (org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException)3 PeriodicQueryStorageException (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException)3 MalformedQueryException (org.openrdf.query.MalformedQueryException)3 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)2 TimeUnit (java.util.concurrent.TimeUnit)1 ValueConstant (org.openrdf.query.algebra.ValueConstant)1 Var (org.openrdf.query.algebra.Var)1