boolean needNewUid = innerLoadsPair.second;
// pull tuple information from innerload
if (innerLoads.get(0).getProjection().getFieldSchema().schema!=null &&
innerLoads.get(0).getProjection().getFieldSchema().type==DataType.BAG) {
LogicalFieldSchema originalTupleFieldSchema = innerLoads.get(0).getProjection().getFieldSchema().schema.getField(0);
LogicalFieldSchema newTupleFieldSchema = new LogicalFieldSchema(originalTupleFieldSchema.alias,
schema, DataType.TUPLE);
if (needNewUid) {
newTupleFieldSchema.uid = LogicalExpression.getNextUid();
}
else {
newTupleFieldSchema.uid = originalTupleFieldSchema.uid;
}
LogicalSchema newTupleSchema = new LogicalSchema();
newTupleSchema.addField(newTupleFieldSchema);
fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, newTupleSchema, DataType.BAG);
}
else {
fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.BAG);
}
if (needNewUid)
fieldSchema.uid = LogicalExpression.getNextUid();
else
fieldSchema.uid = innerLoads.get(0).getProjection().getFieldSchema().uid;
}
else {
// InnerLoad and source is not bag
if(schema == null){
// if we get here, it is range or starProject, otherwise, innerLoad will convert schema to non-null
if (isRangeProject && endCol!=-1){
LogicalSchema innerSchema = new LogicalSchema();
for(int i = startCol; i <= endCol; i++){
//schema is null, so null alias
innerSchema.addField(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
}
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, innerSchema, DataType.TUPLE);
} else {
fieldSchema = null;
}
}
else{
fieldSchema = schema.getField(0);
}
}
if (fieldSchema!=null)
uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
}
else {
if (schema == null) {
if(isRangeOrStarProject()) {
if (isRangeProject && endCol!=-1){
LogicalSchema innerSchema = new LogicalSchema();
for(int i = startCol; i <= endCol; i++){
//schema is null, so null alias
innerSchema.addField(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
}
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, innerSchema, DataType.TUPLE);
}
else {
fieldSchema = null;
}
} else {
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BYTEARRAY);
}
if (fieldSchema!=null)
uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
}
else {
int index = -1;
if (!isRangeOrStarProject() && uidOnlyFieldSchema!=null) {
long uid = uidOnlyFieldSchema.uid;
for (int i=0;i<schema.size();i++) {
LogicalFieldSchema fs = schema.getField(i);
if (fs.uid==uid) {
index = i;
}
}
}