for(final Generate generate: listOfConstructedTripel){
generate.getSucceedingOperators().clear();
final Item[] generateItems = generate.getValueOrVariable();
for(final BasicOperator tpOrIndexScan: new LinkedList<BasicOperator>(toBeConnectedTo)){
if(tpOrIndexScan instanceof TriplePattern){
final TriplePattern tpi = (TriplePattern) tpOrIndexScan;
if(BasicIndexRuleEvaluator.isMatching(tpi, generateItems)){
generate.addSucceedingOperator(tpOrIndexScan);
}
} else {
final BasicIndexScan bi = (BasicIndexScan) tpOrIndexScan;
if(bi.getTriplePattern()!=null && bi.getTriplePattern().size()>0){
final LinkedList<TriplePattern> matchingTPs = new LinkedList<TriplePattern>();
for(final TriplePattern inIndexScan: bi.getTriplePattern()){
if(BasicIndexRuleEvaluator.isMatching(inIndexScan, generateItems)){
matchingTPs.add(inIndexScan);
break;
}
}
if(matchingTPs.size()>0){
// modify BasicIndex in toBeConnectedTo! (delete tp in current bi, add new BasicIndex with tp, join both operators and additionally add tp for generate operator!)
for(final TriplePattern tp: matchingTPs){
final TriplePattern newTP = new TriplePattern(tp.getPos(0), tp.getPos(1), tp.getPos(2));
newTP.recomputeVariables();
generate.addSucceedingOperator(newTP);
newTP.addPrecedingOperator(generate);
if(bi.getTriplePattern().size()==1){
newTP.addSucceedingOperators(new LinkedList<OperatorIDTuple>(bi.getSucceedingOperators()));
for(final OperatorIDTuple opID: bi.getSucceedingOperators()){
opID.getOperator().addPrecedingOperator(newTP);
}
} else {
bi.getTriplePattern().remove(tp);
final Join join = new Join();
join.setUnionVariables(bi.getUnionVariables());
bi.recomputeVariables();
tp.recomputeVariables();
final HashSet<Variable> joinVars = new HashSet<Variable>(tp.getUnionVariables());
joinVars.retainAll(bi.getUnionVariables());
join.setIntersectionVariables(joinVars);
for(final OperatorIDTuple opID: bi.getSucceedingOperators()){
final BasicOperator suc = opID.getOperator();
suc.removePrecedingOperator(bi);
suc.addPrecedingOperator(join);
}
join.setSucceedingOperators(bi.getSucceedingOperators());
bi.setSucceedingOperator(new OperatorIDTuple(join, 0));
join.addPrecedingOperator(bi);
final LinkedList<TriplePattern> tpList = new LinkedList<TriplePattern>();
tpList.add(tp);
final BasicIndexScan newIndex = ((Root)rootQuery).newIndexScan(new OperatorIDTuple(join, 1), tpList, bi.getGraphConstraint());
newIndex.recomputeVariables();
join.addPrecedingOperator(newIndex);
rootQuery.addSucceedingOperator(newIndex);
newIndex.addPrecedingOperator(rootQuery);
newTP.addSucceedingOperator(new OperatorIDTuple(join, 1));
join.addPrecedingOperator(newTP);
toBeConnectedTo.add(newIndex);
}
}