Source:
public static List<FieldOperation> createFieldOperations(Collection<OutputFieldInfo> outputFieldInfos, Map<String, List<String>> perStageJoinKeys) { LinkedList<FieldOperation> operations = new LinkedList<>(); List<String> joinInputs = new ArrayList<>(); Set<String> joinOutputs = new LinkedHashSet<>(); for (Map.Entry<String, List<String>> joinKey : perStageJoinKeys.entrySet()) { for (String field : joinKey.getValue()) { joinInputs.add(joinKey.getKey() + "." + field); joinOutputs.add(field); } } FieldOperation joinOperation = new FieldTransformOperation("Join", JOIN_OPERATION_DESCRIPTIOPN, joinInputs, new ArrayList<>(joinOutputs)); operations.add(joinOperation); Set<String> outputsSoFar = new HashSet<>(joinOutputs); for (OutputFieldInfo outputFieldInfo : outputFieldInfos) { String inputFieldName = outputsSoFar.contains(outputFieldInfo.inputFieldName) ? outputFieldInfo.inputFieldName : outputFieldInfo.stageName + "." + outputFieldInfo.inputFieldName; if (outputFieldInfo.name.equals(outputFieldInfo.inputFieldName)) { if (perStageJoinKeys.get(outputFieldInfo.stageName).contains(outputFieldInfo.inputFieldName)) { continue; } String operationName = String.format("Identity %s", inputFieldName); FieldOperation identity = new FieldTransformOperation(operationName, IDENTITY_OPERATION_DESCRIPTION, Collections.singletonList(inputFieldName), outputFieldInfo.inputFieldName); operations.add(identity); continue; } String operationName = String.format("Rename %s", inputFieldName); FieldOperation transform = new FieldTransformOperation(operationName, RENAME_OPERATION_DESCRIPTION, Collections.singletonList(inputFieldName), outputFieldInfo.name); operations.add(transform); } return operations; }

Target:
public static List<FieldOperation> createFieldOperations(Collection<OutputFieldInfo> outputFieldInfos, Map<String, List<String>> perStageJoinKeys) { LinkedList<FieldOperation> operations = new LinkedList<>(); List<String> joinInputs = new ArrayList<>(); Set<String> joinOutputs = new LinkedHashSet<>(); for (Map.Entry<String, List<String>> joinKey : perStageJoinKeys.entrySet()) { for (String field : joinKey.getValue()) { joinInputs.add(joinKey.getKey() + "." + field); joinOutputs.add(field); } } FieldOperation joinOperation = new FieldTransformOperation("Join", JOIN_OPERATION_DESCRIPTION, joinInputs, new ArrayList<>(joinOutputs)); operations.add(joinOperation); Set<String> outputsSoFar = new HashSet<>(joinOutputs); for (OutputFieldInfo outputFieldInfo : outputFieldInfos) { String stagedInputField = outputsSoFar.contains(outputFieldInfo.inputFieldName) ? outputFieldInfo.inputFieldName : outputFieldInfo.stageName + "." + outputFieldInfo.inputFieldName; if (outputFieldInfo.name.equals(outputFieldInfo.inputFieldName)) { if (perStageJoinKeys.get(outputFieldInfo.stageName).contains(outputFieldInfo.inputFieldName)) { continue; } String operationName = String.format("Identity %s", stagedInputField); FieldOperation identity = new FieldTransformOperation(operationName, IDENTITY_OPERATION_DESCRIPTION, Collections.singletonList(stagedInputField), outputFieldInfo.name); operations.add(identity); continue; } String operationName = String.format("Rename %s", stagedInputField); FieldOperation transform = new FieldTransformOperation(operationName, RENAME_OPERATION_DESCRIPTION, Collections.singletonList(stagedInputField), outputFieldInfo.name); operations.add(transform); } return operations; }