Source:
private Schema getOutputSchema(Map<String, Schema> inputSchemas) { validateRequiredInputs(inputSchemas); Map<String, Schema> inputs = new TreeMap<>(inputSchemas); Map<String, Schema.Field> outputFields = new LinkedHashMap<>(); Map<String, String> duplicateFieldsMap = new HashMap<>(); for (Map.Entry<String, Schema> input : inputs.entrySet()) { String stageName = input.getKey(); Schema inputSchema = input.getValue(); Map<String, String> fieldsToSelectRename = perStageFieldsToRename.row(stageName); for (Schema.Field inputField : inputSchema.getFields()) { String inputFieldName = inputField.getName(); if (!fieldsToSelectRename.containsKey(inputFieldName)) { continue; } String outputFieldName = fieldsToSelectRename.get(inputFieldName); if (outputFields.containsKey(outputFieldName)) { duplicateFieldsMap.put(stageName, com.google.common.base.Joiner.on(",") .join(duplicateFieldsMap.get(stageName), outputFieldName)); continue; } if (!Iterables.isEmpty(requiredInputs) && Iterables.contains(requiredInputs, stageName)) { outputFields.put(outputFieldName, Schema.Field.of(outputFieldName, inputField.getSchema())); } else { outputFields.put(outputFieldName, Schema.Field.of(outputFieldName, Schema.nullableOf(inputField.getSchema() ))); } } } if (!duplicateFieldsMap.isEmpty()) { throw new IllegalArgumentException(GSON.toJson(duplicateFieldsMap)); } return Schema.recordOf("join.output", outputFields.values()); }

Target:
private Schema getOutputSchema(Map<String, Schema> inputSchemas) { validateRequiredInputs(inputSchemas); Map<String, Schema> inputs = new HashMap<>(inputSchemas); Map<String, OutputFieldInfo> outputFieldInfo = new LinkedHashMap<>(); List<String> duplicateAliases = new ArrayList<>(); Set<Table.Cell<String, String, String>> rows = perStageSelectedFields.cellSet(); for (Table.Cell<String, String, String> row : rows) { String stageName = row.getRowKey(); String inputFieldName = row.getColumnKey(); String alias = row.getValue(); Schema inputSchema = inputs.get(stageName); if (inputSchema == null) { throw new IllegalArgumentException(String.format("Input schema for input stage %s can not be null", stageName)); } if (outputFieldInfo.containsKey(alias)) { OutputFieldInfo outInfo = outputFieldInfo.get(alias); if (duplicateAliases.add(alias)) { duplicateFields.put(outInfo.getStageName(), outInfo.getInputFieldName()); } duplicateFields.put(stageName, inputFieldName); continue; } Schema.Field inputField = inputSchema.getField(inputFieldName); if (inputField == null) { throw new IllegalArgumentException(String.format( "Invalid field: %s of stage '%s' does not exist in input schema %s.", inputFieldName, stageName, inputSchema)); } if (requiredInputs.contains(stageName)) { outputFieldInfo.put(alias, new OutputFieldInfo(alias, stageName, inputFieldName, Schema.Field.of(alias, inputField.getSchema()))); } else { outputFieldInfo.put(alias, new OutputFieldInfo(alias, stageName, inputFieldName, Schema.Field.of(alias, Schema.nullableOf(inputField.getSchema())))); } } if (!duplicateFields.isEmpty()) { throw new IllegalArgumentException(String.format("Output schema must not have any duplicate field names, but " + "found: %s for aliases: %s", duplicateFields, duplicateAliases)); } return Schema.recordOf("join.output", getOutputFields(outputFieldInfo.values())); }