for( Integer key : keySet ) {
Collection<LogicalExpressionPlan> plans =
mExpressionPlans.get(key);
for( LogicalExpressionPlan plan : plans ) {
LogicalFieldSchema fieldSchema = getPlanSchema(plan);
// if any plan schema is null, that means we can't calculate
// further schemas so we bail out
if( fieldSchema == null ) {
schema = null;
return schema;
}
// Change the uid of this field
fieldSchema.uid = LogicalExpression.getNextUid();
keySchema.addField(fieldSchema);
}
// We only need fields from one input and not all
break;
}
groupKeySchema = new LogicalFieldSchema(GROUP_COL_NAME, keySchema, DataType.TUPLE,
LogicalExpression.getNextUid() );
} else {
// We sort here to maintain the correct order of inputs
TreeSet<Integer> keySet = new TreeSet<Integer>();
keySet.addAll( mExpressionPlans.keySet() );
for( Integer key : keySet ) {
Collection<LogicalExpressionPlan> plans = mExpressionPlans.get(key);
for( LogicalExpressionPlan plan : plans ) {
groupKeySchema = getPlanSchema(plan);
// if any plan schema is null, that means we can't calculate
// further schemas so we bail out
if( groupKeySchema == null ) {
schema = null;
return schema;
}
// Change the uid of this field
groupKeySchema.alias = GROUP_COL_NAME;
groupKeySchema.uid = LogicalExpression.getNextUid();
break;
}
break;
}
}
}
fieldSchemaList.add( groupKeySchema );
// Generate the Bag Schema
int counter = 0;
for (Operator op : inputs) {
LogicalSchema inputSchema = ((LogicalRelationalOperator)op).getSchema();
// the schema of one input is unknown, so the join schema is unknown, just return
if (inputSchema == null) {
schema = null;
return schema;
}
// Check if we already have calculated Uid for this bag for given
// input operator
long bagUid = -1;
if( generatedInputUids.containsKey(counter) ) {
bagUid = generatedInputUids.get(counter);
} else {
bagUid = LogicalExpression.getNextUid();
generatedInputUids.put( counter, bagUid );
}
LogicalFieldSchema newBagSchema = new LogicalFieldSchema(
((LogicalRelationalOperator)op).getAlias(), inputSchema,
DataType.BAG, bagUid);
fieldSchemaList.add( newBagSchema );
counter ++;