org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store D into 'empty';" );
LogicalPlan newLogicalPlan = migratePlan( plan );
Operator store = newLogicalPlan.getSinks().get(0);
int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
LOForEach foreach1 = (LOForEach)newLogicalPlan.getPredecessors(store).get(0);
Assert.assertTrue( foreach1.getAlias().equals( "D" ) );
PlanOptimizer optimizer = new MyPlanOptimizer( newLogicalPlan, 3 );
optimizer.optimize();
int forEachCount2 = getForEachOperatorCount( newLogicalPlan );
// The number of FOREACHes didn't change because one is genereated because of type cast and
// one is reduced because of the merge.
Assert.assertEquals( 1, forEachCount1 - forEachCount2 );
LOForEach foreach2 = (LOForEach)newLogicalPlan.getPredecessors(store).get(0);
Assert.assertTrue( foreach2.getAlias().equals( "D" ) );
}