@Override
protected void visit(LOCogroup cg) throws VisitorException {
// evaluateOperator(cg);
// there is a slightly different code path for cogroup because of the
// local rearranges
PhysicalOperator physOp = LogToPhyMap.get(cg);
Random r = new Random();
// get the list of original inputs
// List<PhysicalOperator> inputs = physOp.getInputs();
List<PhysicalOperator> inputs = new ArrayList<PhysicalOperator>();
PhysicalPlan phy = new PhysicalPlan();
phy.add(physOp);
// for(PhysicalOperator input : physOp.getInputs()) {
for (PhysicalOperator input : physPlan.getPredecessors(physOp)) {
inputs.add(input.getInputs().get(0));
// input.setInputs(null);
phy.add(input);
try {
phy.connect(input, physOp);
} catch (PlanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("Error connecting " + input.name() + " to "
+ physOp.name());
}
}
physOp.setLineageTracer(lineage);
// replace the original inputs by POReads
for (int i = 0; i < inputs.size(); i++) {
DataBag bag = derivedData.get(cg.getInputs().get(i));
PORead por = new PORead(new OperatorKey("", r.nextLong()), bag);
phy.add(por);
try {
phy.connect(por, physOp.getInputs().get(i));
} catch (PlanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("Error connecting " + por.name() + " to "
+ physOp.name());
}
}
DataBag output = BagFactory.getInstance().newDefaultBag();
Tuple t = null;
try {
for (Result res = physOp.getNext(t); res.returnStatus != POStatus.STATUS_EOP; res = physOp
.getNext(t)) {
output.add((Tuple) res.result);
}
} catch (ExecException e) {
log.error("Error evaluating operator : " + physOp.name());
}
derivedData.put(cg, output);
try {
Collection<IdentityHashSet<Tuple>> eq = EquivalenceClasses
.getEquivalenceClasses(cg, derivedData);
EqClasses.addAll(eq);
OpToEqClasses.put(cg, eq);
} catch (ExecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log
.error("Error updating equivalence classes while evaluating operators. \n"
+ e.getMessage());
}
// re-attach the original operators
// for(int i = 0; i < inputs.size(); i++) {
// try {
// physPlan.connect(inputs.get(i), physOp.getInputs().get(i));
//
// } catch (PlanException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// log.error("Error connecting " + inputs.get(i).name() + " to " +
// physOp.getInputs().get(i).name());
// }
// }
physOp.setLineageTracer(null);
}