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