List<Long> uidSeen = new ArrayList<Long>();
for (int i=0;i<expPlans.size();i++) {
LogicalExpressionPlan expPlan = expPlans.get(i);
boolean flatten = flattens[i];
LogicalExpression exp = (LogicalExpression)expPlan.getSources().get(0);
if (exp.getFieldSchema()!=null) {
if (flatten && (exp.getFieldSchema().type == DataType.BAG || exp.getFieldSchema().type == DataType.TUPLE)) {
List<LogicalFieldSchema> innerFieldSchemas = null;
if (exp.getFieldSchema().type == DataType.BAG) {
if (exp.getFieldSchema().schema!=null) {
if (exp.getFieldSchema().schema.isTwoLevelAccessRequired()) {
// assert(fieldSchema.schema.size() == 1 && fieldSchema.schema.getField(0).type == DataType.TUPLE)
innerFieldSchemas = exp.getFieldSchema().schema.getField(0).schema.getFields();
} else {
innerFieldSchemas = exp.getFieldSchema().schema.getFields();
}
}
}
else { // DataType.TUPLE
if (exp.getFieldSchema().schema!=null)
innerFieldSchemas = exp.getFieldSchema().schema.getFields();
}
if (innerFieldSchemas != null) {
for (LogicalFieldSchema innerFieldSchema : innerFieldSchemas) {
long uid = innerFieldSchema.uid;
if (checkAndAdd(uid, uidSeen)) {
// Seen before
expPlansToInsertIdentity.add(expPlan);
break;
}
}
}
}
else {
long uid = exp.getFieldSchema().uid;
if (checkAndAdd(uid, uidSeen)) {
// Seen before
expPlansToInsertIdentity.add(expPlan);
}
}