}
}
else if (rlo instanceof LOForEach)
{
// Relay map keys from output to input
LogicalPlan forEachPlan = ((LOForEach)rlo).getRelevantPlan(requiredOutputField.second);
if (relevantFields.getFields()!=null && relevantFields.getFields().size()!=0)
{
int index = ((LOForEach)rlo).getForEachPlans().indexOf(forEachPlan);
// We check if the field get flattened, if it does, then we do not relay output map keys to input map keys.
// There are two situations:
// 1. input column is tuple, bag, or other simple type, there is no concept of map key, so we do not relay
// 2. input column is map, flatten does not do anything, we can still relay
boolean nonflatten = false;
if (!((LOForEach)rlo).getFlatten().get(index))
{
nonflatten = true;
}
else
{
// Foreach plan is flattened, check if there is only one input for this foreach plan
// and input schema for that input is not map, if so, it is a dummy flatten
if (forEachPlan.getRoots().size()==1 && forEachPlan.getRoots().get(0) instanceof LOProject)
{
LOProject loProj = (LOProject)forEachPlan.getRoots().get(0);
if (loProj.getExpression().getSchema()!=null &&
loProj.getExpression().getSchema().getField(loProj.getCol()).type!=DataType.BAG)
nonflatten = true;
}
}