public Frame decorrelateRel(Project rel) throws SemanticException {
    //
    // Rewrite logic:
    //
    // 1. Pass along any correlated variables coming from the input.
    //

    final RelNode oldInput = rel.getInput();
    Frame frame = getInvoke(oldInput, rel);
    if (frame == null) {
      // If input has not been rewritten, do not rewrite this rel.
      return null;
    }
    final List<RexNode> oldProjects = rel.getProjects();
    final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();

    // Project projects the original expressions,
    // plus any correlated variables the input wants to pass along.
    final List<Pair<RexNode, String>> projects = Lists.newArrayList();

    // If this Project has correlated reference, create value generator
    // and produce the correlated variables in the new output.
    if (cm.mapRefRelToCorRef.containsKey(rel)) {
      frame = decorrelateInputWithValueGenerator(rel);
    }

    // Project projects the original expressions
    final Map<Integer, Integer> mapOldToNewOutputs =  new HashMap<>();
    int newPos;
    for (newPos = 0; newPos < oldProjects.size(); newPos++) {
      projects.add(
          newPos,
          Pair.of(
              decorrelateExpr(oldProjects.get(newPos)),
              relOutput.get(newPos).getName()));
      mapOldToNewOutputs.put(newPos, newPos);
    }


    // Project any correlated variables the input wants to pass along.
    final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>();
    for (Map.Entry<CorDef, Integer> entry : frame.corDefOutputs.entrySet()) {
      projects.add(
          RexInputRef.of2(entry.getValue(),
              frame.r.getRowType().getFieldList()));
      corDefOutputs.put(entry.getKey(), newPos);
      newPos++;
    }

    RelNode newProject = HiveProject.create(frame.r, Pair.left(projects),
        SqlValidatorUtil.uniquify(Pair.right(projects)));

    return register(rel, newProject, mapOldToNewOutputs,
        corDefOutputs);
  }
Returns a literal output field, or null if it is not literal.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java