public LogicalSchema.LogicalFieldSchema getFieldSchema() throws FrontendException {
if (fieldSchema!=null)
return fieldSchema;
LogicalRelationalOperator referent = findReferent();
LogicalSchema schema = referent.getSchema();
if (attachedRelationalOp instanceof LOGenerate && plan.getSuccessors(this)==null) {
if (!(findReferent() instanceof LOInnerLoad)||
((LOInnerLoad)findReferent()).sourceIsBag()) {
String alias = findReferent().getAlias();
List<LOInnerLoad> innerLoads = LOForEach.findReacheableInnerLoadFromBoundaryProject(this);
// pull tuple information from innerload
if (innerLoads.get(0).getProjection().getFieldSchema().schema!=null &&
innerLoads.get(0).getProjection().getFieldSchema().schema.isTwoLevelAccessRequired()) {
LogicalFieldSchema originalTupleFieldSchema = innerLoads.get(0).getProjection().getFieldSchema().schema.getField(0);
LogicalFieldSchema newTupleFieldSchema = new LogicalFieldSchema(originalTupleFieldSchema.alias,
schema, DataType.TUPLE);
newTupleFieldSchema.uid = originalTupleFieldSchema.uid;
LogicalSchema newTupleSchema = new LogicalSchema();
newTupleSchema.setTwoLevelAccessRequired(true);
newTupleSchema.addField(newTupleFieldSchema);
fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, newTupleSchema, DataType.BAG);
}
else {
fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.BAG);
}
fieldSchema.uid = innerLoads.get(0).getProjection().getFieldSchema().uid;
}
else {
if (findReferent().getSchema()!=null)
fieldSchema = findReferent().getSchema().getField(0);
}
if (fieldSchema!=null)
uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
}
else {
if (schema == null) {
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BYTEARRAY);
uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
}
else {
int index = -1;
if (!isProjectStar() && 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;
}
}
}
if (index==-1)
index = col;
if (!isProjectStar()) {
if (schema!=null && schema.size()>index)
fieldSchema = schema.getField(index);
else
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BYTEARRAY);
uidOnlyFieldSchema = fieldSchema.cloneUid();
}
else {
LogicalSchema newTupleSchema = null;
if (schema!=null)
newTupleSchema = schema.deepCopy();
fieldSchema = new LogicalSchema.LogicalFieldSchema(null, newTupleSchema, DataType.TUPLE);
uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
}