Source:
<code>private JoinEnumerationResult setJoinNodeProperties(JoinNode joinNode) { List<JoinEnumerationResult> possibleJoinNodes = new ArrayList<>(); FeaturesConfig.JoinDistributionType joinDistributionType = getJoinDistributionType(session); if (isAtMostScalar(joinNode.getRight(), lookup)) { JoinNode node = joinNode.withDistributionType(REPLICATED); <START> return new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node)); <END> } if (isAtMostScalar(joinNode.getLeft(), lookup)) { JoinNode node = joinNode.flipChildren().withDistributionType(REPLICATED); return new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node)); } if (joinDistributionType.canRepartition() && !joinNode.isCrossJoin()) { JoinNode node = joinNode.withDistributionType(PARTITIONED); possibleJoinNodes.add(new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node))); node = node.flipChildren(); possibleJoinNodes.add(new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node))); } if (joinDistributionType.canReplicate()) { JoinNode node = joinNode.withDistributionType(REPLICATED); possibleJoinNodes.add(new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node))); node = node.flipChildren(); possibleJoinNodes.add(new JoinEnumerationResult(costProvider.getCumulativeCost(node), Optional.of(node))); } if (possibleJoinNodes.stream().anyMatch(result -> result.cost.hasUnknownComponents())) { return UNKNOWN_COST_RESULT; } return resultComparator.min(possibleJoinNodes); }</code><technical_language>simplified need differentiate unknown infinite cost, check if leftResult.equals(UNKNOWN_COST_RESULT) check fine. I agree a helper method standardizes INFINITE/UNKNOWN cost results is a good idea</technical_language>

Target:
private JoinEnumerationResult setJoinNodeProperties(JoinNode joinNode) { if (isAtMostScalar(joinNode.getRight(), lookup)) { JoinNode node = joinNode.withDistributionType(REPLICATED); return createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node)); } if (isAtMostScalar(joinNode.getLeft(), lookup)) { JoinNode node = joinNode.flipChildren().withDistributionType(REPLICATED); return createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node)); } List<JoinEnumerationResult> possibleJoinNodes = new ArrayList<>(); FeaturesConfig.JoinDistributionType joinDistributionType = getJoinDistributionType(session); if (joinDistributionType.canRepartition() && !joinNode.isCrossJoin()) { JoinNode node = joinNode.withDistributionType(PARTITIONED); possibleJoinNodes.add(createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node))); node = node.flipChildren(); possibleJoinNodes.add(createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node))); } if (joinDistributionType.canReplicate()) { JoinNode node = joinNode.withDistributionType(REPLICATED); possibleJoinNodes.add(createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node))); node = node.flipChildren(); possibleJoinNodes.add(createJoinEnumerationResult(Optional.of(node), costProvider.getCumulativeCost(node))); } if (possibleJoinNodes.stream().anyMatch(result -> result.equals(UNKNOWN_COST_RESULT))) { return UNKNOWN_COST_RESULT; } return resultComparator.min(possibleJoinNodes); }