org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store C into 'empty';" );
LogicalPlan newLogicalPlan = migratePlan( plan );
int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
int outputExprCount1 = getOutputExprCount( newLogicalPlan );
LOForEach foreach1 = getForEachOperator( newLogicalPlan );
Assert.assertTrue( foreach1.getAlias().equals( "C" ) );
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( 0, forEachCount1 - forEachCount2 );
int outputExprCount2 = getOutputExprCount( newLogicalPlan );
Assert.assertTrue( outputExprCount1 == outputExprCount2 );
LOForEach foreach2 = getForEachOperator( newLogicalPlan );
Assert.assertTrue( foreach2.getAlias().equals( "C" ) );
LogicalSchema newSchema = foreach2.getSchema();
Assert.assertTrue(newSchema.getField(0).alias.equals("x"));
Assert.assertTrue(newSchema.getField(1).alias.equals("y"));
}