Skip to content

Commit

Permalink
clean up if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
albertshau committed May 19, 2020
1 parent 5834faa commit 519f129
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ public void validate(List<JoinStage> joinStages) {
// for example, when joining on A.id = B.uid, check that 'id' is in the fields for stage A and 'uid' for stage B
Set<String> keysCopy = new HashSet<>(joinKey.getFields());
keysCopy.removeAll(fields);
if (!keysCopy.isEmpty()) {
String message = "Join key for stage '%s' is invalid.";
if (keysCopy.size() == 1) {
message += String.format("Field '%s' does not exist.", keysCopy.iterator().next());
} else {
message += String.format("Fields %s do not exist.", String.join(", ", keysCopy));
}
throw new InvalidJoinConditionException(message);
if (keysCopy.size() == 1) {
throw new InvalidJoinConditionException(String.format(
"Join key for stage '%s' is invalid. Field '%s' does not exist in the stage.",
joinStageName, keysCopy.iterator().next()));
}
if (keysCopy.size() > 1) {
throw new InvalidJoinConditionException(String.format(
"Join key for stage '%s' is invalid. Fields %s do not exist in the stage.",
joinStageName, String.join(", ", keysCopy)));
}
}

Expand Down

0 comments on commit 519f129

Please sign in to comment.