planTester.buildPlan("B = foreach A generate $0, $1, flatten($2);");
planTester.buildPlan("C = order B by $0, $3;");
org.apache.pig.impl.logicalLayer.LogicalPlan lp = planTester.buildPlan( "D = store C into 'dummy';" );
LogicalPlan newLogicalPlan = migrateAndOptimizePlan( lp );
Operator load = newLogicalPlan.getSources().get( 0 );
Assert.assertTrue( load instanceof LOLoad );
Operator foreach = newLogicalPlan.getSuccessors( load ).get( 0 );
Assert.assertTrue( foreach instanceof LOForEach );
Operator foreach1 = newLogicalPlan.getSuccessors( foreach ).get( 0 );
Assert.assertTrue( foreach1 instanceof LOForEach );
Operator sort = newLogicalPlan.getSuccessors( foreach1 ).get( 0 );
Assert.assertTrue( sort instanceof LOSort );
}