String query = "foreach (cogroup (load 'a') by ($1), (load 'b') by ($1)) generate $1.$1, $2.$1 ;";
LogicalPlan lp = planTester.buildPlan(query);
//check that the loads' projection map is null
LOLoad loada = (LOLoad) lp.getRoots().get(0);
ProjectionMap loadaProjectionMap = loada.getProjectionMap();
assertTrue(loadaProjectionMap.changes() == false);
LOLoad loadb = (LOLoad) lp.getRoots().get(1);
ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
assertTrue(loadbProjectionMap.changes() == false);
//check cogroup projection map
LOCogroup cogroup = (LOCogroup)lp.getSuccessors(loada).get(0);
ProjectionMap cogroupProjectionMap = cogroup.getProjectionMap();
assertTrue(cogroupProjectionMap.changes() == true);
MultiMap<Integer, ProjectionMap.Column> cogroupMapFields = cogroupProjectionMap.getMappedFields();
assertTrue(cogroupMapFields != null);
List<ProjectionMap.Column> mapValues = (ArrayList<ProjectionMap.Column>)cogroupMapFields.get(0);
assertTrue(mapValues.get(0).getInputColumn().first == 0);
assertTrue(mapValues.get(0).getInputColumn().second == 1);
assertTrue(mapValues.get(1).getInputColumn().first == 1);
assertTrue(mapValues.get(1).getInputColumn().second == 1);
//check the cogroup removed fields is null
assertTrue(cogroupProjectionMap.getRemovedFields() == null);
//check that cogroup added fields contain [1, 2]
List<Integer> cogroupAddedFields = cogroupProjectionMap.getAddedFields();
assertTrue(cogroupAddedFields.size() == 2);
assertTrue(cogroupAddedFields.get(0) == 1);
assertTrue(cogroupAddedFields.get(1) == 2);
//check that the foreach projection map has null mappedFields
LOForEach foreach = (LOForEach)lp.getLeaves().get(0);
ProjectionMap foreachProjectionMap = foreach.getProjectionMap();
assertTrue(foreachProjectionMap.changes() == true);
MultiMap<Integer, ProjectionMap.Column> foreachMapFields = foreachProjectionMap.getMappedFields();
assertTrue(foreachMapFields != null);
mapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
assertTrue(mapValues.get(0).getInputColumn().first == 0);
assertTrue(mapValues.get(0).getInputColumn().second == 1);
mapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(1);
assertTrue(mapValues.get(0).getInputColumn().first == 0);
assertTrue(mapValues.get(0).getInputColumn().second == 2);
//check that removed fields has all the group column from the input cogroup
List<Pair<Integer, Integer>> foreachRemovedFields = foreachProjectionMap.getRemovedFields();
assertTrue(foreachRemovedFields.size() == 1);
Pair<Integer, Integer> removedField = foreachRemovedFields.get(0);
assertTrue(removedField.first == 0);
assertTrue(removedField.second == 0);
//check that added fields is null
List<Integer> foreachAddedFields = foreachProjectionMap.getAddedFields();
assertTrue(foreachAddedFields == null);
}