public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
final Map<String, BasicOperator> mso,
final BasicOperator rootOperator) {
final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
final AddBinding add = (AddBinding) mso.get("add");
final Join join = (Join) mso.get("join");
boolean afterJoin = true;
final List<BasicOperator> joinPrec = new LinkedList<BasicOperator>();
joinPrec.addAll(join.getPrecedingOperators());
for (final BasicOperator bo : joinPrec) {
// check if Filter(Add.Var = Add.Constant) must be put to a join
// operand in order to fulfill the join condition
if (!bo.equals(add)
&& bo.getUnionVariables().contains(add.getVar())) {
try {
final Filter filter = new Filter("FILTER( "
+ add.getVar().toString() + " = "
+ add.getLiteral().toString() + " )");
filter.setIntersectionVariables(bo.getUnionVariables());
filter.setUnionVariables(bo.getUnionVariables());
// we assume that
filter.setSucceedingOperators(bo.getSucceedingOperators());
bo.setSucceedingOperator(new OperatorIDTuple(filter, 0));
join.removePrecedingOperator(bo);
join.addPrecedingOperator(filter);
filter.setPrecedingOperator(bo);
afterJoin = false;
added.add(filter);
} catch (final ParseException e) {
System.err.println(e);
e.printStackTrace();
}
}
}
// remove add
for (final BasicOperator bo : add.getPrecedingOperators()) {
bo.removeSucceedingOperator(add);
bo.addSucceedingOperators(add.getSucceedingOperators());
join.addPrecedingOperator(bo);
}
join.removePrecedingOperator(add);
join.getIntersectionVariables().remove(add.getVar());
// must add be put after the join?
if (afterJoin) {
add.setSucceedingOperators(join.getSucceedingOperators());
add.setPrecedingOperator(join);
join.setSucceedingOperator(new OperatorIDTuple(add, 0));
for (final OperatorIDTuple oid : add.getSucceedingOperators()) {
oid.getOperator().removePrecedingOperator(join);
oid.getOperator().addPrecedingOperator(add);
}
} else
deleted.add(add);