if (op instanceof POForEach)
{
POForEach forEach = (POForEach)op;
List<PhysicalPlan> planList = forEach.getInputPlans();
List<Boolean> flatten = forEach.getToBeFlattened();
POProject projOfLastInput = null;
int i = 0;
// check all nested foreach plans
// 1. If it is simple projection
// 2. If last input is all flattened
for (PhysicalPlan p:planList)
{
PhysicalOperator opProj = p.getRoots().get(0);
if (!(opProj instanceof POProject))
{
allSimple = false;
break;
}
POProject proj = (POProject)opProj;
// the project should just be for one column
// from the input
if(proj.getColumns().size() != 1) {
allSimple = false;
break;
}
try {
// if input to project is the last input
if (proj.getColumn() == pack.getNumInps())
{
// if we had already seen another project
// which was also for the last input, then
// we might be trying to flatten twice on the
// last input in which case we can't optimize by
// just streaming the tuple to those projects
// IMPORTANT NOTE: THIS WILL NEED TO CHANGE WHEN WE
// OPTIMIZE BUILTINS LIKE SUM() AND COUNT() TO
// TAKE IN STREAMING INPUT
if(projOfLastInput != null) {
allSimple = false;
break;
}
projOfLastInput = proj;
// make sure the project is on a bag which needs to be
// flattened
if (!flatten.get(i) || proj.getResultType() != DataType.BAG)
{
lastInputFlattened = false;
break;
}
}