java.util.Iterator<BasicOperator> itp = newOrder.iterator();
while(itp.hasNext()) {
BasicOperator first = this.getNext(itp, alreadyUsed);
if(first==null)
break;
if(itp.hasNext()) {
feedAlreadyUsed(oldJoin, first.getOperatorIDTuple(oldJoin).getId(), alreadyUsed);
BasicOperator second = this.getNext(itp, alreadyUsed);
if(second==null){
remainingJoins.add(first);
break;
}
lupos.engine.operators.multiinput.join.Join newJoin = new lupos.engine.operators.multiinput.join.Join();
this.addNodeToStartNodeMapNullCheck(newJoin, _startNodes);
handleJoinOperand(oldJoin, first.getOperatorIDTuple(oldJoin).getId(), newJoin, 0, alreadyUsed);
handleJoinOperand(oldJoin, second.getOperatorIDTuple(oldJoin).getId(), newJoin, 1, alreadyUsed);
HashSet<lupos.datastructures.items.Variable> hv = new HashSet<lupos.datastructures.items.Variable>();
for(BasicOperator bo: newJoin.getPrecedingOperators()){
hv.addAll(bo.getUnionVariables());
}
newJoin.setUnionVariables(hv);
newJoin.setIntersectionVariables(new HashSet<lupos.datastructures.items.Variable>());
newJoin.getIntersectionVariables().addAll(first.getUnionVariables());
for(BasicOperator bo: newJoin.getPrecedingOperators()){
newJoin.getIntersectionVariables().retainAll(bo.getUnionVariables());
}
remainingJoins.add(newJoin);
}
else {
remainingJoins.add(first);
}
}
while(remainingJoins.size() > 1) {
// choose best combination
java.util.Collection<BasicOperator> co = this.getNextJoin(remainingJoins);
java.util.Iterator<BasicOperator> io = co.iterator();
BasicOperator first = io.next();
BasicOperator second = io.next();
lupos.engine.operators.multiinput.join.Join join = new lupos.engine.operators.multiinput.join.Join();
this.addNodeToStartNodeMapNullCheck(join, _startNodes);
if(first instanceof lupos.engine.operators.multiinput.join.Join && second instanceof lupos.engine.operators.multiinput.join.Join){
first.setSucceedingOperator(new OperatorIDTuple(join, 0));
join.addPrecedingOperator(first);
} else {
if(first instanceof lupos.engine.operators.multiinput.join.Join){
BasicOperator tmp = first;
first = second;
second = tmp;
}
// second is now a join and first something else...
handleJoinOperand(oldJoin, first.getOperatorIDTuple(oldJoin).getId(), join, 0, alreadyUsed);