use of org.apache.rya.mongodb.aggregation.AggregationPipelineQueryNode in project incubator-rya by apache.
the class MongoPipelineStrategy method toPipeline.
/**
* Converts a construct rule into a series of documents representing
* aggregation pipeline steps.
* @param rule A construct query rule.
* @param sourceLevel Only make derivations whose source triples have this
* derivation level or higher, i.e. took some number of forward chaining
* steps to infer. Set to zero to skip this check.
* @param timestamp Timestamp to be set for all inferred triples.
* @return An aggregation pipeline.
* @throws ForwardChainException if pipeline construction fails.
*/
private List<Bson> toPipeline(AbstractConstructRule rule, int sourceLevel, long timestamp) throws ForwardChainException {
TupleExpr tupleExpr = rule.getQuery().getTupleExpr();
if (!(tupleExpr instanceof QueryRoot)) {
tupleExpr = new QueryRoot(tupleExpr);
}
try {
tupleExpr.visit(pipelineVisitor);
} catch (Exception e) {
throw new ForwardChainException("Error converting construct rule to an aggregation pipeline", e);
}
if (tupleExpr instanceof QueryRoot) {
QueryRoot root = (QueryRoot) tupleExpr;
if (root.getArg() instanceof AggregationPipelineQueryNode) {
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) root.getArg();
// require distinct triples
pipelineNode.distinct();
pipelineNode.requireSourceDerivationDepth(sourceLevel);
long latestTime = executionTimes.getOrDefault(rule, 0L);
if (latestTime > 0) {
pipelineNode.requireSourceTimestamp(latestTime);
}
return pipelineNode.getTriplePipeline(timestamp, false);
}
}
return null;
}
Aggregations