// The output PlanContext contains a new symbol table defining the fields
// of this source.
PlanContext outContext = new PlanContext(planContext);
SymbolTable inTable = planContext.getSymbolTable();
SymbolTable outTable = mSymbols;
outContext.setSymbolTable(outTable);
// streamSym is guaranteed to be a non-null StreamSymbol by the typechecker.
StreamSymbol streamSym = (StreamSymbol) inTable.resolve(mSourceName).resolveAliases();
List<TypedField> fields = streamSym.getFields();
List<String> fieldNames = new ArrayList<String>();
for (TypedField field : fields) {
String fieldName = field.getAvroName();
if (!fieldNames.contains(fieldName)) {
fieldNames.add(fieldName);
}
}
// Create an Avro output schema for this node, specifying all the fields
// we can emit. Use our internal symbol (mSymbols a.k.a. outTable) to
// create more precise TypedFields that use the proper avro names.
List<TypedField> outFields = new ArrayList<TypedField>();
for (String fieldName : fieldNames) {
AssignedSymbol sym = (AssignedSymbol) outTable.resolve(fieldName).resolveAliases();
outFields.add(new TypedField(fieldName, sym.getType(), sym.getAssignedName(), fieldName));
}
PlanNode node = new NamedSourceNode(mSourceName, outFields);
planContext.getFlowSpec().addRoot(node);