}
Join replacement = new Join();
for (Map.Entry<TupleExpr, Set<SignedConnection>> entry : exprOwnerMap.entrySet()) {
TupleExpr joinArg = entry.getKey();
Set<SignedConnection> owners = entry.getValue();
if (owners.isEmpty()) {
// No results for this expression and thus for the entire join
join.replaceWith(new EmptySet());
return;
}
else if (owners.size() == 1) {
SignedConnection owner = owners.iterator().next();
replacement.addArg(new OwnedTupleExpr(owner, joinArg));
}
else if (joinArg instanceof Join || distinct) {
// Local join with multiple owners or distinct federation members
Union union = new Union();
for (SignedConnection owner : owners) {
union.addArg(new OwnedTupleExpr(owner, joinArg.clone()));
}
replacement.addArg(union);
}
else {
replacement.addArg(joinArg);