466 struct MergedComputables {
467 MergedComputables() : requiresEDB(true) {};
470 std::vector<ComputablePtr> literals;
473 auto lastOut = pipelineInput;
486 std::vector<MergedComputables> mergedComputables;
487 while (!computableLiterals.empty()) {
488 auto next = computableLiterals.front();
490 computableLiterals.erase(computableLiterals.begin());
492 auto &merged = mergedComputables.emplace_back();
496 merged.requiresEDB =
false;
497 for (
auto &r: next->reasonerList()) {
501 merged.requiresEDB =
true;
507 merged.requiresEDB = merged.requiresEDB && indicator.arity <= 2;
508 if (merged.requiresEDB && indicator.functor) {
510 merged.requiresEDB = isMaterializedInEDB(kb, *indicator.functor);
512 merged.literals.push_back(next);
514 bool supportsSimpleConjunction =
true;
515 for (
auto &r: next->reasonerList()) {
517 supportsSimpleConjunction =
false;
522 if (supportsSimpleConjunction && !merged.requiresEDB && next->reasonerList().size() == 1) {
524 for (
auto it = computableLiterals.begin(); it != computableLiterals.end();) {
526 if (next->reasonerList() == lit->reasonerList()) {
527 merged.literals.push_back(lit);
528 it = computableLiterals.erase(it);
537 for (
auto &mergedComputable: mergedComputables) {
538 auto stepInput = lastOut;
539 auto stepOutput = std::make_shared<TokenBroadcaster>();
540 uint32_t numStages = 0;
545 if (mergedComputable.requiresEDB) {
546 auto edb = kb->getBackendForQuery();
547 auto edbStage = std::make_shared<TypedQueryStage<FirstOrderLiteral>>(
549 mergedComputable.item,
551 auto rdfLiteral = std::make_shared<TriplePattern>(
552 q->predicate(), q->isNegated());
553 rdfLiteral->setTripleFrame(ctx->selector);
554 return kb->edb()->getAnswerCursor(edb, std::make_shared<GraphPathQuery>(rdfLiteral, ctx));
556 edbStage->selfWeakRef_ = edbStage;
557 stepInput >> edbStage;
558 edbStage >> stepOutput;
566 for (
auto &r: mergedComputable.item->reasonerList()) {
567 auto idbStage = std::make_shared<TypedQueryStageVec<Computable>>(
568 ctx, mergedComputable.literals,
569 [r, ctx](
const std::vector<ComputablePtr> &q) {
572 idbStage->selfWeakRef_ = idbStage;
573 stepInput >> idbStage;
574 idbStage >> stepOutput;
577 lastOut = stepOutput;
585 auto consolidator = std::make_shared<DisjunctiveBroadcaster>();
586 lastOut >> consolidator;
587 lastOut = consolidator;
596 auto filterStage = std::make_shared<RedundantAnswerFilter>();
597 lastOut >> filterStage;
598 lastOut = filterStage;
602 lastOut >> pipelineOutput;
static TokenBufferPtr evaluateQuery(const GoalDrivenReasonerPtr &reasoner, const std::vector< FirstOrderLiteralPtr > &literals, const QueryContextPtr &ctx)
@ QUERY_FLAG_UNIQUE_SOLUTIONS
std::shared_ptr< Computable > ComputablePtr
@ SupportsSimpleConjunctions
@ SupportsExtensionalGrounding
std::shared_ptr< FirstOrderLiteral > FirstOrderLiteralPtr