planTester.buildPlan("c = cogroup a by url, b by url;");
LogicalPlan lp = planTester.buildPlan("d = foreach c generate group,flatten(a),flatten(b);");
//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 == 0);
assertTrue(cogroupMapValues.get(1).getInputColumn().first == 1);
assertTrue(cogroupMapValues.get(1).getInputColumn().second == 0);
//check that removed fields has hitCount from a and rank from b
List<Pair<Integer, Integer>> cogroupRemovedFields = cogroupProjectionMap.getRemovedFields();
assertTrue(cogroupRemovedFields.size() == 2);
Pair<Integer, Integer> removedField = cogroupRemovedFields.get(0);
assertTrue(removedField.first == 0);
assertTrue(removedField.second == 1);
removedField = cogroupRemovedFields.get(1);
assertTrue(removedField.first == 1);
assertTrue(removedField.second == 1);
//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);
List<ProjectionMap.Column> foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 0);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(1);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(2);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(3);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 2);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(4);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 2);
//check that removed fields is null
List<Pair<Integer, Integer>> foreachRemovedFields = foreachProjectionMap.getRemovedFields();
assertTrue(foreachRemovedFields == null);
//check that added fields is null
List<Integer> foreachAddedFields = foreachProjectionMap.getAddedFields();
assertTrue(foreachAddedFields == null);
lp = planTester.buildPlan("e = foreach d generate group, a::url, b::url, b::rank, rank;");
foreach = (LOForEach)lp.getLeaves().get(0);
foreachProjectionMap = foreach.getProjectionMap();
assertTrue(foreachProjectionMap.changes() == true);
foreachMapFields = foreachProjectionMap.getMappedFields();
assertTrue(foreachMapFields != null);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 0);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(1);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(2);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 3);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(3);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 4);
foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(4);
assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
assertTrue(foreachMapValues.get(0).getInputColumn().second == 4);
//check that removed fields is null
foreachRemovedFields = foreachProjectionMap.getRemovedFields();
assertTrue(foreachRemovedFields != null);
assertTrue(foreachRemovedFields.size() == 1);
removedField = foreachRemovedFields.get(0);
assertTrue(removedField.first == 0);
assertTrue(removedField.second == 2);
//check that added fields is null
foreachAddedFields = foreachProjectionMap.getAddedFields();
assertTrue(foreachAddedFields == null);
}