private RelNode projectJoinOutputWithNullability(
          Join join,
          Project project,
          int nullIndicatorPos) {
    final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory();
    final RelNode left = join.getLeft();
    final JoinRelType joinType = join.getJoinType();

    RexInputRef nullIndicator =
            new RexInputRef(
                    nullIndicatorPos,
                    typeFactory.createTypeWithNullability(
                            join.getRowType().getFieldList().get(nullIndicatorPos)
                                    .getType(),
                            true));

    // now create the new project
    List<Pair<RexNode, String>> newProjExprs = Lists.newArrayList();

    // project everything from the LHS and then those from the original
    // projRel
    List<RelDataTypeField> leftInputFields =
            left.getRowType().getFieldList();

    for (int i = 0; i < leftInputFields.size(); i++) {
      newProjExprs.add(RexInputRef.of2(i, leftInputFields));
    }

    // Marked where the projected expr is coming from so that the types will
    // become nullable for the original projections which are now coming out
    // of the nullable side of the OJ.
    boolean projectPulledAboveLeftCorrelator =
            joinType.generatesNullsOnRight();

    for (Pair<RexNode, String> pair : project.getNamedProjects()) {
      RexNode newProjExpr =
              removeCorrelationExpr(
                      pair.left,
                      projectPulledAboveLeftCorrelator,
                      nullIndicator);

      newProjExprs.add(Pair.of(newProjExpr, pair.right));
    }

    return RelOptUtil.createProject(join, Pair.left(newProjExprs), Pair.right(newProjExprs),
        false, relBuilder);
  }
Pulls project above the join from its RHS input. Enforces nullability
for join output.

@param join          Join
@param project       Original project as the right-hand input of the join
@param nullIndicatorPos Position of null indicator
@return the subtree with the new Project at the root
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java