Iterator<Long> iter = output.iterator();
while(iter.hasNext()) {
long uid = iter.next();
boolean found = false;
for(int i=0; i<ll.size(); i++) {
LogicalExpressionPlan exp = ll.get(i);
LogicalExpression op = (LogicalExpression)exp.getSources().get(0);
if (op.getUid() == uid) {
collectUids(gen, exp, input);
found = true;
} else if (op instanceof ProjectExpression && ((ProjectExpression)op).isProjectStar()) {
int inputNum = ((ProjectExpression)op).getInputNum();
LogicalRelationalOperator pred = (LogicalRelationalOperator)gen.getPlan().getPredecessors(gen).get(inputNum);
if (pred.getSchema() == null) {
throw new SchemaNotDefinedException("Schema for " + pred.getName() + " is not defined.");
}
for(LogicalFieldSchema f: pred.getSchema().getFields()) {
if (f.uid == uid) {
input.add(uid);
found = true;
}
}
} else if (gen.getFlattenFlags()[i]) {
// if uid equal to the expression, get all uids of original projections
List<Operator> ss = exp.getSinks();
for(Operator s: ss) {
if (s instanceof ProjectExpression) {
int inputNum = ((ProjectExpression)s).getInputNum();
LogicalRelationalOperator pred = (LogicalRelationalOperator)gen.getPlan().getPredecessors(gen).get(inputNum);
if (pred.getSchema() == null) {
throw new SchemaNotDefinedException("Schema for " + pred.getName() + " is not defined.");
}
if (pred.getSchema().findField(uid) != -1) {
input.add(uid);
found = true;
}
}
}
}
if (found) {
break;
}
}
if (!found) {
throw new IOException("uid " + uid +" is not in the schema of LOForEach");
}
}
// for the flatten bag, we need to make sure at least one field is in the input
for(int i=0; i<ll.size(); i++) {
if (!gen.getFlattenFlags()[i]) {
continue;
}
LogicalExpressionPlan exp = ll.get(i);
Operator s = exp.getSinks().get(0);
if (s instanceof ProjectExpression) {
int inputNum = ((ProjectExpression)s).getInputNum();
int colNum = ((ProjectExpression)s).getColNum();
LogicalRelationalOperator pred = (LogicalRelationalOperator)gen.getPlan().getPredecessors(gen).get(inputNum);