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);
}
}
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);
}
}
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);
}
}
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();
}
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;
}
Aggregations