Repository: apache/flink
File: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/JoinToMultiJoinRule.java (Java)

Code before:
        combineIfCan(join, right, newInputs, projFieldsList, joinFieldRefCountsList);

        return newInputs;
    }

    private void combineIfCan(
            Join join,
            RelNode relNode,
            List<RelNode> newInputs,
            List<ImmutableBitSet> projFieldsList,
            List<int[]> joinFieldRefCountsList) {
        if (canCombine(relNode, join)) {
            final MultiJoin rightMultiJoin = (MultiJoin) relNode;
            for (int i = 0; i < rightMultiJoin.getInputs().size(); i++) {
                newInputs.add(rightMultiJoin.getInput(i));
                projFieldsList.add(rightMultiJoin.getProjFields().get(i));
                joinFieldRefCountsList.add(
                        rightMultiJoin.getJoinFieldRefCountsMap().get(i).toIntArray());
            }
        } else {
            newInputs.add(relNode);
            projFieldsList.add(null);
            joinFieldRefCountsList.add(new int[relNode.getRowType().getFieldCount()]);
        }
    }

    /**
     * Combines the join conditions and join types from the left and right join inputs. If the join
     * itself is either a left or right outer join, then the join condition corresponding to the
     * join is also set in the position corresponding to the null-generating input into the join.
     * The join type is also set.
     *
     * @param joinRel join rel
     * @param left left child of the joinrel
     * @param joinSpecs the list where the join types and conditions will be copied
     */
    private void combineJoinInfo(
            Join joinRel, RelNode left, List<Pair<JoinRelType, RexNode>> joinSpecs) {
        JoinRelType joinType = joinRel.getJoinType();
        final RexBuilder rexBuilder = joinRel.getCluster().getRexBuilder();
        boolean leftCombined = canCombine(left, joinRel);
        switch (joinType) {
            case LEFT:
            case INNER:
                if (leftCombined) {
                    copyJoinInfo((MultiJoin) left, joinSpecs);
                } else {
                    joinSpecs.add(Pair.of(JoinRelType.INNER, rexBuilder.makeLiteral(true)));
                }
                joinSpecs.add(Pair.of(joinType, joinRel.getCondition()));
                break;

Review comment (refactor):
logic is identical, so extracted into `combineIfCan`

Code after:
        combineIfCan(join, right, newInputs, projFieldsList, joinFieldRefCountsList);

        return newInputs;
    }

    private void combineIfCan(
            Join join,
            RelNode relNode,
            List<RelNode> newInputs,
            List<ImmutableBitSet> projFieldsList,
            List<int[]> joinFieldRefCountsList) {
        if (canCombine(relNode, join)) {
            final MultiJoin multiJoin = (MultiJoin) relNode;
            for (int i = 0; i < multiJoin.getInputs().size(); i++) {
                newInputs.add(multiJoin.getInput(i));
                projFieldsList.add(multiJoin.getProjFields().get(i));
                joinFieldRefCountsList.add(
                        multiJoin.getJoinFieldRefCountsMap().get(i).toIntArray());
            }
        } else {
            newInputs.add(relNode);
            projFieldsList.add(null);
            joinFieldRefCountsList.add(new int[relNode.getRowType().getFieldCount()]);
        }
    }

    /**
     * Combines the join conditions and join types from the left and right join inputs. If the join
     * itself is either a left or right outer join, then the join condition corresponding to the
     * join is also set in the position corresponding to the null-generating input into the join.
     * The join type is also set.
     *
     * @param joinRel join rel
     * @param left left child of the joinrel
     * @param joinSpecs the list where the join types and conditions will be copied
     */
    private void combineJoinInfo(
            Join joinRel, RelNode left, List<Pair<JoinRelType, RexNode>> joinSpecs) {
        JoinRelType joinType = joinRel.getJoinType();
        final RexBuilder rexBuilder = joinRel.getCluster().getRexBuilder();
        boolean leftCombined = canCombine(left, joinRel);
        switch (joinType) {
            case LEFT:
            case INNER:
                if (leftCombined) {
                    copyJoinInfo((MultiJoin) left, joinSpecs);
                } else {
                    joinSpecs.add(Pair.of(JoinRelType.INNER, rexBuilder.makeLiteral(true)));
                }
                joinSpecs.add(Pair.of(joinType, joinRel.getCondition()));
                break;