Search in sources :

Example 1 with FluoQuery

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

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

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

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

the class GetQueryReport method getReport.

/**
 * Get a report that indicates how many biniding sets have been emitted for
 * a query that is being managed by the fluo application.
 *
 * @param fluo - The connection to Fluo that will be used to fetch the metadata. (not null)
 * @param queryId - The ID of the query to fetch. (not null)
 * @return A report that was built for the query.
 * @throws UnsupportedQueryException
 */
public QueryReport getReport(final FluoClient fluo, final String queryId) throws UnsupportedQueryException {
    checkNotNull(fluo);
    checkNotNull(queryId);
    final QueryReport.Builder reportBuilder = QueryReport.builder();
    try (Snapshot sx = fluo.newSnapshot()) {
        final FluoQuery fluoQuery = metadataDao.readFluoQuery(sx, queryId);
        reportBuilder.setFluoQuery(fluoQuery);
        // Query results.
        BigInteger count = countBindingSets(sx, queryId, FluoQueryColumns.QUERY_BINDING_SET);
        reportBuilder.setCount(queryId, count);
        // Filter results.
        for (final FilterMetadata filter : fluoQuery.getFilterMetadata()) {
            final String filterId = filter.getNodeId();
            count = countBindingSets(sx, filterId, FluoQueryColumns.FILTER_BINDING_SET);
            reportBuilder.setCount(filterId, count);
        }
        // Join results.
        for (final JoinMetadata join : fluoQuery.getJoinMetadata()) {
            final String joinId = join.getNodeId();
            count = countBindingSets(sx, joinId, FluoQueryColumns.JOIN_BINDING_SET);
            reportBuilder.setCount(joinId, count);
        }
        // Statement Pattern results.
        for (final StatementPatternMetadata statementPattern : fluoQuery.getStatementPatternMetadata()) {
            final String patternId = statementPattern.getNodeId();
            count = countBindingSets(sx, patternId, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET);
            reportBuilder.setCount(patternId, count);
        }
    }
    return reportBuilder.build();
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) FilterMetadata(org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata) BigInteger(java.math.BigInteger) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Example 5 with FluoQuery

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

the class BatchIT method getNodeIdStrings.

private List<String> getNodeIdStrings(FluoClient fluoClient, String queryId) throws UnsupportedQueryException {
    List<String> nodeStrings;
    try (Snapshot sx = fluoClient.newSnapshot()) {
        FluoQuery query = dao.readFluoQuery(sx, queryId);
        nodeStrings = FluoQueryUtils.collectNodeIds(query);
    }
    return nodeStrings;
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Aggregations

FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)13 StatementPatternMetadata (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)4 UnsupportedQueryException (org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException)4 PeriodicQueryNode (org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode)3 PeriodicQueryStorageException (org.apache.rya.indexing.pcj.storage.PeriodicQueryStorageException)3 MalformedQueryException (org.openrdf.query.MalformedQueryException)3 BigInteger (java.math.BigInteger)2 FluoClient (org.apache.fluo.api.client.FluoClient)2 Snapshot (org.apache.fluo.api.client.Snapshot)2 QueryReport (org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport)2 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)2 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)2 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Connector (org.apache.accumulo.core.client.Connector)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 CreateFluoPcj (org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)1