planTester.buildPlan("B = load 'b';");
LogicalPlan lp = planTester.buildPlan("foreach (cogroup A by ($1), B by ($1)) generate A, flatten(B.($1, $2, $3));");
//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> cogroupMapValues = (ArrayList<ProjectionMap.Column>)cogroupMapFields.get(0);
assertTrue(cogroupMapValues.get(0).getInputColumn().first == 0);
assertTrue(cogroupMapValues.get(0).getInputColumn().second == 1);
assertTrue(cogroupMapValues.get(1).getInputColumn().first == 1);
assertTrue(cogroupMapValues.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 non-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);
List<ProjectionMap.Column> foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
for(int i = 1; i < 4; ++i) {
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(i);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.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(foreachProjectionMap.getRemovedFields().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);
}