@Override
      public RexNode visitInputRef(RexInputRef col) {
        InputContext context = null;
        if (inputContext.inputRowResolver == null) {
          context = inputContext;
        } else {
          int index = col.getIndex();
          String colName = inputContext.positionToColumnName.get(index);
          if (colName != null) {
            context = inputContext;
          }
        }

        if(context == null) {
          // we have correlated column, build data type from outer rr
          RelDataType rowType = TypeConverter.getType(cluster, outerRowResolver, null);
          int index = col.getIndex() - inputContext.inputRowType.getFieldList().size();
          if (outerPositionToColumnName.get(index) == null) {
            throw new RuntimeException(ErrorMsg.INVALID_COLUMN_NAME.getMsg());
          }
          CorrelationId colCorr = new CorrelationId(correlatedId);
          RexNode corExpr = cluster.getRexBuilder().makeCorrel(rowType, colCorr);
          return cluster.getRexBuilder().makeFieldAccess(corExpr, index);
        }
        int pos = col.getIndex();
        return cluster.getRexBuilder().makeInputRef(
            context.inputRowType.getFieldList().get(pos).getType(), pos);
      }
Shuttle that replaces certain references with correlation variables
if needed.
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java